Search in sources :

Example 6 with StudyNode

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

the class LinkerDOITest method createStudyDOIlookup.

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

Example 7 with StudyNode

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

the class LinkerDOITest method assertLinkMany.

public void assertLinkMany(int numberOfStudies) throws NodeFactoryException {
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", "some source", null, DOIResolverImplIT.HOCKING));
    getNodeFactory().getOrCreateStudy(new StudyImpl("title1", "some source", null, DOIResolverImplIT.MEDAN));
    assertThat(study.getDOI(), is(nullValue()));
    for (int i = 0; i < numberOfStudies; i++) {
        getNodeFactory().getOrCreateStudy(new StudyImpl("id" + i, "some source", null, "foo bar this is not a citation" + i));
    }
    new LinkerDOI(getGraphDb()).link();
    StudyNode studyResolved = getNodeFactory().getOrCreateStudy(study);
    assertThat(studyResolved.getDOI(), is(DOIResolverImplIT.HOCKING_DOI));
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl) StudyNode(org.eol.globi.domain.StudyNode)

Example 8 with StudyNode

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

the class ReportGenerator method generateReportForStudySources.

void generateReportForStudySources(SourceHandler sourceHandler) {
    final Set<String> groupByKeys = new HashSet<String>();
    NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode study) {
            String groupByKey = sourceHandler.parse(study);
            if (StringUtils.isNotBlank(groupByKey)) {
                groupByKeys.add(groupByKey);
            }
        }
    });
    for (final String groupByKey : groupByKeys) {
        final Set<Long> distinctTaxonIds = new HashSet<>();
        final Set<Long> distinctTaxonIdsNoMatch = new HashSet<>();
        final Counter counter = new Counter();
        final Counter studyCounter = new Counter();
        final Set<String> distinctSources = new HashSet<String>();
        final Set<String> distinctDatasets = new HashSet<String>();
        NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

            @Override
            public void onStudy(StudyNode study) {
                if (sourceHandler.matches(study, groupByKey)) {
                    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
                    countInteractionsAndTaxa(specimens, distinctTaxonIds, counter, distinctTaxonIdsNoMatch);
                    studyCounter.count();
                    distinctSources.add(study.getSource());
                    distinctDatasets.add(study.getSourceId());
                }
            }
        });
        Transaction tx = getGraphDb().beginTx();
        try {
            final Node node = getGraphDb().createNode();
            node.setProperty(sourceHandler.getGroupByKeyName(), groupByKey);
            node.setProperty(PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS, counter.getCount() / 2);
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA, distinctTaxonIds.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH, distinctTaxonIdsNoMatch.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES, studyCounter.getCount());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES, distinctSources.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS, distinctDatasets.size());
            getGraphDb().index().forNodes("reports").add(node, sourceHandler.getGroupByKeyName(), groupByKey);
            tx.success();
        } finally {
            tx.finish();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyNodeListener(org.eol.globi.util.StudyNodeListener) HashSet(java.util.HashSet) StudyNode(org.eol.globi.domain.StudyNode)

Example 9 with StudyNode

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

the class ReportGenerator method generateReportForCollection.

void generateReportForCollection() {
    final Set<Long> distinctTaxonIds = new HashSet<Long>();
    final Set<Long> distinctTaxonIdsNoMatch = new HashSet<Long>();
    final Counter counter = new Counter();
    final Counter studyCounter = new Counter();
    final Set<String> distinctSources = new HashSet<String>();
    final Set<String> distinctDatasets = new HashSet<String>();
    NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode study) {
            Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
            countInteractionsAndTaxa(specimens, distinctTaxonIds, counter, distinctTaxonIdsNoMatch);
            studyCounter.count();
            distinctSources.add(study.getSource());
            distinctDatasets.add(study.getSourceId());
        }
    });
    Transaction tx = getGraphDb().beginTx();
    try {
        final Node node = getGraphDb().createNode();
        node.setProperty(PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS, counter.getCount() / 2);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA, distinctTaxonIds.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH, distinctTaxonIdsNoMatch.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES, studyCounter.getCount());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES, distinctSources.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS, distinctDatasets.size());
        getGraphDb().index().forNodes("reports").add(node, PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
        tx.success();
    } finally {
        tx.finish();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyNodeListener(org.eol.globi.util.StudyNodeListener) HashSet(java.util.HashSet) StudyNode(org.eol.globi.domain.StudyNode)

Example 10 with StudyNode

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

the class ReportGenerator method generateReportForStudy.

protected void generateReportForStudy(StudyNode study, Set<Long> ids, Counter interactionCounter, HashSet<Long> idsNoMatch) {
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    countInteractionsAndTaxa(specimens, ids, interactionCounter, idsNoMatch);
    Transaction tx = getGraphDb().beginTx();
    try {
        Node node = getGraphDb().createNode();
        if (StringUtils.isNotBlank(study.getSource())) {
            node.setProperty(StudyConstant.SOURCE, study.getSource());
        }
        if (StringUtils.isNotBlank(study.getSourceId())) {
            node.setProperty(StudyConstant.SOURCE_ID, study.getSourceId());
        }
        if (StringUtils.isNotBlank(study.getCitation())) {
            node.setProperty(StudyConstant.CITATION, study.getCitation());
        }
        if (StringUtils.isNotBlank(study.getDOI())) {
            node.setProperty(StudyConstant.DOI, study.getDOI());
        }
        if (StringUtils.isNotBlank(study.getExternalId())) {
            node.setProperty(PropertyAndValueDictionary.EXTERNAL_ID, study.getExternalId());
        }
        node.setProperty(StudyConstant.TITLE, study.getTitle());
        node.setProperty(PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS, interactionCounter.getCount() / 2);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA, ids.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH, idsNoMatch.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES, 1);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES, 1);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS, 1);
        getGraphDb().index().forNodes("reports").add(node, StudyConstant.TITLE, study.getTitle());
        getGraphDb().index().forNodes("reports").add(node, StudyConstant.SOURCE, study.getTitle());
        tx.success();
    } finally {
        tx.finish();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode)

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