Search in sources :

Example 1 with NameType

use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.

the class LinkerTermMatcher method handleBatch.

private void handleBatch(final GraphDatabaseService graphDb, TermMatcher termMatcher, final Map<Long, TaxonNode> nodeMap, int counter) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    String msgPrefix = "batch #" + counter / BATCH_SIZE;
    LOG.info(msgPrefix + " preparing...");
    List<String> nodeIdAndNames = new ArrayList<String>();
    for (Map.Entry<Long, TaxonNode> entry : nodeMap.entrySet()) {
        String name = entry.getKey() + "|" + entry.getValue().getName();
        nodeIdAndNames.add(name);
    }
    try {
        if (nodeIdAndNames.size() > 0) {
            termMatcher.findTermsForNames(nodeIdAndNames, new TermMatchListener() {

                @Override
                public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType relType) {
                    TaxonNode taxonNode = nodeMap.get(nodeId);
                    if (taxonNode != null && NameType.NONE != relType && !TaxonUtil.likelyHomonym(taxon, taxonNode)) {
                        NodeUtil.connectTaxa(taxon, taxonNode, graphDb, RelTypes.forType(relType));
                    }
                }
            });
        }
    } catch (PropertyEnricherException ex) {
        LOG.error(msgPrefix + " problem matching terms", ex);
    }
    stopWatch.stop();
    LOG.info(msgPrefix + " completed in [" + stopWatch.getTime() + "] ms (" + (1.0 * stopWatch.getTime() / BATCH_SIZE) + " ms/name )");
    nodeMap.clear();
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) StopWatch(org.apache.commons.lang.time.StopWatch) HashMap(java.util.HashMap) Map(java.util.Map) TermMatchListener(org.eol.globi.taxon.TermMatchListener)

Example 2 with NameType

use of org.eol.globi.domain.NameType 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 NameType

use of org.eol.globi.domain.NameType in project eol-globi-data by jhpoelen.

the class TaxonCacheServiceTest method matchTermByName.

@Test
public void matchTermByName() throws PropertyEnricherException {
    final TaxonCacheService cacheService = getTaxonCacheService();
    AtomicBoolean matched = new AtomicBoolean(false);
    cacheService.findTermsForNames(Arrays.asList("Green-winged teal"), new TermMatchListener() {

        @Override
        public void foundTaxonForName(Long nodeId, String name, Taxon enrichedTaxon, NameType nameType) {
            assertThat(enrichedTaxon.getExternalId(), is("EOL:1276240"));
            assertThat(enrichedTaxon.getName(), is("Anas crecca carolinensis"));
            assertThat(enrichedTaxon.getThumbnailUrl(), is("http://media.eol.org/content/2012/11/04/08/35791_98_68.jpg"));
            matched.set(true);
        }
    });
    assertTrue(matched.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Taxon(org.eol.globi.domain.Taxon) NameType(org.eol.globi.domain.NameType) Test(org.junit.Test)

Example 4 with NameType

use of org.eol.globi.domain.NameType 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 5 with NameType

use of org.eol.globi.domain.NameType 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)

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