| OpenMS 2.5.0

SemanticValidator.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Andreas Bertsch $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/FORMAT/XMLFile.h>
38 #include <OpenMS/FORMAT/HANDLERS/XMLHandler.h>
39 #include <OpenMS/DATASTRUCTURES/Map.h>
40 #include <OpenMS/DATASTRUCTURES/CVMappings.h>
41
42
43 namespace OpenMS
44 {
45 class ControlledVocabulary;
46 namespace Internal
47 {
48
55 class OPENMS_DLLAPI SemanticValidator :
56 protected Internal::XMLHandler,
57 public Internal::XMLFile
58 {
59 public:
66 SemanticValidator(const CVMappings & mapping, const ControlledVocabulary & cv);
67
69 ~SemanticValidator() override;
70
72 struct CVTerm
73 {
74 String accession;
75 String name;
76 String value;
77 bool has_value;
78 String unit_accession;
79 bool has_unit_accession;
80 String unit_name;
81 bool has_unit_name;
82 };
83
95 bool validate(const String & filename, StringList & errors, StringList & warnings);
96
98 bool locateTerm(const String & path, const CVTerm & parsed_term) const;
99
101 void setTag(const String & tag);
102
104 void setAccessionAttribute(const String & accession);
105
107 void setNameAttribute(const String & name);
108
110 void setValueAttribute(const String & value);
111
120 void setCheckTermValueTypes(bool check);
121
129 void setCheckUnits(bool check);
130
132 void setUnitAccessionAttribute(const String & accession);
133
135 void setUnitNameAttribute(const String & name);
136
137 protected:
138
139 // Docu in base class
140 void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
141
142 // Docu in base class
143 void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
144
145 // Docu in base class
146 void characters(const XMLCh * const chars, const XMLSize_t /*length*/) override;
147
149 virtual String getPath_(UInt remove_from_end = 0) const;
150
152 virtual void getCVTerm_(const xercesc::Attributes & attributes, CVTerm & parsed_term);
153
154 //~ forward dekl. of a inner struct/class not possible in C++ - or our Library is overtemplated
155 //~ /// make a SemanticValidator::CVTerm from a ControlledVocabulary::CVTerm (without any value or unit), needed for writing only cvs at the right places in the xml (i.e. with cvmapping)
156 //~ virtual void makeCVTerm_(const ControlledVocabulary::CVTerm & lc, CVTerm & parsed_term);
157
159 virtual void handleTerm_(const String & path, const CVTerm & parsed_term);
160
162 const CVMappings & mapping_;
163
165 const ControlledVocabulary & cv_;
166
168 StringList errors_;
169
171 StringList warnings_;
172
174 StringList open_tags_;
175
177 Map<String, std::vector<CVMappingRule> > rules_;
178
182 Map<String, Map<String, Map<String, UInt> > > fulfilled_;
183
184
186
187 String cv_tag_;
188 String accession_att_;
189 String name_att_;
190 String value_att_;
191 String unit_accession_att_;
192 String unit_name_att_;
193 bool check_term_value_types_;
194 bool check_units_;
196
197 private:
198
200 SemanticValidator();
201
203 SemanticValidator(const SemanticValidator & rhs);
204
206 SemanticValidator & operator=(const SemanticValidator & rhs);
207
208 };
209
210 } // namespace Internal
211
212 } // namespace OpenMS
213
214
OpenMS::String
A more convenient string class.
Definition: String.h:58
XMLFile.h
OpenMS::Internal::SemanticValidator::CVTerm::has_value
bool has_value
Definition: SemanticValidator.h:77
XMLHandler.h
OpenMS::Internal::SemanticValidator::check_term_value_types_
bool check_term_value_types_
Definition: SemanticValidator.h:193
OpenMS::CVMappings
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition: CVMappings.h:56
OpenMS::Internal::SemanticValidator::accession_att_
String accession_att_
Definition: SemanticValidator.h:188
OpenMS::Internal::ClassTest::validate
bool validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
OpenMS::Internal::SemanticValidator::CVTerm::unit_name
String unit_name
Definition: SemanticValidator.h:80
OpenMS::Internal::SemanticValidator::unit_name_att_
String unit_name_att_
Definition: SemanticValidator.h:192
OpenMS::Internal::SemanticValidator::CVTerm
Representation of a parsed CV term.
Definition: SemanticValidator.h:72
OpenMS::Internal::SemanticValidator::CVTerm::has_unit_name
bool has_unit_name
Definition: SemanticValidator.h:81
OpenMS::Internal::SemanticValidator::CVTerm::accession
String accession
Definition: SemanticValidator.h:74
OpenMS::Internal::SemanticValidator::warnings_
StringList warnings_
Validation warnings.
Definition: SemanticValidator.h:171
OpenMS::Internal::SemanticValidator
Semantically validates XML files using CVMappings and a ControlledVocabulary.
Definition: SemanticValidator.h:55
OpenMS::Internal::SemanticValidator::value_att_
String value_att_
Definition: SemanticValidator.h:190
OpenMS::Internal::SemanticValidator::open_tags_
StringList open_tags_
List of open tags.
Definition: SemanticValidator.h:174
OpenMS::Internal::SemanticValidator::CVTerm::has_unit_accession
bool has_unit_accession
Definition: SemanticValidator.h:79
OpenMS::Internal::SemanticValidator::fulfilled_
Map< String, Map< String, Map< String, UInt > > > fulfilled_
Definition: SemanticValidator.h:182
OpenMS::Internal::SemanticValidator::rules_
Map< String, std::vector< CVMappingRule > > rules_
Rules (location => rule)
Definition: SemanticValidator.h:177
OpenMS::Internal::XMLFile
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:48
OpenMS::Internal::SemanticValidator::mapping_
const CVMappings & mapping_
Reference to the mappings.
Definition: SemanticValidator.h:162
OpenMS::Internal::SemanticValidator::CVTerm::value
String value
Definition: SemanticValidator.h:76
OpenMS::Map
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
OpenMS::Internal::SemanticValidator::unit_accession_att_
String unit_accession_att_
Definition: SemanticValidator.h:191
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::Internal::SemanticValidator::CVTerm::name
String name
Definition: SemanticValidator.h:75
OpenMS::Internal::SemanticValidator::cv_tag_
String cv_tag_
Definition: SemanticValidator.h:187
Map.h
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::Internal::SemanticValidator::CVTerm::unit_accession
String unit_accession
Definition: SemanticValidator.h:78
OpenMS::Internal::SemanticValidator::name_att_
String name_att_
Definition: SemanticValidator.h:189
OpenMS::Internal::SemanticValidator::errors_
StringList errors_
Validation errors.
Definition: SemanticValidator.h:168
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::ControlledVocabulary
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:54
CVMappings.h
OpenMS::Internal::XMLHandler
Base class for XML handlers.
Definition: XMLHandler.h:151
OpenMS::Internal::SemanticValidator::cv_
const ControlledVocabulary & cv_
Reference to the CVs.
Definition: SemanticValidator.h:165
OpenMS::Internal::SemanticValidator::check_units_
bool check_units_
Definition: SemanticValidator.h:194