Search in sources :

Example 1 with InteractionNode

use of org.eol.globi.domain.InteractionNode 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));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Relationship(org.neo4j.graphdb.Relationship) DatasetImpl(org.eol.globi.service.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) InteractionNode(org.eol.globi.domain.InteractionNode) DatasetNode(org.eol.globi.domain.DatasetNode) Test(org.junit.Test)

Example 2 with InteractionNode

use of org.eol.globi.domain.InteractionNode 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();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatasetNode(org.eol.globi.domain.DatasetNode) InteractionNode(org.eol.globi.domain.InteractionNode) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) Nanopub(org.nanopub.Nanopub) MakeTrustyNanopub(org.nanopub.trusty.MakeTrustyNanopub) InteractionNode(org.eol.globi.domain.InteractionNode) DatasetNode(org.eol.globi.domain.DatasetNode)

Aggregations

DatasetNode (org.eol.globi.domain.DatasetNode)2 InteractionNode (org.eol.globi.domain.InteractionNode)2 Relationship (org.neo4j.graphdb.Relationship)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)1 TaxonNode (org.eol.globi.domain.TaxonNode)1 DatasetImpl (org.eol.globi.service.DatasetImpl)1 Test (org.junit.Test)1 Nanopub (org.nanopub.Nanopub)1 MakeTrustyNanopub (org.nanopub.trusty.MakeTrustyNanopub)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1