Search in sources :

Example 11 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class LinkerTrustyNanoPubsTest method link.

@Test
public void link() throws NodeFactoryException, OpenRDFException, IOException, MalformedNanopubException, TrustyUriException {
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com/dataset"));
    populateDataset(dataset);
    LinkerTrustyNanoPubs linker = new LinkerTrustyNanoPubs(getGraphDb());
    linker.link();
    Index<Node> nanopubs = getGraphDb().index().forNodes("nanopubs");
    IndexHits<Node> hits = nanopubs.query("code:\"RA7XQvcOGTux6HTndtjAiVWXjEMZbQMH4yJIxTMCV8sx4\"");
    assertThat(hits.hasNext(), is(true));
    Node nanopubRef = hits.next();
    assertThat(nanopubRef.getProperty("code"), is("RA7XQvcOGTux6HTndtjAiVWXjEMZbQMH4yJIxTMCV8sx4"));
    Iterable<Relationship> rels = nanopubRef.getRelationships(NodeUtil.asNeo4j(RelTypes.SUPPORTS), Direction.INCOMING);
    assertThat(rels.iterator().hasNext(), is(true));
    Relationship rel = rels.iterator().next();
    Iterable<Relationship> participants = rel.getStartNode().getRelationships(NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT), Direction.OUTGOING);
    Iterator<Relationship> iter = participants.iterator();
    assertTrue(iter.hasNext());
    iter.next();
    assertTrue(iter.hasNext());
    iter.next();
    assertFalse(iter.hasNext());
}
Also used : 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) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 12 with DatasetImpl

use of org.eol.globi.service.DatasetImpl 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 13 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForMetaTableIT method parseNaturalHistoryMuseum.

@Test
public void parseNaturalHistoryMuseum() throws IOException, StudyImporterException {
    final Class<StudyImporterForMetaTable> clazz = StudyImporterForMetaTable.class;
    final String name = "test-meta-globi-nhm.json";
    final URL resource = clazz.getResource(name);
    Assert.assertNotNull(resource);
    final JsonNode config = new ObjectMapper().readTree(clazz.getResourceAsStream(name));
    DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("http://example.com"));
    dataset.setConfig(config);
    final List<JsonNode> tables = StudyImporterForMetaTable.collectTables(dataset);
    assertThat(tables.size(), is(1));
    JsonNode firstTable = tables.get(0);
    String bibliographicCitation = firstTable.get("dcterms:bibliographicCitation").asText();
    assertThat(bibliographicCitation, containsString("NHM Interactions Bank. http://dx.doi.org/10.5519/0060767"));
    String resourceUrl = firstTable.get("url").asText();
    // see https://github.com/jhpoelen/eol-globi-data/issues/266
    // assertThat(resourceUrl, is("http://data.nhm.ac.uk/dataset/82e807f0-6273-4f19-be0a-7f7558442a25/resource/1f64e2cf-d738-4a7c-9e81-a1951eac635f/download/output.csv"));
    assertThat(firstTable.get("headerRowCount").asInt(), is(1));
    assertThat(firstTable.has("tableSchema"), is(true));
    assertThat(firstTable.has("null"), is(true));
    assertThat(firstTable.get("tableSchema").has("columns"), is(true));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) StringContains.containsString(org.junit.internal.matchers.StringContains.containsString) DatasetImpl(org.eol.globi.service.DatasetImpl) URL(java.net.URL) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 14 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4jTest method datasetWithNamespace.

private DatasetImpl datasetWithNamespace(String namespace) {
    DatasetImpl dataset = new DatasetImpl(namespace, URI.create("some:uri"));
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false);
    dataset.setConfig(objectNode);
    return dataset;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 15 with DatasetImpl

use of org.eol.globi.service.DatasetImpl in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4jTest method addDatasetToStudyNulls2.

@Test
public void addDatasetToStudyNulls2() throws NodeFactoryException {
    StudyImpl study1 = new StudyImpl("my title", "some source", "some doi", "some citation");
    DatasetImpl dataset = new DatasetImpl("some/namespace", null);
    study1.setOriginatingDataset(dataset);
    StudyNode study = getNodeFactory().getOrCreateStudy(study1);
    Node datasetNode = NodeUtil.getDataSetForStudy(study);
    assertThat(datasetNode.getProperty(DatasetConstant.NAMESPACE), is("some/namespace"));
    assertThat(datasetNode.hasProperty(DatasetConstant.ARCHIVE_URI), is(false));
    assertThat(datasetNode.getProperty(DatasetConstant.SHOULD_RESOLVE_REFERENCES), is("true"));
}
Also used : Node(org.neo4j.graphdb.Node) ObjectNode(org.codehaus.jackson.node.ObjectNode) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Aggregations

DatasetImpl (org.eol.globi.service.DatasetImpl)45 Test (org.junit.Test)31 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)24 JsonNode (org.codehaus.jackson.JsonNode)16 Study (org.eol.globi.domain.Study)13 Relationship (org.neo4j.graphdb.Relationship)9 ArrayList (java.util.ArrayList)6 ObjectNode (org.codehaus.jackson.node.ObjectNode)6 StudyImpl (org.eol.globi.domain.StudyImpl)6 Dataset (org.eol.globi.service.Dataset)6 Node (org.neo4j.graphdb.Node)5 InputStream (java.io.InputStream)4 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)4 NodeFactoryWithDatasetContext (org.eol.globi.data.NodeFactoryWithDatasetContext)3 LogContext (org.eol.globi.domain.LogContext)3 Specimen (org.eol.globi.domain.Specimen)3 Taxon (org.eol.globi.domain.Taxon)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2