Search in sources :

Example 11 with TaxonImpl

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

the class ExportTaxonMapTest method exportOnePredatorTwoPrey.

@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
    final PropertyEnricher taxonEnricher = new PropertyEnricher() {

        @Override
        public Map<String, String> enrich(Map<String, String> properties) {
            Taxon taxon = new TaxonImpl();
            TaxonUtil.mapToTaxon(properties, taxon);
            if ("Homo sapiens".equals(taxon.getName())) {
                taxon.setExternalId("homoSapiensId");
                taxon.setPath("one two three");
            } else if ("Canis lupus".equals(taxon.getName())) {
                taxon.setExternalId("canisLupusId");
                taxon.setPath("four\tfive six");
            }
            return TaxonUtil.taxonToMap(taxon);
        }

        @Override
        public void shutdown() {
        }
    };
    taxonIndex = ExportTestUtil.taxonIndexWithEnricher(taxonEnricher, getGraphDb());
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("title", "source", null, "citation"));
    Taxon taxon = new TaxonImpl("Homo sapiens");
    taxon.setExternalId("homoSapiensId");
    taxon.setPath("one two three");
    taxon.setExternalUrl("http://some/thing");
    taxon.setThumbnailUrl("http://thing/some");
    nodeFactory.createSpecimen(study, taxon);
    Taxon human = taxonIndex.getOrCreateTaxon(taxon);
    TaxonImpl dog = new TaxonImpl("Canis lupus");
    dog.setExternalId("canisLupusId");
    dog.setPath("four\tfive six");
    nodeFactory.createSpecimen(study, dog);
    final TaxonImpl altTaxonWithPath = new TaxonImpl("Alternate Homo sapiens", "alt:123");
    altTaxonWithPath.setPath("some path here");
    NodeUtil.connectTaxa(altTaxonWithPath, (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
    NodeUtil.connectTaxa(new TaxonImpl("Alternate Homo sapiens no path", "alt:123"), (TaxonNode) human, getGraphDb(), RelTypes.SAME_AS);
    NodeUtil.connectTaxa(new TaxonImpl("Similar Homo sapiens", "alt:456"), (TaxonNode) human, getGraphDb(), RelTypes.SIMILAR_TO);
    resolveNames();
    StringWriter writer = new StringWriter();
    new ExportTaxonMap().exportStudy(study, writer, true);
    assertThat(writer.toString(), is("providedTaxonId\tprovidedTaxonName\tresolvedTaxonId\tresolvedTaxonName" + "\nhomoSapiensId\tHomo sapiens\thomoSapiensId\tHomo sapiens" + "\nhomoSapiensId\tHomo sapiens\talt:123\tAlternate Homo sapiens" + "\ncanisLupusId\tCanis lupus\tcanisLupusId\tCanis lupus"));
}
Also used : Study(org.eol.globi.domain.Study) StringWriter(java.io.StringWriter) PropertyEnricher(org.eol.globi.service.PropertyEnricher) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Map(java.util.Map) Test(org.junit.Test)

Example 12 with TaxonImpl

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

the class ExportTestUtil method createTestData.

public static Study createTestData(Double length, NodeFactory factory) throws NodeFactoryException, ParseException {
    Study myStudy = factory.createStudy(new StudyImpl("myStudy", null, null, null));
    Specimen specimen1 = factory.createSpecimen(myStudy, new TaxonImpl("Homo sapiens", "EOL:45634"));
    specimen1.setStomachVolumeInMilliLiter(666.0);
    specimen1.setLifeStage(new TermImpl("GLOBI:JUVENILE", "JUVENILE"));
    specimen1.setPhysiologicalState(new TermImpl("GLOBI:DIGESTATE", "DIGESTATE"));
    specimen1.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
    factory.setUnixEpochProperty(specimen1, ExportTestUtil.utcTestDate());
    final Specimen specimen2 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
    specimen2.setVolumeInMilliLiter(124.0);
    specimen1.ate(specimen2);
    final Specimen specimen3 = factory.createSpecimen(myStudy, new TaxonImpl("Canis lupus", "EOL:123"));
    specimen3.setVolumeInMilliLiter(18.0);
    specimen1.ate(specimen3);
    if (null != length) {
        specimen1.setLengthInMm(length);
    }
    Location location = factory.getOrCreateLocation(new LocationImpl(88.0, -120.0, -60.0, null));
    specimen1.caughtIn(location);
    return myStudy;
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Example 13 with TaxonImpl

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

the class ExporterAssociationAggregatesTest method exportNoMatchTaxa.

@Test
public void exportNoMatchTaxa() throws IOException, NodeFactoryException, ParseException {
    String[] studyTitles = { "myStudy1", "myStudy2" };
    for (String studyTitle : studyTitles) {
        Study myStudy = nodeFactory.getOrCreateStudy(new StudyImpl(studyTitle, "data source description", null, ExternalIdUtil.toCitation("contributor", "description", "pubYear")));
        Specimen specimen = nodeFactory.createSpecimen(myStudy, new TaxonImpl(PropertyAndValueDictionary.NO_MATCH, null));
        specimen.ate(nodeFactory.createSpecimen(myStudy, new TaxonImpl(PropertyAndValueDictionary.NO_MATCH, null)));
    }
    resolveNames();
    ExporterAssociationAggregates exporter = new ExporterAssociationAggregates();
    StringWriter row = new StringWriter();
    for (String studyTitle : studyTitles) {
        Study myStudy1 = nodeFactory.findStudy(studyTitle);
        exporter.exportStudy(myStudy1, row, false);
    }
    assertThat(row.getBuffer().toString(), equalTo(""));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) StringWriter(java.io.StringWriter) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 14 with TaxonImpl

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

the class ExporterAssociationAggregatesTest method createTestData.

private void createTestData(Double length, String studyTitle) throws NodeFactoryException, ParseException {
    Study myStudy = nodeFactory.getOrCreateStudy(new StudyImpl(studyTitle, "data source description", null, ExternalIdUtil.toCitation("contributor", "description", "pubYear")));
    Specimen specimen = nodeFactory.createSpecimen(myStudy, setPathAndId(new TaxonImpl("Homo sapiens", null)));
    specimen.setStomachVolumeInMilliLiter(666.0);
    specimen.setLifeStage(new TermImpl("GlOBI:JUVENILE", "JUVENILE"));
    specimen.setPhysiologicalState(new TermImpl("GlOBI:DIGESTATE", "DIGESTATE"));
    specimen.setBodyPart(new TermImpl("GLOBI:BONE", "BONE"));
    nodeFactory.setUnixEpochProperty(specimen, new Date(ExportTestUtil.utcTestTime()));
    TaxonImpl taxon = new TaxonImpl("Canis lupus", null);
    Specimen otherSpecimen = nodeFactory.createSpecimen(myStudy, setPathAndId(taxon));
    otherSpecimen.setVolumeInMilliLiter(124.0);
    specimen.ate(otherSpecimen);
    specimen.ate(otherSpecimen);
    if (null != length) {
        specimen.setLengthInMm(length);
    }
    Location location = nodeFactory.getOrCreateLocation(new LocationImpl(44.0, 120.0, -60.0, null));
    specimen.caughtIn(location);
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LocationImpl(org.eol.globi.domain.LocationImpl) Date(java.util.Date) TermImpl(org.eol.globi.domain.TermImpl) Location(org.eol.globi.domain.Location)

Example 15 with TaxonImpl

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

the class ExportUnmatchedTaxonNamesTest method exportOnePredatorTwoPrey.

@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
    taxonIndex = ExportTestUtil.taxonIndexWithEnricher(null, getGraphDb());
    String title = "my study\"";
    String citation = "citation my study";
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl(title, "my first source", null, citation));
    taxonIndex.getOrCreateTaxon(new TaxonImpl("Homo sapiens", null));
    Specimen predatorSpecimen = nodeFactory.createSpecimen(study, human());
    taxonIndex.getOrCreateTaxon(new TaxonImpl("Canis lupus", null));
    Specimen preySpecimen6 = nodeFactory.createSpecimen(study, dog());
    predatorSpecimen.interactsWith(preySpecimen6, InteractType.ATE);
    Specimen preySpecimen5 = nodeFactory.createSpecimen(study, dog());
    predatorSpecimen.interactsWith(preySpecimen5, InteractType.ATE);
    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Caniz", null));
    predatorSpecimen.ate(preySpecimen);
    Specimen predatorSpecimen23 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens2", null));
    Specimen preySpecimen4 = nodeFactory.createSpecimen(study, dog());
    predatorSpecimen23.interactsWith(preySpecimen4, InteractType.ATE);
    Specimen predatorSpecimen22 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens2", null));
    Specimen preySpecimen3 = nodeFactory.createSpecimen(study, dog());
    predatorSpecimen22.interactsWith(preySpecimen3, InteractType.ATE);
    Study study2 = nodeFactory.getOrCreateStudy(new StudyImpl("my study2", "my source2", null, "citation study2"));
    Specimen predatorSpecimen21 = nodeFactory.createSpecimen(study2, new TaxonImpl("Homo sapiens2", null));
    Specimen preySpecimen2 = nodeFactory.createSpecimen(study2, dog());
    predatorSpecimen21.interactsWith(preySpecimen2, InteractType.ATE);
    Specimen predatorSpecimen2 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens3", PropertyAndValueDictionary.NO_MATCH));
    Specimen preySpecimen1 = nodeFactory.createSpecimen(study, dog());
    predatorSpecimen2.interactsWith(preySpecimen1, InteractType.ATE);
    resolveNames();
    StringWriter writer = new StringWriter();
    new ExportUnmatchedTaxonNames().exportStudy(study, writer, true);
    assertThat(writer.toString(), is("unmatched taxon name\tunmatched taxon id\tname status\tsimilar to taxon name\tsimilar to taxon path\tsimilar to taxon id\tstudy\tsource" + "\nCaniz\t\t\t\t\t\tcitation my study\tmy first source" + "\nHomo sapiens2\t\t\t\t\t\tcitation my study\tmy first source" + "\nHomo sapiens3\tno:match\t\t\t\t\tcitation my study\tmy first source"));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) StringWriter(java.io.StringWriter) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Aggregations

TaxonImpl (org.eol.globi.domain.TaxonImpl)123 Specimen (org.eol.globi.domain.Specimen)59 Test (org.junit.Test)54 Taxon (org.eol.globi.domain.Taxon)42 StudyImpl (org.eol.globi.domain.StudyImpl)34 Study (org.eol.globi.domain.Study)32 Location (org.eol.globi.domain.Location)16 LocationImpl (org.eol.globi.domain.LocationImpl)15 TaxonNode (org.eol.globi.domain.TaxonNode)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 IOException (java.io.IOException)11 TermImpl (org.eol.globi.domain.TermImpl)11 StringWriter (java.io.StringWriter)9 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)7 Map (java.util.Map)5 Node (org.neo4j.graphdb.Node)5 File (java.io.File)4