Skip to content

Commit

Permalink
attempt to ignore greedy ncbi matches from globalnames. related to Gl…
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpoelen committed Dec 18, 2018
1 parent 6d5ee65 commit 2008d28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private void parseResult(TermMatchListener termMatchListener, String result) thr
}

private void parseResultNode(TermMatchListener termMatchListener, JsonNode jsonNode) {

JsonNode dataList = jsonNode.get("data");
if (dataList != null && dataList.isArray()) {
for (JsonNode data : dataList) {
Expand Down Expand Up @@ -287,7 +288,7 @@ protected void parseClassification(TermMatchListener termMatchListener, JsonNode
}

// related to https://github.com/GlobalNamesArchitecture/gni/issues/48
if (!pathTailRepetitions(taxon)) {
if (!pathTailRepetitions(taxon) && !speciesNoGenus(taxon)) {
termMatchListener.foundTaxonForName(requestId(data), suppliedNameString, taxon, nameType);
}
}
Expand All @@ -310,6 +311,11 @@ protected void parseClassification(TermMatchListener termMatchListener, JsonNode
}
}

private boolean speciesNoGenus(Taxon taxon) {
return taxon.getPathNames().contains("species")
&& !taxon.getPathNames().contains("genus");
}

private String getSuppliedNameString(JsonNode data) {
return data.get("supplied_name_string").getTextValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,34 @@ public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType na

}

@Test
public void lookupNCBIIgnoreCanonicalMatchOnExactMatch() throws PropertyEnricherException {
GlobalNamesService2 service = new GlobalNamesService2(Arrays.asList(GlobalNamesSources2.NCBI));
final List<Taxon> taxa = new ArrayList<>();
service.findTermsForNames(Collections.singletonList("Amphipoda"), (nodeId, name, taxon, nameType) -> {
taxa.add(taxon);
assertThat(nameType, is(NameType.SAME_AS));
});

assertThat(taxa.size(), is(1));
assertThat(taxa.get(0).getPath(), endsWith("Amphipoda"));
assertThat(taxa.get(0).getPathNames(), endsWith("order"));

}

@Test
public void lookupNCBIIgnoreCanonicalMatchSingleWordSpecies() throws PropertyEnricherException {
GlobalNamesService2 service = new GlobalNamesService2(Collections.singletonList(GlobalNamesSources2.NCBI));
final List<Taxon> taxa = new ArrayList<>();
service.findTermsForNames(Collections.singletonList("Procladius sp1 M_PL_014"), (nodeId, name, taxon, nameType) -> {
taxa.add(taxon);
assertThat(nameType, is(NameType.SAME_AS));
});

assertThat(taxa.size(), is(1));
assertThat(taxa.get(0).getPath(), endsWith("Procladius"));
assertThat(taxa.get(0).getPathNames(), endsWith("genus"));

}

}

0 comments on commit 2008d28

Please sign in to comment.