Search in sources :

Example 46 with Dataset

use of org.globalbioticinteractions.dataset.Dataset in project eol-globi-data by jhpoelen.

the class DatasetImporterForTSVTest method assertEventDate.

private void assertEventDate(String header) throws StudyImporterException {
    AtomicInteger atomicInteger = new AtomicInteger(0);
    String firstFewLines = header + "\tITIS:632267\tRousettus aegyptiacus\t\t\t\t\thttp://purl.obolibrary.org/obo/RO_0002470\teats\t\tITIS:28882\tCitrus sp.\thttp://purl.obolibrary.org/obo/PO_0009001\tfruit\t\t\tGEONAMES:298795\tHatay, Adana, Mersin, and Antalya, Turkey\t\t\t1999-09/2003-09\t\thttp://journals.tubitak.gov.tr/zoology/issues/zoo-08-32-1/zoo-32-1-2-0604-8.pdf\tAlbayrak, I., Aşan, N., & Yorulmaz, T. (2008). The natural history of the Egyptian fruit bat, Rousettus aegyptiacus, in Turkey (Mammalia: Chiroptera). Turkish Journal of Zoology, 32(1), 11-18.";
    Dataset dataset = getDataset(new TreeMap<URI, String>() {

        {
            put(URI.create("/interactions.tsv"), firstFewLines);
        }
    });
    DatasetImporterForTSV importer = new DatasetImporterForTSV(null, nodeFactory);
    importer.setDataset(dataset);
    importer.setInteractionListener(link -> {
        atomicInteger.incrementAndGet();
        assertThat(link.get(DatasetImporterForMetaTable.EVENT_DATE), is(not(nullValue())));
        assertThat(link.get(SOURCE_TAXON_NAME), is("Rousettus aegyptiacus"));
        assertThat(link.get(TARGET_TAXON_NAME), is("Citrus sp."));
    });
    importStudy(importer);
    assertThat(atomicInteger.get(), is(1));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Dataset(org.globalbioticinteractions.dataset.Dataset) URI(java.net.URI)

Example 47 with Dataset

use of org.globalbioticinteractions.dataset.Dataset in project eol-globi-data by jhpoelen.

the class DatasetImporterForRSSIT method importUCSB.

@Test
public void importUCSB() throws StudyImporterException, IOException {
    File tempFile = File.createTempFile("test", ".tmp", new File("target"));
    DatasetImporter importer = new StudyImporterTestFactory(nodeFactory).instantiateImporter(DatasetImporterForRSS.class);
    final DatasetLocal dataset = new DatasetLocal(inStream -> inStream);
    DatasetWithCache datasetWithCache = new DatasetWithCache(dataset, new CachePullThrough("testing", tempFile.getParentFile().getAbsolutePath()));
    ObjectNode rssUrl = new ObjectMapper().createObjectNode();
    rssUrl.put("rss", "https://symbiota.ccber.ucsb.edu/webservices/dwc/rss.xml");
    ObjectNode configNode = new ObjectMapper().createObjectNode();
    configNode.set("resources", rssUrl);
    datasetWithCache.setConfig(configNode);
    importer.setDataset(datasetWithCache);
    importStudy(importer);
    final Dataset datasetImported = nodeFactory.getOrCreateDataset(dataset);
    assertThat(datasetImported.getNamespace(), Is.is("jhpoelen/eol-globidata"));
}
Also used : CachePullThrough(org.globalbioticinteractions.cache.CachePullThrough) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(org.globalbioticinteractions.dataset.Dataset) File(java.io.File) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetWithCache(org.globalbioticinteractions.dataset.DatasetWithCache) Test(org.junit.Test)

Example 48 with Dataset

use of org.globalbioticinteractions.dataset.Dataset in project eol-globi-data by jhpoelen.

the class DatasetImporterForSeltmannTest method importSome.

@Test
public void importSome() throws StudyImporterException, IOException {
    DatasetImporterForSeltmann importer = new DatasetImporterForSeltmann(null, nodeFactory);
    Dataset dataset = new DatasetLocal(inStream -> inStream);
    JsonNode config = new ObjectMapper().readTree("{\"citation\": \"some citation\", \"resources\": {\"archive\": \"seltmann/testArchive.zip\"}}");
    dataset.setConfig(config);
    importer.setDataset(dataset);
    importStudy(importer);
    List<StudyNode> allStudies = NodeUtil.findAllStudies(getGraphDb());
    for (StudyNode allStudy : allStudies) {
        assertThat(allStudy.getCitation(), is("Digital Bee Collections Network, 2014 (and updates). Version: 2015-03-18. National Science Foundation grant DBI 0956388"));
        AtomicBoolean success = new AtomicBoolean(false);
        NodeUtil.handleCollectedRelationships(new NodeTypeDirection(allStudy.getUnderlyingNode()), relationship -> {
            SpecimenNode spec = new SpecimenNode(relationship.getEndNode());
            final String recordId = (String) spec.getUnderlyingNode().getProperty("idigbio:recordID");
            assertThat(recordId, is(notNullValue()));
            assertThat(spec.getExternalId(), is(recordId));
            Term basisOfRecord = spec.getBasisOfRecord();
            assertThat(basisOfRecord.getId(), either(is("TEST:PreservedSpecimen")).or(is("TEST:LabelObservation")));
            assertThat(basisOfRecord.getName(), either(is("PreservedSpecimen")).or(is("LabelObservation")));
            success.set(true);
        });
        assertTrue(success.get());
    }
    assertThat(taxonIndex.findTaxonByName("Megandrena mentzeliae"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Mentzelia tricuspis"), is(notNullValue()));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Dataset(org.globalbioticinteractions.dataset.Dataset) JsonNode(com.fasterxml.jackson.databind.JsonNode) Term(org.eol.globi.domain.Term) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Example 49 with Dataset

use of org.globalbioticinteractions.dataset.Dataset in project eol-globi-data by jhpoelen.

the class CmdGenerateReportTest method generateIndividualStudySourceReports.

@Test
public void generateIndividualStudySourceReports() throws NodeFactoryException {
    Dataset originatingDataset1 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source", URI.create("http://example.com"), inStream -> inStream));
    StudyImpl study1 = new StudyImpl("a title", null, "citation");
    study1.setOriginatingDataset(originatingDataset1);
    createStudy(study1);
    StudyImpl study2 = new StudyImpl("another title", null, "citation");
    study2.setOriginatingDataset(originatingDataset1);
    createStudy(study2);
    Dataset originatingDataset3 = nodeFactory.getOrCreateDataset(new DatasetImpl("zother/source", URI.create("http://example.com"), inStream -> inStream));
    StudyImpl study3 = new StudyImpl("yet another title", null, null);
    study3.setOriginatingDataset(originatingDataset3);
    createStudy(study3);
    resolveNames();
    new CmdGenerateReport(getGraphDb(), cacheService).generateReportForSourceIndividuals();
    String escapedQuery = QueryParser.escape("globi:az/source");
    IndexHits<Node> reports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, escapedQuery);
    Node reportNode = reports.getSingle();
    assertThat(reportNode.getProperty(StudyConstant.SOURCE_ID), is("globi:az/source"));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(2));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(8));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
    reports.close();
    IndexHits<Node> otherReports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:zother\\/source");
    Node otherReport = otherReports.getSingle();
    assertThat(otherReport.getProperty(StudyConstant.SOURCE_ID), is("globi:zother/source"));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(4));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
}
Also used : CacheService(org.eol.globi.service.CacheService) IndexHits(org.neo4j.graphdb.index.IndexHits) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) StudyConstant(org.eol.globi.domain.StudyConstant) Test(org.junit.Test) IOException(java.io.IOException) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Rule(org.junit.Rule) TaxonImpl(org.eol.globi.domain.TaxonImpl) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Dataset(org.globalbioticinteractions.dataset.Dataset) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Study(org.eol.globi.domain.Study) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Dataset(org.globalbioticinteractions.dataset.Dataset) Node(org.neo4j.graphdb.Node) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 50 with Dataset

