use of org.eol.globi.data.NodeFactoryWithDatasetContext in project eol-globi-data by jhpoelen.
the class LinkerTrustyNanoPubsTest method writingNanopub.
@Test
public void writingNanopub() throws NodeFactoryException, OpenRDFException, IOException, MalformedNanopubException, TrustyUriException {
DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com/dataset"));
NodeFactoryWithDatasetContext factory = populateDataset(dataset);
LinkerTrustyNanoPubs linker = new LinkerTrustyNanoPubs(getGraphDb());
linker.link();
DatasetNode datasetNode = (DatasetNode) factory.getOrCreateDataset(dataset);
Iterable<Relationship> rels = datasetNode.getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(RelTypes.ACCESSED_AT), Direction.INCOMING);
InteractionNode interactionNode = new InteractionNode(rels.iterator().next().getStartNode());
String nanoPubText = LinkerTrustyNanoPubs.writeNanoPub(datasetNode, interactionNode);
InputStream rdfIn = IOUtils.toInputStream(nanoPubText);
String rdfActual = toTrigString(rdfIn);
String rdfExpected = toTrigString(getClass().getResourceAsStream("nanopub.trig"));
assertThat(rdfActual, is(rdfExpected));
}
use of org.eol.globi.data.NodeFactoryWithDatasetContext 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.NodeFactoryWithDatasetContext in project eol-globi-data by jhpoelen.
the class LinkerTrustyNanoPubsTest method populateDataset.
public NodeFactoryWithDatasetContext populateDataset(DatasetImpl dataset) 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, dataset);
Interaction interaction = factory.createInteraction(factory.createStudy(study));
TaxonImpl donaldTaxon = new TaxonImpl("donald duck", "NCBI:1234");
Specimen donald = factory.createSpecimen(interaction, donaldTaxon);
donald.classifyAs(taxonIndex.getOrCreateTaxon(donaldTaxon));
Taxon mickeyTaxon = new TaxonImpl("mickey mouse", "NCBI:4444");
Taxon mickeyTaxonEOL = taxonIndex.getOrCreateTaxon(new TaxonImpl("mickey mouse", "EOL:567"));
NodeUtil.connectTaxa(mickeyTaxon, (TaxonNode) mickeyTaxonEOL, getGraphDb(), RelTypes.SAME_AS);
Specimen mickey = factory.createSpecimen(interaction, mickeyTaxonEOL);
mickey.classifyAs(taxonIndex.getOrCreateTaxon(mickeyTaxonEOL));
donald.ate(mickey);
return factory;
}
use of org.eol.globi.data.NodeFactoryWithDatasetContext in project eol-globi-data by jhpoelen.
the class GitHubImporterFactory method createImporter.
public StudyImporter createImporter(Dataset dataset, final NodeFactory nodeFactory) throws StudyImporterException {
Class<? extends StudyImporter> anImporter = findImporterFor(dataset);
try {
Constructor<? extends StudyImporter> constructor = anImporter.getConstructor(ParserFactory.class, NodeFactory.class);
ParserFactoryForDataset parserFactory = new ParserFactoryForDataset(dataset);
StudyImporter studyImporter = constructor.newInstance(parserFactory, new NodeFactoryWithDatasetContext(nodeFactory, dataset));
studyImporter.setDataset(dataset);
return studyImporter;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
throw new StudyImporterException("failed to instantiate importer for [" + dataset.getNamespace() + "]", e);
}
}
use of org.eol.globi.data.NodeFactoryWithDatasetContext in project eol-globi-data by jhpoelen.
the class ExportFlatInteractionsTest method init.
@Before
public void init() throws IOException {
super.startGraphDb();
DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
factory = new NodeFactoryWithDatasetContext(nodeFactory, dataset);
}
Aggregations