use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.
the class GlobalNamesServiceTest method createTaxaListFromNameList.
@Test
public void createTaxaListFromNameList() throws PropertyEnricherException {
GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.ITIS);
final List<Taxon> foundTaxa = new ArrayList<Taxon>();
service.findTermsForNames(Arrays.asList("1|Homo sapiens", "2|Ariopsis felis"), new TermMatchListener() {
@Override
public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
assertNotNull(nodeId);
foundTaxa.add(taxon);
}
});
assertThat(foundTaxa.size(), is(2));
}
use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.
the class TaxonEnricherImpl method findTerms.
@Override
public void findTerms(List<Term> terms, TermMatchListener termMatchListener) throws PropertyEnricherException {
for (Term name : terms) {
Map<String, String> enriched = enrich(new TreeMap<String, String>() {
{
put(PropertyAndValueDictionary.NAME, name.getName());
put(PropertyAndValueDictionary.EXTERNAL_ID, name.getId());
}
});
if (enriched != null) {
NameType nameMatchType = TaxonUtil.isResolved(enriched) ? NameType.SAME_AS : NameType.NONE;
termMatchListener.foundTaxonForName(null, name.getName(), TaxonUtil.mapToTaxon(enriched), nameMatchType);
}
}
}
use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.
the class GlobalNamesServiceTest method lookupMultipleSources.
@Test
public void lookupMultipleSources() throws PropertyEnricherException {
GlobalNamesService service = new GlobalNamesService(Arrays.asList(GlobalNamesSources.GBIF, GlobalNamesSources.ITIS));
final List<Taxon> taxa = new ArrayList<Taxon>();
service.findTermsForNames(Collections.singletonList("Homo sapiens"), new TermMatchListener() {
@Override
public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
taxa.add(taxon);
}
});
assertThat(taxa.size(), is(2));
}
use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.
the class GlobalNamesService method parseClassification.
protected void parseClassification(TermMatchListener termMatchListener, JsonNode data, JsonNode aResult, TaxonomyProvider provider) {
Taxon taxon = new TaxonImpl();
String classificationPath = aResult.get("classification_path").asText();
taxon.setPath(parseList(classificationPath));
if (aResult.has("classification_path_ids")) {
String classificationPathIds = aResult.get("classification_path_ids").asText();
taxon.setPathIds(parseList(classificationPathIds, provider.getIdPrefix()));
}
String pathRanks = aResult.get("classification_path_ranks").asText();
taxon.setPathNames(parseList(pathRanks));
String[] ranks = pathRanks.split("\\|");
if (ranks.length > 0) {
String rank = ranks[ranks.length - 1];
taxon.setRank(rank);
}
String[] taxonNames = classificationPath.split("\\|");
if (ranks.length > 0 && taxonNames.length > 0) {
String taxonName = taxonNames[taxonNames.length - 1];
taxon.setName(taxonName);
} else {
taxon.setName(aResult.get("canonical_form").asText());
}
String taxonIdLabel = aResult.has("current_taxon_id") ? "current_taxon_id" : "taxon_id";
String taxonIdValue = aResult.get(taxonIdLabel).asText();
// see https://github.com/GlobalNamesArchitecture/gni/issues/35
if (!StringUtils.startsWith(taxonIdValue, "gn:")) {
String externalId = provider.getIdPrefix() + taxonIdValue;
taxon.setExternalId(externalId);
String suppliedNameString = getSuppliedNameString(data);
boolean isExactMatch = aResult.has("match_type") && aResult.get("match_type").getIntValue() < 3;
NameType nameType = isExactMatch ? NameType.SAME_AS : NameType.SIMILAR_TO;
if (isExactMatch && aResult.has("current_name_string")) {
nameType = NameType.SYNONYM_OF;
}
// related to https://github.com/GlobalNamesArchitecture/gni/issues/48
if (!pathTailRepetitions(taxon)) {
termMatchListener.foundTaxonForName(requestId(data), suppliedNameString, taxon, nameType);
}
}
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));
}
}
}
use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.
the class GlobalNamesServiceTest method createTaxaListFromNameWithSpecialCharacter.
@Test
public void createTaxaListFromNameWithSpecialCharacter() throws PropertyEnricherException {
GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.IF);
final List<Taxon> foundTaxa = new ArrayList<Taxon>();
service.findTermsForNames(Collections.singletonList("4594386|Epichloƫ"), new TermMatchListener() {
@Override
public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
assertNotNull(nodeId);
foundTaxa.add(taxon);
}
});
assertThat(foundTaxa.size(), is(1));
}
Aggregations