use of org.globalbioticinteractions.dataset.Dataset in project eol-globi-data by jhpoelen.

the class CmdGenerateReportTest method generateStudySourceOrganizationReports.

@Test
public void generateStudySourceOrganizationReports() throws NodeFactoryException {
    Dataset originatingDataset1 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source1", URI.create("http://example.com"), inStream -> inStream));
    StudyImpl study1 = new StudyImpl("a title", null, "citation");
    study1.setOriginatingDataset(originatingDataset1);
    createStudy(study1);
    Dataset originatingDataset2 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source2", URI.create("http://example.com"), inStream -> inStream));
    StudyImpl study2 = new StudyImpl("another title", null, "citation");
    study2.setOriginatingDataset(originatingDataset2);
    createStudy(study2);
    Dataset originatingDataset3 = nodeFactory.getOrCreateDataset(new DatasetImpl("zother/source", URI.create("http://example.com"), inStream -> inStream));
    StudyImpl study3 = new StudyImpl("yet another title", null, null);
    study3.setOriginatingDataset(originatingDataset3);
    createStudy(study3);
    resolveNames();
    new CmdGenerateReport(getGraphDb(), cacheService).generateReportForSourceOrganizations();
    IndexHits<Node> reports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:az");
    Node reportNode = reports.getSingle();
    assertThat(reportNode.getProperty(StudyConstant.SOURCE_ID), is("globi:az"));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(2));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(2));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(2));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(8));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
    assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
    reports.close();
    IndexHits<Node> otherReports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:zother");
    Node otherReport = otherReports.getSingle();
    assertThat(otherReport.getProperty(StudyConstant.SOURCE_ID), is("globi:zother"));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(4));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
    assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
}
Also used : CacheService(org.eol.globi.service.CacheService) IndexHits(org.neo4j.graphdb.index.IndexHits) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) StudyConstant(org.eol.globi.domain.StudyConstant) Test(org.junit.Test) IOException(java.io.IOException) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Rule(org.junit.Rule) TaxonImpl(org.eol.globi.domain.TaxonImpl) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Dataset(org.globalbioticinteractions.dataset.Dataset) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Study(org.eol.globi.domain.Study) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Dataset(org.globalbioticinteractions.dataset.Dataset) Node(org.neo4j.graphdb.Node) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Aggregations

Dataset (org.globalbioticinteractions.dataset.Dataset)68 Test (org.junit.Test)46 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)25 URI (java.net.URI)20 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Matchers.containsString (org.hamcrest.Matchers.containsString)14 IOException (java.io.IOException)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 InputStream (java.io.InputStream)9 Is.is (org.hamcrest.core.Is.is)9 StudyNode (org.eol.globi.domain.StudyNode)8 Node (org.neo4j.graphdb.Node)8 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 StringStartsWith.startsWith (org.hamcrest.core.StringStartsWith.startsWith)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 BaseDatasetImporter (org.eol.globi.data.BaseDatasetImporter)6 DatasetImporter (org.eol.globi.data.DatasetImporter)6 DatasetNode (org.eol.globi.domain.DatasetNode)6