use of org.eol.globi.db.GraphServiceFactoryProxy 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.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class IndexInteractionsTest method indexInteractions.
@Test
public void indexInteractions() throws NodeFactoryException {
TaxonIndex taxonIndex = getOrCreateTaxonIndex();
// see https://github.com/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
Study interaction = factory.getOrCreateStudy(study);
TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
TaxonImpl mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
Taxon mickeyTaxonNCBI = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonNCBI, getGraphDb(), RelTypes.SAME_AS);
Specimen mickey = factory.createSpecimen(interaction, mickeyTaxon);
mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxon));
donald.ate(mickey);
new IndexInteractions(new GraphServiceFactoryProxy(getGraphDb())).index();
NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
assertThat(interaction.getTitle(), is(someStudy.getTitle()));
RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
Set<Long> ids = new HashSet<>();
List<Long> idList = new ArrayList<>();
NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {
@Override
public void on(Relationship specimen) {
assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
for (Relationship relationship : relationships) {
long id = relationship.getStartNode().getId();
ids.add(id);
idList.add(id);
}
}
});
assertThat(ids.size(), Is.is(1));
assertThat(idList.size(), Is.is(2));
Node interactionNode = getGraphDb().getNodeById(idList.get(0));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.DERIVED_FROM)));
assertTrue(interactionNode.hasRelationship(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.ACCESSED_AT)));
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class LinkerDOITest method assertLinkMany.
private void assertLinkMany(long numberOfStudies) throws NodeFactoryException {
StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "HOCKING"));
getNodeFactory().getOrCreateStudy(new StudyImpl("title1", null, "MEDAN"));
assertThat(study.getDOI(), is(nullValue()));
for (int i = 0; i < numberOfStudies; i++) {
getNodeFactory().getOrCreateStudy(new StudyImpl("id" + i, null, "foo bar this is not a citation" + i));
}
new LinkerDOI(new GraphServiceFactoryProxy(getGraphDb()), new DOIResolver() {
@Override
public Map<String, DOI> resolveDoiFor(Collection<String> references) throws IOException {
Map<String, DOI> resolved = new HashMap<>();
for (String reference : references) {
resolved.put(reference, resolveDoiFor(reference));
}
return resolved;
}
@Override
public DOI resolveDoiFor(String reference) throws IOException {
return new DOI("123", "456");
}
}).index();
StudyNode studyResolved = getNodeFactory().getOrCreateStudy(study);
assertThat(studyResolved.getDOI(), is(new DOI("123", "456")));
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class LinkerDOITest method doLink.
@Test
public void doLink() throws NodeFactoryException, PropertyEnricherException {
StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "some citation"));
new LinkerDOI(new GraphServiceFactoryProxy(getGraphDb())).index();
Study studyResolved = nodeFactory.getOrCreateStudy(study);
assertThat(studyResolved.getDOI(), is(nullValue()));
assertThat(study.getDOI(), is(nullValue()));
}
use of org.eol.globi.db.GraphServiceFactoryProxy in project eol-globi-data by jhpoelen.
the class LinkerTaxonIndexTest method linkingWithNameOnly.
@Test
public void linkingWithNameOnly() throws NodeFactoryException {
Taxon taxonFound = new TaxonImpl("urn:catalog:AMNH:Mammals:M-39582", null);
taxonIndex.getOrCreateTaxon(taxonFound);
Taxon foundTaxon = taxonIndex.findTaxonByName("urn:catalog:AMNH:Mammals:M-39582");
assertThat(foundTaxon, is(not(nullValue())));
assertThat(foundTaxon.getName(), is("urn:catalog:AMNH:Mammals:M-39582"));
resolveNames();
new LinkerTaxonIndex(new GraphServiceFactoryProxy(getGraphDb())).index();
IndexHits<Node> hits = getGraphDb().index().forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS).query("path:\"urn:catalog:AMNH:Mammals:M-39582\"");
Node next = hits.next();
assertThat(new TaxonNode(next).getName(), is("urn:catalog:AMNH:Mammals:M-39582"));
assertThat(hits.hasNext(), is(false));
hits.close();
}
Aggregations