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();
}
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 + "]");
}
}
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));
}
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));
}
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));
}
Aggregations