use of org.eol.globi.domain.DatasetNode 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.domain.DatasetNode in project eol-globi-data by jhpoelen.
the class LinkerTrustyNanoPubs method doLink.
public void doLink() throws MalformedNanopubException, OpenRDFException, TrustyUriException {
LinkProgress progress = new LinkProgress(LOG::info);
progress.start();
Index<Node> datasets = graphDb.index().forNodes("datasets");
Index<Node> nanopubs = graphDb.index().forNodes("nanopubs");
for (Node node : datasets.query("*:*")) {
DatasetNode dataset = new DatasetNode(node);
Iterable<Relationship> rels = dataset.getUnderlyingNode().getRelationships(NodeUtil.asNeo4j(RelTypes.ACCESSED_AT), Direction.INCOMING);
for (Relationship rel : rels) {
InteractionNode interaction = new InteractionNode(rel.getStartNode());
String nanoPubString = writeNanoPub(dataset, interaction);
Nanopub trustyNanopub = generateTrustyNanopub(nanoPubString);
String artifactCode = TrustyUriUtils.getArtifactCode(trustyNanopub.getUri().toString());
IndexHits<Node> withSameCode = nanopubs.query("code:\"" + artifactCode + "\"");
if (!withSameCode.hasNext()) {
Transaction tx = graphDb.beginTx();
try {
Node npubNode = graphDb.createNode();
npubNode.setProperty("code", artifactCode);
interaction.getUnderlyingNode().createRelationshipTo(npubNode, NodeUtil.asNeo4j(RelTypes.SUPPORTS));
nanopubs.add(npubNode, "code", artifactCode);
tx.success();
} finally {
tx.finish();
}
}
withSameCode.close();
progress.progress();
}
}
}
Aggregations