Search in sources :

Example 11 with StudyNode

use of org.eol.globi.domain.StudyNode in project eol-globi-data by jhpoelen.

the class NodeUtil method findStudies.

public static void findStudies(GraphDatabaseService graphService, StudyNodeListener listener) {
    Index<Node> studyIndex = graphService.index().forNodes("studies");
    IndexHits<Node> hits = studyIndex.query("title", "*");
    for (Node hit : hits) {
        listener.onStudy(new StudyNode(hit));
    }
    hits.close();
}
Also used : StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyNode(org.eol.globi.domain.StudyNode)

Example 12 with StudyNode

use of org.eol.globi.domain.StudyNode in project eol-globi-data by jhpoelen.

the class ExporterOccurrences method addOccurrenceProperties.

private void addOccurrenceProperties(Node locationNode, Relationship collectedRelationship, Map<String, String> properties, Node specimenNode, Study study) throws IOException {
    if (specimenNode != null) {
        Iterable<Relationship> relationships = specimenNode.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
        Iterator<Relationship> iterator = relationships.iterator();
        if (iterator.hasNext()) {
            Relationship classifiedAs = iterator.next();
            if (classifiedAs != null) {
                Node taxonNode = classifiedAs.getEndNode();
                if (taxonNode.hasProperty(PropertyAndValueDictionary.EXTERNAL_ID)) {
                    String taxonId = (String) taxonNode.getProperty(PropertyAndValueDictionary.EXTERNAL_ID);
                    if (taxonId != null) {
                        properties.put(EOLDictionary.TAXON_ID, taxonId);
                    }
                }
                if (taxonNode.hasProperty(PropertyAndValueDictionary.NAME)) {
                    String taxonName = (String) taxonNode.getProperty(PropertyAndValueDictionary.NAME);
                    if (taxonName != null) {
                        properties.put(EOLDictionary.SCIENTIFIC_NAME, taxonName);
                    }
                }
            }
        }
    }
    properties.put(EOLDictionary.OCCURRENCE_ID, "globi:occur:" + specimenNode.getId());
    addProperty(properties, specimenNode, SpecimenConstant.BASIS_OF_RECORD_LABEL, EOLDictionary.BASIS_OF_RECORD);
    addProperty(properties, specimenNode, SpecimenConstant.LIFE_STAGE_LABEL, EOLDictionary.LIFE_STAGE);
    addProperty(properties, specimenNode, SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, EOLDictionary.PHYSIOLOGICAL_STATE);
    addProperty(properties, specimenNode, SpecimenConstant.BODY_PART_LABEL, EOLDictionary.BODY_PART);
    addProperty(properties, locationNode, LocationConstant.LATITUDE, EOLDictionary.DECIMAL_LATITUDE);
    addProperty(properties, locationNode, LocationConstant.LONGITUDE, EOLDictionary.DECIMAL_LONGITUDE);
    if (locationNode != null && locationNode.hasProperty(LocationConstant.ALTITUDE)) {
        properties.put(EOLDictionary.VERBATIM_ELEVATION, locationNode.getProperty(LocationConstant.ALTITUDE).toString() + " m");
    }
    addProperty(properties, ((StudyNode) study).getUnderlyingNode(), StudyConstant.TITLE, EOLDictionary.EVENT_ID);
    addCollectionDate(properties, collectedRelationship, EOLDictionary.EVENT_DATE);
}
Also used : Relationship(org.neo4j.graphdb.Relationship) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node)

Example 13 with StudyNode

use of org.eol.globi.domain.StudyNode in project eol-globi-data by jhpoelen.

the class ExporterAggregateUtil method exportDistinctInteractionsByStudy.

public static void exportDistinctInteractionsByStudy(Writer writer, GraphDatabaseService graphDatabase, RowWriter rowWriter) throws IOException {
    DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
    final Map<Fun.Tuple3<Long, String, String>, List<String>> studyOccAggregate = db.createTreeMap("studyOccAggregate").make();
    NodeUtil.findStudies(graphDatabase, new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode aStudy) {
            collectDistinctInteractions(aStudy, studyOccAggregate);
        }
    });
    for (Map.Entry<Fun.Tuple3<Long, String, String>, List<String>> distinctInteractions : studyOccAggregate.entrySet()) {
        rowWriter.writeRow(writer, new StudyNode(graphDatabase.getNodeById(distinctInteractions.getKey().a)), distinctInteractions.getKey().b, distinctInteractions.getKey().c, distinctInteractions.getValue());
    }
    db.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) StudyNodeListener(org.eol.globi.util.StudyNodeListener) Map(java.util.Map) DB(org.mapdb.DB) StudyNode(org.eol.globi.domain.StudyNode)

Example 14 with StudyNode

use of org.eol.globi.domain.StudyNode in project eol-globi-data by jhpoelen.

the class LinkerDOITest method createStudyDOIlookupCitationWithURL.

@Test
public void createStudyDOIlookupCitationWithURL() throws NodeFactoryException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", "some source", null, "http://bla"));
    new LinkerDOI(getGraphDb()).linkStudy(new DOIResolverThatFails(), study);
    assertThat(study.getSource(), is("some source"));
    assertThat(study.getCitation(), is("http://bla"));
    assertThat(study.getTitle(), is("title"));
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 15 with StudyNode

use of org.eol.globi.domain.StudyNode in project eol-globi-data by jhpoelen.

the class LinkerDOITest method createStudyDOIlookupCitationEnabled.

@Test
public void createStudyDOIlookupCitationEnabled() throws NodeFactoryException {
    StudyImpl title = new StudyImpl("title", "some source", null, "some citation");
    DatasetImpl originatingDataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, true);
    originatingDataset.setConfig(objectNode);
    title.setOriginatingDataset(originatingDataset);
    StudyNode study = getNodeFactory().getOrCreateStudy(title);
    new LinkerDOI(getGraphDb()).linkStudy(new TestDOIResolver(), study);
    assertThat(study.getSource(), is("some source"));
    assertThat(study.getDOI(), is("doi:some citation"));
    assertThat(study.getCitation(), is("some citation"));
    assertThat(study.getTitle(), is("title"));
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.eol.globi.service.DatasetImpl) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Aggregations

StudyNode (org.eol.globi.domain.StudyNode)15 Node (org.neo4j.graphdb.Node)8 StudyImpl (org.eol.globi.domain.StudyImpl)7 TaxonNode (org.eol.globi.domain.TaxonNode)6 Test (org.junit.Test)6 Relationship (org.neo4j.graphdb.Relationship)4 HashSet (java.util.HashSet)3 StudyNodeListener (org.eol.globi.util.StudyNodeListener)3 Transaction (org.neo4j.graphdb.Transaction)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Study (org.eol.globi.domain.Study)2 DatasetImpl (org.eol.globi.service.DatasetImpl)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 NodeFactoryNeo4j (org.eol.globi.data.NodeFactoryNeo4j)1