OpenMS
Loading...
Searching...
No Matches
SemanticValidator.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm, Andreas Bertsch $
7// --------------------------------------------------------------------------
8
9#pragma once
10
14#include <map>
15
16
17namespace OpenMS
18{
19 class ControlledVocabulary;
20 namespace Internal
21 {
22
29 class OPENMS_DLLAPI SemanticValidator :
30 protected Internal::XMLHandler,
32 {
33public:
41
44
46 struct CVTerm
47 {
48 std::string accession;
49 std::string name;
50 std::string value;
51 bool has_value{};
52 std::string unit_accession;
53 bool has_unit_accession{};
54 std::string unit_name;
55 bool has_unit_name{};
56 };
57
69 bool validate(const std::string & filename, StringList & errors, StringList & warnings);
70
72 bool locateTerm(const std::string & path, const CVTerm & parsed_term) const;
73
75 void setTag(const std::string & tag);
76
78 void setAccessionAttribute(const std::string & accession);
79
81 void setNameAttribute(const std::string & name);
82
84 void setValueAttribute(const std::string & value);
85
94 void setCheckTermValueTypes(bool check);
95
103 void setCheckUnits(bool check);
104
106 void setUnitAccessionAttribute(const std::string & accession);
107
109 void setUnitNameAttribute(const std::string & name);
110
111protected:
112
113 // Docu in base class
114 void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
115
116 // Docu in base class
117 void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
118
119 // Docu in base class
120 void characters(const XMLCh * const chars, const XMLSize_t /*length*/) override;
121
123 virtual std::string getPath_(UInt remove_from_end = 0) const;
124
126 virtual void getCVTerm_(const xercesc::Attributes & attributes, CVTerm & parsed_term);
127
128 //~ forward dekl. of a inner struct/class not possible in C++ - or our Library is overtemplated
129 //~ /// 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)
130 //~ virtual void makeCVTerm_(const ControlledVocabulary::CVTerm & lc, CVTerm & parsed_term);
131
133 virtual void handleTerm_(const std::string & path, const CVTerm & parsed_term);
134
137
140
143
146
149
151 std::map<std::string, std::vector<CVMappingRule> > rules_;
152
156 std::map<std::string, std::map<std::string, std::map<std::string, UInt> > > fulfilled_;
157
158
160
161 std::string cv_tag_;
162 std::string accession_att_;
163 std::string name_att_;
164 std::string value_att_;
166 std::string unit_name_att_;
170
171private:
172
175
178
181
182 };
183
184 } // namespace Internal
185
186} // namespace OpenMS
187
188
char16_t XMLCh
Definition ClassTest.h:30
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition CVMappings.h:31
Definition ControlledVocabulary.h:29
Semantically validates XML files using CVMappings and a ControlledVocabulary.
Definition SemanticValidator.h:32
bool check_term_value_types_
Definition SemanticValidator.h:167
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...
bool locateTerm(const std::string &path, const CVTerm &parsed_term) const
Checks if a CVTerm is allowed in a given path.
std::string cv_tag_
Definition SemanticValidator.h:161
SemanticValidator(const SemanticValidator &rhs)
Not implemented.
void setUnitNameAttribute(const std::string &name)
Sets the name of the unit name attribute (default: 'unitName')
SemanticValidator(const CVMappings &mapping, const ControlledVocabulary &cv)
Constructor.
std::string value_att_
Definition SemanticValidator.h:164
const ControlledVocabulary & cv_
Reference to the CVs.
Definition SemanticValidator.h:139
std::string unit_accession_att_
Definition SemanticValidator.h:165
std::map< std::string, std::map< std::string, std::map< std::string, UInt > > > fulfilled_
Definition SemanticValidator.h:156
std::map< std::string, std::vector< CVMappingRule > > rules_
Rules (location => rule)
Definition SemanticValidator.h:151
void setCheckUnits(bool check)
Set if CV term units should be check (disabled by default)
void setUnitAccessionAttribute(const std::string &accession)
Sets the name of the unit accession attribute (default: 'unitAccession')
std::string value
Definition SemanticValidator.h:50
SemanticValidator & operator=(const SemanticValidator &rhs)
Not implemented.
std::string unit_accession
Definition SemanticValidator.h:52
std::string accession_att_
Definition SemanticValidator.h:162
void setNameAttribute(const std::string &name)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'name')
StringList warnings_
Validation warnings.
Definition SemanticValidator.h:145
void setTag(const std::string &tag)
Sets the CV parameter tag name (default: 'cvParam')
StringList errors_
Validation errors.
Definition SemanticValidator.h:142
virtual std::string getPath_(UInt remove_from_end=0) const
Returns the current element path.
void setValueAttribute(const std::string &value)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'value')
void setCheckTermValueTypes(bool check)
Set if CV term value types should be check (enabled by default)
void setAccessionAttribute(const std::string &accession)
Sets the name of the attribute for accessions in the CV parameter tag name (default: 'accession')
StringList open_tags_
List of open tags.
Definition SemanticValidator.h:148
std::string name
Definition SemanticValidator.h:49
void startElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname, const xercesc::Attributes &attributes) override
bool check_units_
Definition SemanticValidator.h:168
void characters(const XMLCh *const chars, const XMLSize_t) override
std::string unit_name
Definition SemanticValidator.h:54
virtual void handleTerm_(const std::string &path, const CVTerm &parsed_term)
Handling of the term.
void endElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname) override
std::string accession
Definition SemanticValidator.h:48
const CVMappings & mapping_
Reference to the mappings.
Definition SemanticValidator.h:136
std::string name_att_
Definition SemanticValidator.h:163
~SemanticValidator() override
Destructor.
bool validate(const std::string &filename, StringList &errors, StringList &warnings)
Semantically validates an XML file.
std::string unit_name_att_
Definition SemanticValidator.h:166
Representation of a parsed CV term.
Definition SemanticValidator.h:47
Base class for loading and storing XML files via Xerces, with optional schema validation and transpar...
Definition XMLFile.h:38
Base class for XML handlers.
Definition XMLHandler.h:316
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19