Skip to content

Commit

Permalink
Check for pre-existing OTT ID before checking for homonym.
Browse files Browse the repository at this point in the history
  • Loading branch information
bredelings committed Oct 9, 2023
1 parent 0bd5163 commit d32db56
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions otc/taxonomy/patching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,16 @@ bool_str_t PatchableTaxonomy::add_new_taxon(OttId oid,
auto & tree = this->get_mutable_tax_tree();
auto & rt_data = tree.get_data();

// 1. Check if the new taxon is a homonym of an existing taxon.
// 1. Check if the OTT ID is already used.
auto itnit = included_taxon_from_id(oid);
auto itrit = rt_data.id_to_record.find(oid);
if (itnit != nullptr || itrit != rt_data.id_to_record.end()) {
std::string expl = "OTT ID " + std::to_string(oid);
expl += " is already used.";
return bool_str_t{false, expl};
}

// 2. Check if the new taxon is a homonym of an existing taxon.
auto nm_nd_it = rt_data.name_to_node.find(name);
if (nm_nd_it == rt_data.name_to_node.end()) {
if (homonym_of != nullptr) {
Expand All @@ -302,15 +311,6 @@ bool_str_t PatchableTaxonomy::add_new_taxon(OttId oid,
return bool_str_t{false, expl};
}

// 2. Check if the OTT ID is already used.
auto itnit = included_taxon_from_id(oid);
auto itrit = rt_data.id_to_record.find(oid);
if (itnit != nullptr || itrit != rt_data.id_to_record.end()) {
std::string expl = "OTT ID " + std::to_string(oid);
expl += " is already used.";
return bool_str_t{false, expl};
}

// 3. Find the parent taxon by its OTT ID.
RTRichTaxNode * par_ptr = const_cast<RTRichTaxNode *>(included_taxon_from_id(parent_id));
if (par_ptr == nullptr) {
Expand Down

0 comments on commit d32db56

Please sign in to comment.