Search in sources :

Example 6 with NameType

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));
}
Also used : Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) Matchers.containsString(org.hamcrest.Matchers.containsString) GlobalNamesService(org.eol.globi.taxon.GlobalNamesService) TermMatchListener(org.eol.globi.taxon.TermMatchListener) Test(org.junit.Test)

Example 7 with NameType

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);
        }
    }
}
Also used : NameType(org.eol.globi.domain.NameType) Term(org.eol.globi.domain.Term)

Example 8 with NameType

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));
}
Also used : Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) Matchers.containsString(org.hamcrest.Matchers.containsString) GlobalNamesService(org.eol.globi.taxon.GlobalNamesService) TermMatchListener(org.eol.globi.taxon.TermMatchListener) Test(org.junit.Test)

Example 9 with NameType

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));
        }
    }
}
Also used : Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) JsonNode(org.codehaus.jackson.JsonNode)

Example 10 with NameType

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));
}
Also used : Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) Matchers.containsString(org.hamcrest.Matchers.containsString) GlobalNamesService(org.eol.globi.taxon.GlobalNamesService) TermMatchListener(org.eol.globi.taxon.TermMatchListener) Test(org.junit.Test)

Aggregations

NameType (org.eol.globi.domain.NameType)13 Taxon (org.eol.globi.domain.Taxon)12 ArrayList (java.util.ArrayList)11 TermMatchListener (org.eol.globi.taxon.TermMatchListener)10 GlobalNamesService (org.eol.globi.taxon.GlobalNamesService)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 JsonNode (org.codehaus.jackson.JsonNode)1 TaxonImpl (org.eol.globi.domain.TaxonImpl)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 Term (org.eol.globi.domain.Term)1 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)1