Search in sources :

Example 1 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class InteractionImporter method studyOf.

private StudyImpl studyOf(Map<String, String> l) {
    String referenceCitation = l.get(REFERENCE_CITATION);
    DOI doi = null;
    String doiString = l.get(REFERENCE_DOI);
    try {
        doi = StringUtils.isBlank(doiString) ? null : DOI.create(doiString);
    } catch (MalformedDOIException e) {
        LogUtil.logWarningIfPossible(l, "found malformed doi [" + doiString + "]", logger);
    }
    StudyImpl study1 = new StudyImpl(l.get(REFERENCE_ID), doi, referenceCitation);
    final String referenceUrl = l.get(REFERENCE_URL);
    if (StringUtils.isBlank(study1.getExternalId()) && StringUtils.isNotBlank(referenceUrl)) {
        study1.setExternalId(referenceUrl);
    }
    return study1;
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl) DOI(org.globalbioticinteractions.doi.DOI) REFERENCE_DOI(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Example 2 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class ReferenceUtil method generateReferenceCitation.

public static String generateReferenceCitation(Map<String, String> properties) {
    StringBuilder citation = new StringBuilder();
    append(citation, properties.get(DatasetImporterForMetaTable.AUTHOR), ", ");
    append(citation, properties.get(DatasetImporterForMetaTable.YEAR), ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.TITLE), ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.JOURNAL), properties.containsKey(DatasetImporterForMetaTable.VOLUME) || properties.containsKey(DatasetImporterForMetaTable.NUMBER) || properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.VOLUME), properties.containsKey(DatasetImporterForMetaTable.NUMBER) ? "(" : (properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ". "));
    append(citation, properties.get(DatasetImporterForMetaTable.NUMBER), properties.containsKey(DatasetImporterForMetaTable.VOLUME) ? ")" : "");
    if (properties.containsKey(DatasetImporterForMetaTable.NUMBER)) {
        citation.append(properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ".");
    }
    append(citation, properties.get(DatasetImporterForMetaTable.PAGES), ". ", "pp.");
    String citationFromId = null;
    if (properties.containsKey(DatasetImporterForTSV.REFERENCE_DOI)) {
        String str = properties.get(DatasetImporterForTSV.REFERENCE_DOI);
        if (StringUtils.isNoneBlank(str)) {
            try {
                DOI doi = DOI.create(str);
                citationFromId = doi.toPrintableDOI();
            } catch (MalformedDOIException e) {
            // ignore malformed DOIs here
            }
        }
    }
    if (StringUtils.isBlank(citationFromId) && properties.containsKey(DatasetImporterForTSV.REFERENCE_URL)) {
        citationFromId = properties.get(DatasetImporterForTSV.REFERENCE_URL);
    }
    if (StringUtils.isNoneBlank(citationFromId)) {
        citation.append(citationFromId);
    }
    return StringUtils.trim(citation.toString());
}
Also used : DOI(org.globalbioticinteractions.doi.DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Example 3 with DOI

use of org.globalbioticinteractions.doi.DOI 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/globalbioticinteractions/globalbioticinteractions/wiki/Nanopubs
    StudyImpl study = new StudyImpl("some study", new DOI("123.23", "222"), "some study citation");
    NodeFactoryWithDatasetContext factory = new NodeFactoryWithDatasetContext(nodeFactory, new DatasetImpl("some/namespace", URI.create("https://some.uri"), inStream -> inStream));
    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(new GraphServiceFactoryProxy(getGraphDb())).index();
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j2(getGraphDb());
    StudyImpl study1 = new StudyImpl("some study", new DOI("123.23", "222"), "come citation");
    study1.setOriginatingDataset(new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream));
    StudyNode someStudy = nodeFactoryNeo4j.getOrCreateStudy(study1);
    assertThat(interaction.getOriginatingDataset().getNamespace(), is(someStudy.getOriginatingDataset().getNamespace()));
    assertThat(interaction.getTitle(), is(someStudy.getTitle()));
    RelationshipType hasParticipant = NodeUtil.asNeo4j(RelTypes.HAS_PARTICIPANT);
    Set<Long> ids = new HashSet<>();
    List<Long> idList = new ArrayList<>();
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(someStudy.getUnderlyingNode()), new RelationshipListener() {

        @Override
        public void on(Relationship specimen) {
            assertThat(specimen.getEndNode().hasRelationship(Direction.INCOMING, hasParticipant), Is.is(true));
            Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(hasParticipant, Direction.INCOMING);
            for (Relationship relationship : relationships) {
                long id = relationship.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)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TaxonIndex(org.eol.globi.data.TaxonIndex) NodeUtil(org.eol.globi.util.NodeUtil) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) Direction(org.neo4j.graphdb.Direction) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Is(org.hamcrest.core.Is) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaxonImpl(org.eol.globi.domain.TaxonImpl) RelationshipListener(org.eol.globi.util.RelationshipListener) DOI(org.globalbioticinteractions.doi.DOI) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Taxon(org.eol.globi.domain.Taxon) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipType(org.neo4j.graphdb.RelationshipType) Study(org.eol.globi.domain.Study) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) TaxonNode(org.eol.globi.domain.TaxonNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) TaxonNode(org.eol.globi.domain.TaxonNode) StudyImpl(org.eol.globi.domain.StudyImpl) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) RelationshipListener(org.eol.globi.util.RelationshipListener) Specimen(org.eol.globi.domain.Specimen) TaxonIndex(org.eol.globi.data.TaxonIndex) DOI(org.globalbioticinteractions.doi.DOI) HashSet(java.util.HashSet) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) NodeFactoryWithDatasetContext(org.eol.globi.data.NodeFactoryWithDatasetContext) StudyNode(org.eol.globi.domain.StudyNode) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) Test(org.junit.Test)

