Search in sources :

Example 6 with TermMatchListener

use of org.eol.globi.taxon.TermMatchListener 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 7 with TermMatchListener

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

Example 8 with TermMatchListener

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

the class GlobalNamesServiceTest method createTaxaListFromNoNameList.

@Test
public void createTaxaListFromNoNameList() throws PropertyEnricherException {
    GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.ITIS);
    final List<Taxon> foundTaxa = new ArrayList<Taxon>();
    service.findTermsForNames(Arrays.asList("1|Donald duck", "2|Mickey mouse"), new TermMatchListener() {

        @Override
        public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
            assertNotNull(nodeId);
            assertThat(nameType, is(NameType.NONE));
            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 9 with TermMatchListener

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

the class GlobalNamesServiceTest method lookupNCBIPrune.

@Test
public void lookupNCBIPrune() throws PropertyEnricherException {
    GlobalNamesService service = new GlobalNamesService(Arrays.asList(GlobalNamesSources.NCBI));
    final List<Taxon> taxa = new ArrayList<>();
    service.findTermsForNames(Collections.singletonList("Klebsiella pneumoniae"), new TermMatchListener() {

        @Override
        public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
            taxa.add(taxon);
            assertThat(nameType, is(NameType.SAME_AS));
        }
    });
    assertThat(taxa.size(), is(1));
    assertThat(taxa.get(0).getPath(), endsWith("Klebsiella | Klebsiella pneumoniae"));
}
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 10 with TermMatchListener

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

the class GlobalNamesServiceTest method createTaxaListFromNameListNCBI.

@Test
public void createTaxaListFromNameListNCBI() throws PropertyEnricherException {
    GlobalNamesService service = new GlobalNamesService(GlobalNamesSources.NCBI);
    final List<Taxon> foundTaxa = new ArrayList<Taxon>();
    service.findTermsForNames(Collections.singletonList("1|Prunus persica L."), new TermMatchListener() {

        @Override
        public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType nameType) {
            assertNotNull(nodeId);
            foundTaxa.add(taxon);
        }
    });
    assertThat(foundTaxa.size(), is(1));
    assertThat(foundTaxa.get(0).getExternalId(), is(TaxonomyProvider.NCBI.getIdPrefix() + "3760"));
}
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

ArrayList (java.util.ArrayList)10 NameType (org.eol.globi.domain.NameType)10 Taxon (org.eol.globi.domain.Taxon)10 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)8 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 PropertyEnricherException (org.eol.globi.service.PropertyEnricherException)1