Skip to content

Commit

Permalink
include global names vernacular names using new feature introduced in G…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Aug 12, 2015
1 parent 51eb7d6 commit 5d6ab97
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected String queryForNames(List<String> names, List<GlobalNamesSources> sour
HttpClient httpClient = HttpUtil.getHttpClient();
URI uri = new URI("http", "resolver.globalnames.org"
, "/name_resolvers.json"
, "data_source_ids=" + StringUtils.join(sourceIds, "|")
, "with_vernaculars=true&data_source_ids=" + StringUtils.join(sourceIds, "|")
, null);
HttpPost post = new HttpPost(uri);

Expand Down Expand Up @@ -184,6 +184,23 @@ protected void parseClassification(TermMatchListener termMatchListener, JsonNode
&& aResult.get("match_type").getIntValue() < 3;
termMatchListener.foundTaxonForName(suppliedId, suppliedNameString, taxon, isExactMatch);
}

if (aResult.has("vernaculars")) {
List<String> commonNames = new ArrayList<String>();
JsonNode vernaculars = aResult.get("vernaculars");
for (JsonNode vernacular : vernaculars) {
if (vernacular.has("name") && vernacular.has("language")) {
String name = vernacular.get("name").asText();
String language = vernacular.get("language").asText();
if (!StringUtils.equals(name, "null") && !StringUtils.equals(language, "null")) {
commonNames.add(vernacular.get("name").asText() + " @" + language);
}
}
}
if (commonNames.size() > 0) {
taxon.setCommonNames(StringUtils.join(commonNames, CharsetConstant.SEPARATOR));
}
}
}

private TaxonomyProvider getTaxonomyProvider(JsonNode aResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import static junit.framework.Assert.assertNotNull;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

public class GlobalNamesServiceTest {
Expand Down Expand Up @@ -71,6 +74,7 @@ public void lookupNCBI() throws PropertyEnricherException {
assertThat(enrich.get(PropertyAndValueDictionary.PATH_NAMES), is("superkingdom | kingdom | phylum | subphylum | superclass | class | superorder | order | suborder | infraorder | parvorder | superfamily | family | subfamily | genus | species"));
assertThat(enrich.get(PropertyAndValueDictionary.RANK), is("species"));
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("NCBI:9606"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), is(nullValue()));
}

@Test
Expand All @@ -85,6 +89,18 @@ public void lookupWoRMS() throws PropertyEnricherException {
assertThat(enrich.get(PropertyAndValueDictionary.PATH_NAMES), is("kingdom | phylum | class | order | family | genus | species"));
assertThat(enrich.get(PropertyAndValueDictionary.RANK), is("species"));
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("WORMS:158709"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), not(containsString("hardhead catfish @en")));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), not(containsString("bagre boca chica @en")));
}

@Test
public void lookupWoRMSCod() throws PropertyEnricherException {
GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.WORMS);
HashMap<String, String> props1 = new HashMap<String, String>();
props1.put(PropertyAndValueDictionary.NAME, "Gadus morhua");
Map<String, String> enrich = service.enrich(props1);
assertThat(enrich.get(PropertyAndValueDictionary.PATH), containsString("Animalia | Chordata | Actinopterygii | Gadiformes | Gadidae | Gadus | Gadus morhua"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), is(nullValue()));
}

private Map<String, String> assertHomoSapiens(GlobalNamesService service) throws PropertyEnricherException {
Expand Down Expand Up @@ -120,6 +136,7 @@ public void lookupITISFish() throws PropertyEnricherException {
assertThat(enrich.get(PropertyAndValueDictionary.PATH_NAMES), is("Kingdom | Subkingdom | Infrakingdom | Phylum | Subphylum | Infraphylum | Superclass | Class | Subclass | Infraclass | Superorder | Order | Family | Genus | Species"));
assertThat(enrich.get(PropertyAndValueDictionary.RANK), is("Species"));
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("ITIS:680665"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), is("bagre boca chica @Spanish"));
}

@Test
Expand All @@ -134,6 +151,9 @@ public void lookupGBIF() throws PropertyEnricherException {
assertThat(enrich.get(PropertyAndValueDictionary.PATH_NAMES), is("kingdom | phylum | class | order"));
assertThat(enrich.get(PropertyAndValueDictionary.RANK), is("order"));
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("GBIF:952"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), containsString("Kikkers @nl"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), containsString("Бесхвостые @ru"));
assertThat(enrich.get(PropertyAndValueDictionary.COMMON_NAMES), not(containsString("Frogs @en")));
}

@Test
Expand Down

0 comments on commit 5d6ab97

Please sign in to comment.