Example 4 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class LinkerDOITest method assertLinkMany.

private void assertLinkMany(long numberOfStudies) throws NodeFactoryException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "HOCKING"));
    getNodeFactory().getOrCreateStudy(new StudyImpl("title1", null, "MEDAN"));
    assertThat(study.getDOI(), is(nullValue()));
    for (int i = 0; i < numberOfStudies; i++) {
        getNodeFactory().getOrCreateStudy(new StudyImpl("id" + i, null, "foo bar this is not a citation" + i));
    }
    new LinkerDOI(new GraphServiceFactoryProxy(getGraphDb()), new DOIResolver() {

        @Override
        public Map<String, DOI> resolveDoiFor(Collection<String> references) throws IOException {
            Map<String, DOI> resolved = new HashMap<>();
            for (String reference : references) {
                resolved.put(reference, resolveDoiFor(reference));
            }
            return resolved;
        }

        @Override
        public DOI resolveDoiFor(String reference) throws IOException {
            return new DOI("123", "456");
        }
    }).index();
    StudyNode studyResolved = getNodeFactory().getOrCreateStudy(study);
    assertThat(studyResolved.getDOI(), is(new DOI("123", "456")));
}
Also used : HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) Collection(java.util.Collection) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) DOIResolver(org.eol.globi.service.DOIResolver) StudyNode(org.eol.globi.domain.StudyNode) DOI(org.globalbioticinteractions.doi.DOI)

Example 5 with DOI

use of org.globalbioticinteractions.doi.DOI in project eol-globi-data by jhpoelen.

the class LinkerDOITest method addDOIToStudy.

@Test
public void addDOIToStudy() throws NodeFactoryException {
    DOIResolver doiResolver = new DOIResolver() {

        @Override
        public Map<String, DOI> resolveDoiFor(Collection<String> references) throws IOException {
            Map<String, DOI> doiMap = new HashMap<>();
            for (String reference : references) {
                doiMap.put(reference, resolveDoiFor(reference));
            }
            return doiMap;
        }

        @Override
        public DOI resolveDoiFor(String reference) throws IOException {
            return new DOI("1234", "567");
        }
    };
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("my title", null, ExternalIdUtil.toCitation("my contr", "some description", null)));
    LinkerDOI.linkStudy(doiResolver, study);
    assertThat(study.getDOI().toString(), is("10.1234/567"));
    assertThat(study.getExternalId(), is("https://doi.org/10.1234/567"));
    assertThat(study.getCitation(), is("my contr. some description"));
    StudyImpl study1 = new StudyImpl("my other title", null, ExternalIdUtil.toCitation("my contr", "some description", null));
    assertThat(study1.getExternalId(), nullValue());
    study = getNodeFactory().getOrCreateStudy(study1);
    assertThat(study.getExternalId(), nullValue());
    LinkerDOI.linkStudy(new DOIResolverThatExplodes(), study);
    assertThat(study.getDOI(), nullValue());
    assertThat(study.getExternalId(), nullValue());
    assertThat(study.getCitation(), is("my contr. some description"));
}
Also used : HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) Collection(java.util.Collection) DOIResolver(org.eol.globi.service.DOIResolver) DOI(org.globalbioticinteractions.doi.DOI) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Aggregations

DOI (org.globalbioticinteractions.doi.DOI)74 Test (org.junit.Test)50 StudyImpl (org.eol.globi.domain.StudyImpl)28 IOException (java.io.IOException)15 Study (org.eol.globi.domain.Study)15 Specimen (org.eol.globi.domain.Specimen)13 StudyNode (org.eol.globi.domain.StudyNode)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)11 URI (java.net.URI)10 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)8 MalformedDOIException (org.globalbioticinteractions.doi.MalformedDOIException)8 Location (org.eol.globi.domain.Location)7 LocationImpl (org.eol.globi.domain.LocationImpl)7 ArrayList (java.util.ArrayList)6 Dataset (org.globalbioticinteractions.dataset.Dataset)6 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5