OpenMS  3.0.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-2022.
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>
40 #include <map>
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 
177  std::map<String, std::vector<CVMappingRule> > rules_;
178 
182  std::map<String, std::map<String, std::map<String, UInt> > > fulfilled_;
183 
184 
186 
196 
197 private:
198 
201 
204 
206  SemanticValidator & operator=(const SemanticValidator & rhs);
207 
208  };
209 
210  } // namespace Internal
211 
212 } // namespace OpenMS
213 
214 
OpenMS::Internal::SemanticValidator::warnings_
StringList warnings_
Validation warnings.
Definition: SemanticValidator.h:171
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::Internal::SemanticValidator::CVTerm::has_unit_accession
bool has_unit_accession
Definition: SemanticValidator.h:79
FileHandler.h
FileTypes.h
XMLFile.h
Size
OpenMS::CVMappingFile
Used to load CvMapping files.
Definition: CVMappingFile.h:58
OpenMS::Internal::ClassTest::validate
bool validate(const std::vector< std::string > &file_names)
Validates the given files against the XML schema (if available)
OpenMS::ControlledVocabulary
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:54
OpenMS::Internal::XMLHandler
Base class for XML handlers.
Definition: XMLHandler.h:323
ControlledVocabulary.h
OpenMS::Internal::SemanticValidator::CVTerm::name
String name
Definition: SemanticValidator.h:75
OpenMS::Internal::SemanticValidator::errors_
StringList errors_
Validation errors.
Definition: SemanticValidator.h:168
OpenMS::Internal::SemanticValidator::cv_tag_
String cv_tag_
Definition: SemanticValidator.h:187
OpenMS::CVMappingFile::load
void load(const String &filename, CVMappings &cv_mappings, bool strip_namespaces=false)
loads CvMappings from the given file
OpenMS::Internal::SemanticValidator::check_term_value_types_
bool check_term_value_types_
Definition: SemanticValidator.h:193
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::Internal::SemanticValidator::CVTerm::has_unit_name
bool has_unit_name
Definition: SemanticValidator.h:81
OpenMS::Internal::SemanticValidator::name_att_
String name_att_
Definition: SemanticValidator.h:189
OpenMS::Internal::SemanticValidator::CVTerm::value
String value
Definition: SemanticValidator.h:76
XMLHandler.h
OpenMS::CVMappings
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition: CVMappings.h:56
OpenMS::File::find
static String find(const String &filename, StringList directories=StringList())
Looks up the location of the file filename.
OpenMS::ControlledVocabulary::loadFromOBO
void loadFromOBO(const String &name, const String &filename)
Loads the CV from an OBO file.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
CVMappings.h
OpenMS::Internal::SemanticValidator
Semantically validates XML files using CVMappings and a ControlledVocabulary.
Definition: SemanticValidator.h:55
OpenMS::Internal::SemanticValidator::fulfilled_
std::map< String, std::map< String, std::map< String, UInt > > > fulfilled_
Definition: SemanticValidator.h:182
OpenMS::Internal::SemanticValidator::unit_name_att_
String unit_name_att_
Definition: SemanticValidator.h:192
OpenMS::Internal::SemanticValidator::CVTerm::has_value
bool has_value
Definition: SemanticValidator.h:77
OpenMS::Internal::SemanticValidator::check_units_
bool check_units_
Definition: SemanticValidator.h:194
SemanticValidator.h
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
CVMappingFile.h
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::Internal::SemanticValidator::rules_
std::map< String, std::vector< CVMappingRule > > rules_
Rules (location => rule)
Definition: SemanticValidator.h:177
OpenMS::Internal::SemanticValidator::CVTerm
Representation of a parsed CV term.
Definition: SemanticValidator.h:72
OpenMS::Internal::SemanticValidator::cv_
const ControlledVocabulary & cv_
Reference to the CVs.
Definition: SemanticValidator.h:165
OpenMS::Internal::SemanticValidator::mapping_
const CVMappings & mapping_
Reference to the mappings.
Definition: SemanticValidator.h:162
OpenMS::Internal::SemanticValidator::value_att_
String value_att_
Definition: SemanticValidator.h:190
OpenMS::Internal::SemanticValidator::CVTerm::accession
String accession
Definition: SemanticValidator.h:74
OpenMS::Internal::XMLFile
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:48
OpenMS::Internal::SemanticValidator::unit_accession_att_
String unit_accession_att_
Definition: SemanticValidator.h:191
OpenMS::Internal::SemanticValidator::CVTerm::unit_accession
String unit_accession
Definition: SemanticValidator.h:78
OpenMS::Internal::SemanticValidator::open_tags_
StringList open_tags_
List of open tags.
Definition: SemanticValidator.h:174
File.h
TOPPBase.h
OpenMS::Internal::SemanticValidator::CVTerm::unit_name
String unit_name
Definition: SemanticValidator.h:80
OpenMS::Internal::SemanticValidator::accession_att_
String accession_att_
Definition: SemanticValidator.h:188