use of org.eol.globi.tool.LinkerTaxonIndex in project eol-globi-data by jhpoelen.
the class ResolvingTaxonIndexTest method ensureThatEnrichedPropertiesAreLinked.
@Test
public void ensureThatEnrichedPropertiesAreLinked() throws NodeFactoryException {
this.taxonService = new ResolvingTaxonIndex(new PropertyEnricher() {
@Override
public Map<String, String> enrichFirstMatch(Map<String, String> properties) throws PropertyEnricherException {
return enrichAllMatches(properties).get(0);
}
@Override
public List<Map<String, String>> enrichAllMatches(Map<String, String> properties) throws PropertyEnricherException {
Taxon taxon1 = enrichTaxonWithSuffix(properties, "1");
Taxon taxon2 = enrichTaxonWithSuffix(properties, "2");
return Arrays.asList(TaxonUtil.taxonToMap(taxon1), TaxonUtil.taxonToMap(taxon2));
}
Taxon enrichTaxonWithSuffix(Map<String, String> properties, String suffix) {
Taxon taxon = TaxonUtil.mapToTaxon(properties);
taxon.setPathNames("kingdom" + suffix + CharsetConstant.SEPARATOR + "phylum" + CharsetConstant.SEPARATOR + "etc" + CharsetConstant.SEPARATOR);
taxon.setPath("a kingdom name" + suffix + CharsetConstant.SEPARATOR + "a phylum name" + CharsetConstant.SEPARATOR + "a etc name" + CharsetConstant.SEPARATOR);
taxon.setPathIds("a kingdom id" + suffix + CharsetConstant.SEPARATOR + "a phylum id" + CharsetConstant.SEPARATOR + "a etc id" + CharsetConstant.SEPARATOR);
taxon.setExternalId("anExternalId" + suffix);
taxon.setCommonNames(EXPECTED_COMMON_NAMES);
return taxon;
}
@Override
public void shutdown() {
}
}, getGraphDb());
assertThat(getGraphDb().index().existsForNodes("taxons"), is(false));
assertThat(getGraphDb().index().existsForNodes("thisDoesnoTExist"), is(false));
TaxonNode indexedTaxonNode = taxonService.getOrCreateTaxon(new TaxonImpl("some name1"));
assertThat(getGraphDb().index().existsForNodes("taxons"), is(true));
assertEnrichedPropertiesSet(indexedTaxonNode, "1");
TaxonNode someFoundTaxonNode = taxonService.findTaxonByName("some name1");
assertThat(someFoundTaxonNode.getNodeID(), is(indexedTaxonNode.getNodeID()));
assertEnrichedPropertiesSet(someFoundTaxonNode, "1");
{
Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
assertThat(ids.query("path:\"some name2\"").size(), is(0));
}
LinkerTaxonIndex linkerTaxonIndex = new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb()));
linkerTaxonIndex.index();
{
Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
IndexHits<Node> hits = ids.query("path:\"a kingdom name2\"");
assertThat(hits.size(), is(1));
for (Node hit : hits) {
TaxonNode taxonHit = new TaxonNode(hit);
assertNotNull(taxonHit);
assertThat(taxonHit.getNodeID(), is(indexedTaxonNode.getNodeID()));
}
}
TaxonNode someOtherFoundTaxonNodeTake2 = taxonService.findTaxonByName("some name2");
assertNull(someOtherFoundTaxonNodeTake2);
}
use of org.eol.globi.tool.LinkerTaxonIndex in project eol-globi-data by jhpoelen.
the class CypherTestUtil method validate.
public static void validate(CypherQuery cypherQuery, GraphDatabaseService graphDatabaseService) {
try (Transaction tx = graphDatabaseService.beginTx()) {
new NodeFactoryNeo4j2(graphDatabaseService);
new NonResolvingTaxonIndex(graphDatabaseService);
new LinkerTaxonIndex(new GraphServiceFactoryProxy(graphDatabaseService)).index();
CacheService cacheService = new CacheService();
File cacheDir = new File("target/reportGeneration" + UUID.randomUUID());
cacheService.setCacheDir(cacheDir);
CmdGenerateReport reportGenerator = new CmdGenerateReport(graphDatabaseService, cacheService);
reportGenerator.run(NOPLogger.NOP_LOGGER);
Map<String, Object> params = cypherQuery.getParams() == null ? Collections.emptyMap() : new HashMap<>(cypherQuery.getParams());
try {
graphDatabaseService.execute(cypherQuery.getVersionedQuery(), params);
} catch (NullPointerException ex) {
// encountered nullpointer exceptions were caused by initialization of graph database
throw ex;
} catch (RuntimeException ex) {
// work fine in cypher query, but cause parse exception when running programatically
if (!ex.getMessage().contains("Encountered \" \":\" \": \"\"")) {
throw ex;
}
} finally {
FileUtils.deleteQuietly(cacheDir);
}
}
}
Aggregations