| 142 | } |
| 143 | |
| 144 | void SemanticValidator::endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname) |
| 145 | { |
| 146 | String tag = sm_.convert(qname); |
| 147 | String path = getPath_() + "/" + cv_tag_ + "/@" + accession_att_; |
| 148 | |
| 149 | //look up rules and fulfilled rules/terms |
| 150 | vector<CVMappingRule>& rules = rules_[path]; |
| 151 | std::map<String, std::map<String, UInt> >& fulfilled = fulfilled_[path]; //(rule ID => term ID => term count) |
| 152 | |
| 153 | //check how often each term appeared |
| 154 | for (Size r = 0; r < rules.size(); ++r) |
| 155 | { |
| 156 | for (Size t = 0; t < rules[r].getCVTerms().size(); ++t) |
| 157 | { |
| 158 | if (!rules[r].getCVTerms()[t].getIsRepeatable() && fulfilled[rules[r].getIdentifier()][rules[r].getCVTerms()[t].getAccession()] > 1) |
| 159 | { |
| 160 | errors_.push_back(String("Violated mapping rule '") + rules[r].getIdentifier() + "' number of term repeats at element '" + getPath_() + "'"); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | //check if all required rules are fulfilled |
| 166 | for (Size r = 0; r < rules.size(); ++r) |
| 167 | { |
| 168 | //Count the number of distinct matched terms |
| 169 | Size terms_count = rules[r].getCVTerms().size(); |
| 170 | UInt match_count = 0; |
| 171 | for (Size t = 0; t < terms_count; ++t) |
| 172 | { |
| 173 | if (fulfilled[rules[r].getIdentifier()][rules[r].getCVTerms()[t].getAccession()] >= 1) |
| 174 | { |
| 175 | ++match_count; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | //MUST / AND - all terms must be matched |
| 180 | if (rules[r].getRequirementLevel() == CVMappingRule::MUST && rules[r].getCombinationsLogic() == CVMappingRule::AND) |
| 181 | { |
| 182 | if (match_count != terms_count) |
| 183 | { |
| 184 | errors_.push_back(String("Violated mapping rule '") + rules[r].getIdentifier() + "' at element '" + getPath_() + "', " + String(terms_count) + " term(s) should be present, " + String(match_count) + " found!"); |
| 185 | } |
| 186 | } |
| 187 | //MUST / OR - at least one terms must be matched |
| 188 | else if (rules[r].getRequirementLevel() == CVMappingRule::MUST && rules[r].getCombinationsLogic() == CVMappingRule::OR) |
| 189 | { |
| 190 | if (match_count == 0) |
| 191 | { |
| 192 | errors_.push_back(String("Violated mapping rule '") + rules[r].getIdentifier() + "' at element '" + getPath_() + "', at least one term must be present!"); |
| 193 | } |
| 194 | } |
| 195 | //MUST / XOR - exactly one term must be matched |
| 196 | else if (rules[r].getRequirementLevel() == CVMappingRule::MUST && rules[r].getCombinationsLogic() == CVMappingRule::XOR) |
| 197 | { |
| 198 | if (match_count != 1) |
| 199 | { |
| 200 | errors_.push_back(String("Violated mapping rule '") + rules[r].getIdentifier() + "' at element '" + getPath_() + "' exactly one of the allowed terms must be used!"); |
| 201 | } |
nothing calls this directly
no test coverage detected