Search in sources :

Example 31 with Location

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

the class StudyImporterForCruaud method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser dataParser;
    try {
        dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
    }
    try {
        Study study = nodeFactory.getOrCreateStudy(new StudyImpl("cruaud", SOURCE, "http://dx.doi.org/10.1093/sysbio/sys068", null));
        while (dataParser.getLine() != null) {
            if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
                try {
                    String parasiteName = StringUtils.trim(dataParser.getValueByLabel("Family and Species"));
                    String hostName = StringUtils.trim(dataParser.getValueByLabel("Natural host Ficus species"));
                    hostName = StringUtils.replace(hostName, "F.", "Ficus");
                    if (areNamesAvailable(parasiteName, hostName)) {
                        Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
                        Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
                        parasite.interactsWith(host, InteractType.PARASITE_OF);
                        String samplingLocation = StringUtils.trim(dataParser.getValueByLabel("Sampling location"));
                        if (getGeoNamesService().hasTermForLocale(samplingLocation)) {
                            LatLng pointForLocality = getGeoNamesService().findLatLng(samplingLocation);
                            if (pointForLocality == null) {
                                LOG.warn("no location associated with locality [" + samplingLocation + "]");
                            } else {
                                Location location = nodeFactory.getOrCreateLocation(new LocationImpl(pointForLocality.getLat(), pointForLocality.getLng(), null, null));
                                parasite.caughtIn(location);
                                host.caughtIn(location);
                            }
                        } else {
                            LOG.warn("no location associated with locality [" + samplingLocation + "]");
                        }
                    }
                } catch (NodeFactoryException | NumberFormatException e) {
                    throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 32 with Location

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

the class StudyImporterForDunne method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    Study study = createStudy();
    try {
        LabeledCSVParser nodes = parserFactory.createParser(getNodesResourceName(), CharsetConstant.UTF8);
        nodes.changeDelimiter(getDelimiter());
        Map<Integer, Taxon> taxonForNode = new HashMap<Integer, Taxon>();
        while (nodes.getLine() != null) {
            Integer nodeId = getNodeId(nodes);
            if (nodeId != null) {
                final String tsn = nodes.getValueByLabel("TSN");
                taxonForNode.put(nodeId, new TaxonImpl(nodes.getValueByLabel("Name"), TaxonomyProvider.ID_PREFIX_ITIS + tsn));
            }
        }
        LabeledCSVParser links = parserFactory.createParser(getLinksResourceName(), CharsetConstant.UTF8);
        links.changeDelimiter(getDelimiter());
        while (links.getLine() != null) {
            List<Location> locations = new ArrayList<>();
            if (getLocation() != null) {
                Location loc = nodeFactory.getOrCreateLocation(new LocationImpl(getLocation().getLat(), getLocation().getLng(), null, null));
                if (loc != null) {
                    locations.add(loc);
                }
            }
            for (Location location : locations) {
                addLink(study, taxonForNode, links, location);
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to find data file(s)", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create nodes", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 33 with Location

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

the class StudyImporterForBroseTest method importHeadAndTail.

@Test
public void importHeadAndTail() throws IOException, StudyImporterException {
    final String headAndTail = "Link ID\tLink reference \tBody size reference\tGeographic location\tGeneral habitat\tSpecific habitat\tLink methodology\tBody size methodology\tTaxonomy consumer\tLifestage consumer\tCommon name(s) consumer\tMetabolic category consumer\tType of feeding interaction\tMinimum length (m) consumer\tMean length (m) consumer\tMaximum length (m) consumer\tMinimum mass (g) consumer\tMean mass (g) consumer\tMaximum mass (g) consumer\tTaxonomy resource\tLifestage - resource\tCommon name(s) resource\tMetabolic category resource\tMinimum length (m) resource\tMean length (m) resource\tMaximum length (m) resource\tMinimum mass (g) resource\tMean mass (g) resource\tMaximum mass (g) resource\tConsumer/resource body mass ratio\tNotes\n" + "1\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tBacteria\theterotrophic bacteria\therbivorous\t-999\t-999\t-999\t-999\t0.00000001\t-999\t-999\tadults\tPhytoplankton\tphoto-autotroph\t-999\t-999\t-999\t-999\t0.0001\t-999\t0.0001\t-999\n" + "2\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tBenthic carnivores\tinvertebrate\tpredacious\t-999\t-999\t-999\t-999\t10\t-999\t-999\tadults\tBenthic filter feeders\tinvertebrate\t-999\t-999\t-999\t-999\t10\t-999\t1\t-999\n" + "3\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMicrozooplankton\tinvertebrate\therbivorous\t-999\t-999\t-999\t-999\t0.0001\t-999\t-999\tadults\tPhytoplankton\tphoto-autotroph\t-999\t-999\t-999\t-999\t0.0001\t-999\t1\t-999\n" + "4\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMicrozooplankton\tinvertebrate\tbacterivorous\t-999\t-999\t-999\t-999\t0.0001\t-999\t-999\tadults\tBacteria\theterotrophic bacteria\t-999\t-999\t-999\t-999\t0.00000001\t-999\t10000\t-999\n" + "5\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMicrozooplankton\tinvertebrate\tpredacious\t-999\t-999\t-999\t-999\t0.0001\t-999\t-999\tadults\tMicrozooplankton\tinvertebrate\t-999\t-999\t-999\t-999\t0.0001\t-999\t1\t-999\n" + "6\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMesozooplankton\tinvertebrate\therbivorous\t-999\t-999\t-999\t-999\t0.01\t-999\t-999\tadults\tPhytoplankton\tphoto-autotroph\t-999\t-999\t-999\t-999\t0.0001\t-999\t100\t-999\n" + "7\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMesozooplankton\tinvertebrate\tpredacious\t-999\t-999\t-999\t-999\t0.01\t-999\t-999\tadults\tMicrozooplankton\tinvertebrate\t-999\t-999\t-999\t-999\t0.0001\t-999\t100\t-999\n" + "8\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMacrozooplankton\tinvertebrate\therbivorous\t-999\t-999\t-999\t-999\t1\t-999\t-999\tadults\tPhytoplankton\tphoto-autotroph\t-999\t-999\t-999\t-999\t0.0001\t-999\t10000\t-999\n" + "9\tYodzis (1998)\tYodzis (1998)\tAfrica, Benguela ecosystem\tmarine\tpelagic food web\tpublished account\t\"published account; expert; regression\"\t-999\tadults\tMacrozooplankton\tinvertebrate\tpredacious\t-999\t-999\t-999\t-999\t1\t-999\t-999\tadults\tMesozooplankton\tinvertebrate\t-999\t-999\t-999\t-999\t0.01\t-999\t100\t-999\n" + "16857\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tPraon dorsale\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.002034483\t0.002197044\t0.002344828\t-999\t-999\t-999\tAcyrthosiphon pisum\tadult\taphid\tinvertebrate\t0.002448276\t0.00264532\t0.002793103\t-999\t-999\t-999\t0.614787036\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 7 pairs of individuals were measured\"\n" + "16858\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphidius urticae\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.002\t0.002665025\t0.003517241\t-999\t-999\t-999\tMacrosiphum funestum\tadult\taphid\tinvertebrate\t0.002482759\t0.003214286\t0.003965517\t-999\t-999\t-999\t0.61203447\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 14 pairs of individuals were measured\"\n" + "16859\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tPraon dorsale\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.001965517\t0.001965517\t0.001965517\t-999\t-999\t-999\tAmphorophora rubi\tadult\taphid\tinvertebrate\t0.002482759\t0.002482759\t0.002482759\t-999\t-999\t-999\t0.542226802\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 1 pair of individuals were measured\"\n" + "16860\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tPraon dorsale\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.001896552\t0.001896552\t0.001896552\t-999\t-999\t-999\tMegoura viciaei\tadult\taphid\tinvertebrate\t0.002862069\t0.002862069\t0.002862069\t-999\t-999\t-999\t0.340224547\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 1 pair of individuals were measured\"\n" + "16861\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus abdominalis\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.000793103\t0.000926724\t0.001206897\t-999\t-999\t-999\tSitobion fragariae / Sitobion avenae\tnymphs\taphid\tinvertebrate\t0.001310345\t0.001599138\t0.001896552\t-999\t-999\t-999\t0.239457874\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 16 pairs of individuals were measured\"\n" + "16862\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus abdominalis\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.000965517\t0.000965517\t0.000965517\t-999\t-999\t-999\tAmphorophora rubi\tadult\taphid\tinvertebrate\t0.001689655\t0.001689655\t0.001689655\t-999\t-999\t-999\t0.230802396\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 1 pair of individuals were measured\"\n" + "16863\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus abdominalis\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.000896552\t0.001132626\t0.001310345\t-999\t-999\t-999\tSitobion fragariae / Sitobion avenae\tadult\taphid\tinvertebrate\t0.001448276\t0.00201061\t0.002517241\t-999\t-999\t-999\t0.222324699\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 13 pairs of individuals were measured\"\n" + "16864\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus abdominalis\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.001068966\t0.001206897\t0.001344828\t-999\t-999\t-999\tAcyrthosiphon pisum\tnymphs\taphid\tinvertebrate\t0.002034483\t0.002206897\t0.00237931\t-999\t-999\t-999\t0.205715371\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 2 pairs of individuals were measured\"\n" + "16865\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus abdominalis\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.001103448\t0.00112069\t0.001137931\t-999\t-999\t-999\tMetopolophium albidum\tadult\taphid\tinvertebrate\t0.002034483\t0.002172414\t0.002310345\t-999\t-999\t-999\t0.176547741\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 2 pairs of individuals were measured\"\n" + "16866\tCohen et al. (2005)\tCohen et al. (2005)\t\"Country: United Kingdom; UTM: 51.24'N, 0.34'W; Silwood Park, Berkshire\"\tterrestrial\tabandoned field\trearing\t\"measurement; regression\"\tAphelinus varipes\tadult\tparasitoid wasp\tinvertebrate\tparasitoid\t0.000896552\t0.000896552\t0.000896552\t-999\t-999\t-999\tSitobion fragariae / Sitobion avenae\tnymphs\taphid\tinvertebrate\t0.001965517\t0.001965517\t0.001965517\t-999\t-999\t-999\t0.127890431\t\"newly emerged adult parsitoids were measured; resource length was measured without cauda; for data on individual body sizes and body sizes of hyperparasitoids and mummy parasitoids see Cohen et al. (2005); 1 pair of individuals were measured\"\n";
    TestParserFactory parserFactory = new TestParserFactory(new HashMap<String, String>() {

        {
            put(StudyImporterForBrose.RESOURCE_PATH, headAndTail);
            put(StudyImporterForBrose.REFERENCE_PATH, "short,full\nCohen et al. (2005),something long\nYodzis (1998),something longer");
        }
    });
    StudyImporter importer = new StudyImporterForBrose(parserFactory, nodeFactory);
    importStudy(importer);
    Taxon taxon = taxonIndex.findTaxonByName("Praon dorsale");
    Iterable<Relationship> relationships = ((NodeBacked) taxon).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    for (Relationship relationship : relationships) {
        Node predatorSpecimenNode = relationship.getStartNode();
        assertThat((String) predatorSpecimenNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
        assertThat((String) predatorSpecimenNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
    }
    assertThat(taxon, is(notNullValue()));
    assertThat(taxonIndex.findTaxonByName("Aphelinus abdominalis"), is(notNullValue()));
    Location location = nodeFactory.findLocation(new LocationImpl(51.24, -0.34, null, null));
    assertThat("missing location", location, is(notNullValue()));
    List<Environment> environments = location.getEnvironments();
    assertThat(environments.size(), is(1));
    assertThat(environments.get(0).getExternalId(), is("TEST:terrestrial abandoned field"));
    assertThat(environments.get(0).getName(), is("terrestrial abandoned field"));
}
Also used : Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Environment(org.eol.globi.domain.Environment) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 34 with Location

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

the class StudyImporterForBlewettTest method importLines.

@Test
public void importLines() throws StudyImporterException, NodeFactoryException {
    String predatorPreyMapping = "\"Collection #\",\"Sp#\",\"Standard Length\",\"ID\",\"Far duoraum\",\"Cal sapidus\",\"Unid fish\",\"Anchoa spp\",\"Mug gyrans\",\"Bai chrysoura\",\"Portunus spp\",\"Bivalves\",\"Portunidae\",\"Lag rhomboides\",\"Xanthidae\",\"Palaemonidae\",\"Eucinostomus spp\",\"Mugil spp\",\"Alpheidae\",\"Atherinidae\",\"Syn foetens\",\"Ort chrysoptera\",\"Snails\",\"Euc gula\",\"Cynoscion spp\",\"Cyp. Variegatus\",\"Fun majalis\",\"Poe latipinna\",\"Unid crab\",\"Har jaguana\",\"Arm mierii\",\"Fun grandis\",\"Mic gulosus\",\"Ari felis\",\"Clupeidae\",\"Fundulus spp\",\"Diapterus/Eugerres spp\",\"Isopods\",\"Cyn nebulosus\",\"Opi oglinum\",\"Flo carpio\",\"Luc parva\",\"Uca spp\",\"Majidae\",\"Mug cephalus\",\"Squ empusa\",\"Opi robinsi\",\"Ariidae\",\"Sci ocellatus\",\"Unid shrimp\",\"Uca thayeri\",\"Grapsidae\",\"Lei xanthurus\",\"Elo saurus\",\"Brevoortia spp\"\n" + "\"CHD01101502\",1,549,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",1,548,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",2,550,,3,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",1,580,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",2,556,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    String dateLocationString = "\"Collection #\",\"Longitude\",\"Latitude\",\"Time\",\"Date\",\"Temperature\",\"Salinity\"\n" + "\"CHD01101502\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHD01102504\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000151\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000152\",-82.103833,26.651833,12:40:00,1-Mar-00,24.8,30.3\n" + "\"CHM000153\",-82.087333,26.644833,13:40:00,1-Mar-00,25.1,30.1\n" + "\"CHM000154\",-82.083167,26.671167,14:40:00,1-Mar-00,26,30.4\n" + "\"CHM000175\",-82.197833,26.688167,10:00:00,8-Mar-00,22.2,35.05\n" + "\"CHM000176\",-82.191333,26.667333,11:00:00,8-Mar-00,22.7,35.25";
    final TestParserFactory preyPredatorFactory = new TestParserFactory(predatorPreyMapping);
    final TestParserFactory dateLocationFactory = new TestParserFactory(dateLocationString);
    ParserFactory testFactory = new ParserFactory() {

        @Override
        public LabeledCSVParser createParser(String studyResource, String characterEncoding) throws IOException {
            LabeledCSVParser parser = null;
            if (studyResource.contains("abundance")) {
                parser = preyPredatorFactory.createParser(studyResource, characterEncoding);
            } else {
                parser = dateLocationFactory.createParser(studyResource, characterEncoding);
            }
            return parser;
        }
    };
    StudyImporter importer = new StudyImporterTestFactory(testFactory, nodeFactory).instantiateImporter((Class) StudyImporterForBlewett.class);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    Iterable<Relationship> collectedRels = NodeUtil.getSpecimens(study);
    Relationship collectedRel = collectedRels.iterator().next();
    Date unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(collectedRel.getEndNode()));
    assertThat(unixEpochProperty, is(not(nullValue())));
    assertThat(dateToString(unixEpochProperty), is("2000-03-01T10:55:00.000-06:00"));
    Node predatorNode = collectedRel.getEndNode();
    assertThat((String) predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
    assertThat((String) predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
    assertThat((Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(549.0));
    Node predatorTaxonNode = predatorNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
    assertThat((String) predatorTaxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Centropomus undecimalis"));
    Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
    Node preyNode = ate.iterator().next().getEndNode();
    assertThat(preyNode, is(not(nullValue())));
    Node taxonNode = preyNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
    assertThat(taxonNode, is(not(nullValue())));
    assertThat((String) taxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Lag rhomboides"));
    Iterator<Relationship> i = collectedRels.iterator();
    i.next();
    collectedRel = i.next();
    predatorNode = collectedRel.getEndNode();
    assertThat((Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(548.0));
    ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
    assertThat(ate.iterator().hasNext(), is(false));
    Location location = nodeFactory.findLocation(new LocationImpl(26.651833, -82.103833, 0.0, null));
    assertThat(location, is(not(nullValue())));
    Iterable<Relationship> specimenCaughtHere = NodeUtil.getSpecimenCaughtHere(location);
    Iterator<Relationship> iterator = specimenCaughtHere.iterator();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(false));
}
Also used : Study(org.eol.globi.domain.Study) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 35 with Location

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

the class StudyImporterForPlanque method addInteractionForPredator.

private void addInteractionForPredator(LabeledCSVParser parser, Study localStudy, String predatorName) throws NodeFactoryException, StudyImporterException {
    Specimen predator = nodeFactory.createSpecimen(localStudy, new TaxonImpl(normalizeName(predatorName), null));
    // from http://www.geonames.org/630674/barents-sea.html
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(74.0, 36.0, null, null));
    predator.caughtIn(location);
    String preyName = parser.getValueByLabel("PREY");
    if (StringUtils.isBlank(preyName)) {
        getLogger().warn(localStudy, "found empty prey name on line [" + parser.lastLineNumber() + "]");
    } else {
        Specimen prey = nodeFactory.createSpecimen(localStudy, new TaxonImpl(normalizeName(preyName), null));
        prey.caughtIn(location);
        predator.ate(prey);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Aggregations

Location (org.eol.globi.domain.Location)44 LocationImpl (org.eol.globi.domain.LocationImpl)32 Specimen (org.eol.globi.domain.Specimen)31 Study (org.eol.globi.domain.Study)24 StudyImpl (org.eol.globi.domain.StudyImpl)16 TaxonImpl (org.eol.globi.domain.TaxonImpl)16 Date (java.util.Date)14 IOException (java.io.IOException)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 HashMap (java.util.HashMap)8 LatLng (org.eol.globi.geo.LatLng)8 TermImpl (org.eol.globi.domain.TermImpl)6 Test (org.junit.Test)6 Relationship (org.neo4j.graphdb.Relationship)6 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 ArrayList (java.util.ArrayList)4 Taxon (org.eol.globi.domain.Taxon)4 Node (org.neo4j.graphdb.Node)3 List (java.util.List)2 Map (java.util.Map)2