use of org.eol.globi.db.GraphServiceFactoryProxy 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);
}
}
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class LinkerOpenTreeOfLifeTest method assertOTTLink.
protected void assertOTTLink(int expectedCount, String ottId, Taxon taxon) throws NodeFactoryException, PropertyEnricherException {
OpenTreeTaxonIndex index = null;
try {
index = new OpenTreeTaxonIndex(getClass().getResource("taxonomy-small.tsv"));
Taxon createdTaxon = taxonIndex.getOrCreateTaxon(taxon);
long nodeID = ((NodeBacked) createdTaxon).getNodeID();
new LinkerTermMatcher((terms, termMatchListener) -> {
for (Term term : terms) {
termMatchListener.foundTaxonForTerm(nodeID, term, NameType.SAME_AS, taxon);
}
}, new GraphServiceFactoryProxy(getGraphDb())).index();
new LinkerOpenTreeOfLife(index, new GraphServiceFactoryProxy(getGraphDb())).index();
Collection<String> externalIds = LinkerTestUtil.assertHasOther(taxon.getName(), expectedCount, taxonIndex, RelTypes.SAME_AS);
assertThat(externalIds, hasItem(TaxonomyProvider.OPEN_TREE_OF_LIFE.getIdPrefix() + ottId));
} finally {
if (index != null) {
index.destroy();
}
}
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class LinkerTermMatcherTest method assertTaxonMapping.
private void assertTaxonMapping(String classifiedId) throws NodeFactoryException {
Taxon taxon2 = new TaxonImpl("Holorchis castex", classifiedId);
Taxon createdTaxon = taxonIndex.getOrCreateTaxon(taxon2);
Node specimenDummy = getGraphDb().createNode();
Node originalTaxonDummy = getGraphDb().createNode();
originalTaxonDummy.setProperty("name", "holorchis castex");
originalTaxonDummy.setProperty("externalId", "EOL:11987314");
specimenDummy.createRelationshipTo(originalTaxonDummy, NodeUtil.asNeo4j(RelTypes.ORIGINALLY_DESCRIBED_AS));
specimenDummy.createRelationshipTo(((TaxonNode) createdTaxon).getUnderlyingNode(), NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
TaxonCacheService taxonCacheService = new TaxonCacheService("/org/eol/globi/taxon/taxonCacheHolorchis.tsv", "/org/eol/globi/taxon/taxonMapHolorchis.tsv");
new LinkerTermMatcher(taxonCacheService, new GraphServiceFactoryProxy(getGraphDb())).index();
Collection<String> externalIds = LinkerTestUtil.sameAsCountForNode(RelTypes.SAME_AS, (TaxonNode) createdTaxon);
assertThat(externalIds, hasItem("EOL_V2:11987314"));
assertThat(externalIds, hasItem("GBIF:5890922"));
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexerTest method indexNoNameNoMatch.
@Test
public void indexNoNameNoMatch() throws NodeFactoryException {
Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Homo sapiens", PropertyAndValueDictionary.NO_MATCH));
Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Canis lupus", PropertyAndValueDictionary.NO_MATCH));
human.ate(animal);
for (int i = 0; i < 10; i++) {
Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Arius felis", null));
human.ate(fish);
}
assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
new NameResolver(new GraphServiceFactoryProxy(getGraphDb()), new NonResolvingTaxonIndex(getGraphDb())).index();
assertNotNull(taxonIndex.findTaxonByName("Homo sapiens"));
assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
assertNull(taxonIndex.findTaxonByName(PropertyAndValueDictionary.NO_NAME));
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexerTest method buildTaxonInterIndex.
@Test
public void buildTaxonInterIndex() throws NodeFactoryException {
Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"));
Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Canis lupus", "WORMS:2"));
human.ate(animal);
for (int i = 0; i < 10; i++) {
Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
human.ate(fish);
}
assertNull(taxonIndex.findTaxonById("WORMS:2"));
assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
new NameResolver(new GraphServiceFactoryProxy(getGraphDb()), new NonResolvingTaxonIndex(getGraphDb())).index();
new TaxonInteractionIndexer(new GraphServiceFactoryProxy(getGraphDb())).index();
Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
assertNotNull(homoSapiens);
Iterable<Relationship> rels = ((NodeBacked) homoSapiens).getUnderlyingNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
List<String> humanFood = new ArrayList<String>();
List<Long> counts = new ArrayList<Long>();
List<String> labels = new ArrayList<>();
for (Relationship rel : rels) {
humanFood.add((String) rel.getEndNode().getProperty("name"));
counts.add((Long) rel.getProperty("count"));
labels.add((String) rel.getProperty("label"));
}
assertThat(humanFood.size(), is(4));
assertThat(humanFood, hasItems("Arius felis", "Canis lupus"));
assertThat(counts, hasItems(10L, 1L));
assertThat(labels, hasItems("eats"));
}
Aggregations