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;
}
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());
}
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)));
}
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")));
}
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"));
}
Aggregations