use of org.eol.globi.data.NodeFactoryNeo4j 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/jhpoelen/eol-globi-data/wiki/Nanopubs
StudyImpl study = new StudyImpl("some study", "some source", "http://doi.org/123.23/222", "some study citation");
NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri")));
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(getGraphDb()).link();
NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
StudyImpl study1 = new StudyImpl("some study", "some source", null, "come citation");
study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri")));
StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
assertThat(interaction.getTitle(), is(someStudy.getTitle()));
Iterable<Relationship> specimens = NodeUtil.getSpecimens(someStudy);
RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
Set<Long> ids = new HashSet<>();
List<Long> idList = new ArrayList<>();
for (Relationship specimen : specimens) {
assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
Relationship singleRelationship = specimen.getEndNode().getSingleRelationship(hasParticipant, Direction.INCOMING);
long id = singleRelationship.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.data.NodeFactoryNeo4j in project eol-globi-data by jhpoelen.
the class Normalizer method importData.
void importData(GraphDatabaseService graphService, String cacheDir) {
NodeFactoryNeo4j factory = new NodeFactoryNeo4j(graphService);
factory.setEcoregionFinder(getEcoregionFinder());
factory.setDoiResolver(new DOIResolverImpl());
try {
CacheFactory cacheFactory = dataset -> new CacheLocalReadonly(dataset.getNamespace(), cacheDir);
DatasetFinder finder = new DatasetFinderLocal(cacheDir, cacheFactory);
StudyImporter importer = new StudyImporterForGitHubData(new ParserFactoryLocal(), factory, finder);
importer.setDataset(new DatasetLocal());
importer.setLogger(new StudyImportLogger());
importer.importStudy();
} catch (StudyImporterException e) {
LOG.error("problem encountered while importing [" + StudyImporterForGitHubData.class.getName() + "]", e);
}
EcoregionFinder regionFinder = getEcoregionFinder();
if (regionFinder != null) {
regionFinder.shutdown();
}
}
use of org.eol.globi.data.NodeFactoryNeo4j in project eol-globi-data by jhpoelen.
the class NormalizerTest method doSingleImport.
@Test
public void doSingleImport() throws IOException, StudyImporterException {
importData(StudyImporterForSimons.class, new NodeFactoryNeo4j(getGraphDb()));
GraphDatabaseService graphService = getGraphDb();
Study study = getStudySingleton(graphService);
assertThat(study.getTitle(), is("Simons 1997"));
assertNotNull(graphService.getNodeById(1));
assertNotNull(graphService.getNodeById(200));
}
use of org.eol.globi.data.NodeFactoryNeo4j in project eol-globi-data by jhpoelen.
the class NanoPressTest method init.
@Test
public void init() throws IOException {
FileUtils.deleteQuietly(new File("target/neo4j"));
// instantiate node factory to create indexes
new NodeFactoryNeo4j(GraphService.getGraphService("target/neo4j"));
List<String> ts = Arrays.asList("-i", "target/neo4j", "-o", "target/np");
NanoPress.main(ts.toArray(new String[ts.size()]));
}
Aggregations