OpenMS  2.7.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-2021.
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>
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  {
77  bool has_value;
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 
163 
166 
169 
172 
175 
178 
183 
184 
186 
196 
197 private:
198 
201 
204 
207 
208  };
209 
210  } // namespace Internal
211 
212 } // namespace OpenMS
213 
214 
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition: CVMappings.h:57
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:55
Semantically validates XML files using CVMappings and a ControlledVocabulary.
Definition: SemanticValidator.h:58
bool check_term_value_types_
Definition: SemanticValidator.h:193
virtual void getCVTerm_(const xercesc::Attributes &attributes, CVTerm &parsed_term)
Parses the CV term accession (required), name (required) and value (optional) from the XML attributes...
String unit_name
Definition: SemanticValidator.h:80
SemanticValidator(const SemanticValidator &rhs)
Not implemented.
SemanticValidator(const CVMappings &mapping, const ControlledVocabulary &cv)
Constructor.
void setUnitNameAttribute(const String &name)
Sets the name of the unit name attribute (default: 'unitName')
virtual void handleTerm_(const String &path, const CVTerm &parsed_term)
Handling of the term.
const ControlledVocabulary & cv_
Reference to the CVs.
Definition: SemanticValidator.h:165
String name_att_
Definition: SemanticValidator.h:189
String value
Definition: SemanticValidator.h:76
String unit_name_att_
Definition: SemanticValidator.h:192
void setValueAttribute(const String &value)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'value')
void setCheckUnits(bool check)
Set if CV term units should be check (disabled by default)
bool locateTerm(const String &path, const CVTerm &parsed_term) const
Checks if a CVTerm is allowed in a given path.
String unit_accession_att_
Definition: SemanticValidator.h:191
String unit_accession
Definition: SemanticValidator.h:78
bool has_unit_name
Definition: SemanticValidator.h:81
StringList warnings_
Validation warnings.
Definition: SemanticValidator.h:171
void setUnitAccessionAttribute(const String &accession)
Sets the name of the unit accession attribute (default: 'unitAccession')
String cv_tag_
Definition: SemanticValidator.h:187
StringList errors_
Validation errors.
Definition: SemanticValidator.h:168
void setCheckTermValueTypes(bool check)
Set if CV term value types should be check (enabled by default)
void setTag(const String &tag)
Sets the CV parameter tag name (default: 'cvParam')
StringList open_tags_
List of open tags.
Definition: SemanticValidator.h:174
String name
Definition: SemanticValidator.h:75
bool has_value
Definition: SemanticValidator.h:77
void startElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname, const xercesc::Attributes &attributes) override
bool validate(const String &filename, StringList &errors, StringList &warnings)
Semantically validates an XML file.
String accession
Definition: SemanticValidator.h:74
SemanticValidator & operator=(const SemanticValidator &rhs)
Not implemented.
bool check_units_
Definition: SemanticValidator.h:194
Map< String, Map< String, Map< String, UInt > > > fulfilled_
Definition: SemanticValidator.h:182
void characters(const XMLCh *const chars, const XMLSize_t) override
bool has_unit_accession
Definition: SemanticValidator.h:79
Map< String, std::vector< CVMappingRule > > rules_
Rules (location => rule)
Definition: SemanticValidator.h:177
void endElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname) override
String value_att_
Definition: SemanticValidator.h:190
void setAccessionAttribute(const String &accession)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'accession')
virtual String getPath_(UInt remove_from_end=0) const
Returns the current element path.
const CVMappings & mapping_
Reference to the mappings.
Definition: SemanticValidator.h:162
void setNameAttribute(const String &name)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'name')
~SemanticValidator() override
Destructor.
String accession_att_
Definition: SemanticValidator.h:188
Representation of a parsed CV term.
Definition: SemanticValidator.h:73
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:49
Base class for XML handlers.
Definition: XMLHandler.h:327
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:52
A more convenient string class.
Definition: String.h:61
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47