Search in sources :

Example 1 with GlobalNamesService

use of org.eol.globi.taxon.GlobalNamesService in project eol-globi-data by jhpoelen.

the class GlobalNamesServiceTest method lookupWoRMS.

@Test
public void lookupWoRMS() throws PropertyEnricherException {
    GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.WORMS);
    HashMap<String, String> props1 = new HashMap<String, String>();
    props1.put(PropertyAndValueDictionary.NAME, "Ariopsis felis");
    Map<String, String> enrich = service.enrich(props1);
    assertThat(enrich.get(PropertyAndValueDictionary.NAME), is("Ariopsis felis"));
    assertThat(enrich.get(PropertyAndValueDictionary.PATH), containsString("Siluriformes | Ariidae | Ariopsis"));
    assertThat(enrich.get(PropertyAndValueDictionary.PATH_IDS), is(""));
    assertThat(enrich.get(PropertyAndValueDictionary.PATH_NAMES), containsString("order | family | genus"));
    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")));
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) GlobalNamesService(org.eol.globi.taxon.GlobalNamesService) Test(org.junit.Test)

Example 2 with GlobalNamesService

use of org.eol.globi.taxon.GlobalNamesService in project eol-globi-data by jhpoelen.

the class GlobalNamesServiceTest method assertAtLeastFortyFound.

public void assertAtLeastFortyFound(String response, final List<Taxon> foundTaxa, List<GlobalNamesSources> sources) {
    String[] idsNames = response.split("\\|");
    GlobalNamesService service = new GlobalNamesService(sources);
    List<String> names = new ArrayList<String>();
    for (int i = 0; i < idsNames.length; i += 2) {
        names.add(idsNames[i] + "|" + idsNames[i + 1]);
    }
    try {
        service.findTermsForNames(names, new TermMatchListener() {

            @Override
            public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
                assertNotNull(nodeId);
                foundTaxa.add(taxon);
            }
        });
    } catch (PropertyEnricherException ex) {
        fail("failed to lookup name with id: [" + names + "]");
    }
}
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)

Example 3 with GlobalNamesService

use of org.eol.globi.taxon.GlobalNamesService in project eol-globi-data by jhpoelen.

the class GlobalNamesServiceTest method createTaxaListFromLongNameList4.

@Test
public void createTaxaListFromLongNameList4() throws PropertyEnricherException {
    List<String> names = namesListWithMaximumOf(100);
    final List<Taxon> foundTaxa = new ArrayList<Taxon>();
    GlobalNamesService service = new GlobalNamesService(Arrays.asList(GlobalNamesSources.values()));
    try {
        service.findTermsForNames(names, new TermMatchListener() {

            @Override
            public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
                assertNotNull(nodeId);
                foundTaxa.add(taxon);
            }
        });
    } catch (PropertyEnricherException ex) {
        fail("failed to lookup name with id: [" + names + "]");
    }
    assertThat(foundTaxa.size() > 2, is(true));
}
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 4 with GlobalNamesService

use of org.eol.globi.taxon.GlobalNamesService in project eol-globi-data by jhpoelen.

the class GlobalNamesServiceTest method lookupSimilar.

@Test
public void lookupSimilar() throws PropertyEnricherException {
    GlobalNamesService service = new GlobalNamesService(Arrays.asList(GlobalNamesSources.GBIF, GlobalNamesSources.ITIS));
    final List<Taxon> taxa = new ArrayList<Taxon>();
    service.findTermsForNames(Collections.singletonList("Zyziphus mauritiana"), new TermMatchListener() {

        @Override
        public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
            taxa.add(taxon);
            assertThat(nameType, is(NameType.SIMILAR_TO));
        }
    });
    assertThat(taxa.size() > 1, is(true));
}
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 5 with GlobalNamesService

use of org.eol.globi.taxon.GlobalNamesService 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)

Aggregations

GlobalNamesService (org.eol.globi.taxon.GlobalNamesService)21 Matchers.containsString (org.hamcrest.Matchers.containsString)21 Test (org.junit.Test)20 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)9 NameType (org.eol.globi.domain.NameType)9 Taxon (org.eol.globi.domain.Taxon)9 TermMatchListener (org.eol.globi.taxon.TermMatchListener)9