Search in sources :

Example 1 with TermMatchListener

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

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

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

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

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

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