Search in sources :

Example 36 with LabeledCSVParser

use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.

the class LengthRangeParserImplTest method parse.

@Test
public void parse() throws IOException, StudyImporterException {
    LengthRangeParserImpl parser = new LengthRangeParserImpl("johnny");
    LabeledCSVParser csvParser = initParser();
    assertEquals((146d + 123d) / 2d, parser.parseLengthInMm(csvParser));
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 37 with LabeledCSVParser

use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.

the class LengthRangeParserImplTest method initParser.

private LabeledCSVParser initParser() throws IOException {
    LabeledCSVParser csvParser = new TestParserFactory("\"johnny\"\n123-146\n324-345\n").createParser("aStudy", "UTF-8");
    csvParser.getLine();
    return csvParser;
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser)

Example 38 with LabeledCSVParser

use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.

the class LengthRangeParserImplTest method parseNoLengthUnavailable.

@Test
public void parseNoLengthUnavailable() throws IOException, StudyImporterException {
    LengthRangeParserImpl parser = new LengthRangeParserImpl("bla");
    LabeledCSVParser csvParser = initParser();
    assertNull(parser.parseLengthInMm(csvParser));
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 39 with LabeledCSVParser

use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.

the class LengthParserImplTest method initParser.

private LabeledCSVParser initParser() throws IOException {
    LabeledCSVParser csvParser = new TestParserFactory("\"johnny\"\n123\n324\n").createParser("aStudy", "UTF-8");
    csvParser.getLine();
    return csvParser;
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser)

Example 40 with LabeledCSVParser

use of com.Ostermiller.util.LabeledCSVParser in project eol-globi-data by jhpoelen.

the class StudyImporterForRoopnarineTest method importLine.

@Test
public void importLine() throws StudyImporterException, NodeFactoryException {
    // note that this test data is a modified version of the actual data - please don't use this data for actual analysis purposes
    final String trophicGuildsToSpeciesLookup = "\"Guild Number\",\"Taxa\",\"Fish Body Length\",\"Cayman Islands\",\"Cuba\",\"Jamaica\"\n" + "1,\"something something\",,,,\n" + "2,\"Skeletonema tropicum        \",,,,\n" + "3,\"Something else        \",,,,\n" + "11,\" Epinephelus striatus          \",122,\"x \",\"x\",\"x\"\n" + "12,\" Negaprion brevirostris        \",240,\"x \",\" \",\" \"\n" + "13,\" Carcharhinus perezi           \",300,\"x \",\"x\",\"x\"\n" + "14,\" Rhizoprionodon porosus        \",75,\"x \",\"x\",\" \"\n" + "14,\" Sphyrna tiburo                \",80,\"x \",\" \",\" \"\n" + "14,\" Galeocerdo cuvieri            \",500,\"  \",,";
    final String trophicInteractions = "\"Guild Number\",\"Guild Description\",\"Foraging Habitat\",\"Number of Prey\",\"Prey\"\n" + "1,\"Planktonic bacteria   \",\".\",0,\".\"\n" + "2,\"Phytoplankton         \",\".\",0,\".\"\n" + "3,\"Nanno-zooplankton     \",\".\",30,\"1, 2\"\n" + "4,\"Filamentous macroalgae\",\".\",0,\".\"\n" + "5,\"Sheet macroalgae      \",\".\",0,\".\"\n" + "6,\"Coarsely branched macroalgae                 \",\".\",0,\".\"\n" + "7,\"Jointed calcareous macroalgae                \",\".\",0,\".\"\n" + "8,\"Thick leathery macroalgae                    \",\".\",0,\".\"\n" + "9,\"Crustose coralline algae                     \",\".\",0,\".\"\n" + "10,\"Seagrasses            \",\".\",0,\".\"\n" + "11,\"Epibenthic sponges    \",\".\",30,\"1,  2\"\n" + "12,\"Endolithic sponges    \",\".\",30,\"1,   2\"\n" + "13,\"Ahermatypic benthic corals\",\".\",35,\"1\"\n" + "14,\"Hermatypic corals\",\".\",36,\"2\"";
    StudyImporterForRoopnarine importer = new StudyImporterForRoopnarine(new ParserFactory() {

        @Override
        public LabeledCSVParser createParser(String studyResource, String characterEncoding) throws IOException {
            ParserFactory factory;
            if (studyResource.contains("4.csv")) {
                factory = new TestParserFactory(trophicGuildsToSpeciesLookup);
            } else {
                factory = new TestParserFactory(trophicInteractions);
            }
            return factory.createParser("", characterEncoding);
        }
    }, nodeFactory);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    assertNotNull(taxonIndex.findTaxonByName("Negaprion brevirostris"));
    assertNotNull(taxonIndex.findTaxonByName("Carcharhinus perezi"));
    assertNotNull(taxonIndex.findTaxonByName("Galeocerdo cuvieri"));
    Iterable<Relationship> collectedRels = NodeUtil.getSpecimens(study);
    int totalRels = validateSpecimen(collectedRels);
    assertThat(totalRels, Is.is(51));
}
Also used : Study(org.eol.globi.domain.Study) Relationship(org.neo4j.graphdb.Relationship) IOException(java.io.IOException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Aggregations

LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)82 IOException (java.io.IOException)40 Test (org.junit.Test)31 Study (org.eol.globi.domain.Study)24 StudyImpl (org.eol.globi.domain.StudyImpl)17 Specimen (org.eol.globi.domain.Specimen)15 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 Location (org.eol.globi.domain.Location)12 TaxonImpl (org.eol.globi.domain.TaxonImpl)12 CSVParser (com.Ostermiller.util.CSVParser)10 StringReader (java.io.StringReader)8 LocationImpl (org.eol.globi.domain.LocationImpl)8 Taxon (org.eol.globi.domain.Taxon)8 InteractType (org.eol.globi.domain.InteractType)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 Date (java.util.Date)6 List (java.util.List)6