Search in sources :

Example 6 with LabeledCSVParser

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

the class StudyImporterForWrast method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String citation = "Wrast JL. Spatiotemporal And Habitat-mediated Food Web Dynamics in Lavaca Bay, Texas. 2008. Master Thesis.";
    StudyImpl study1 = new StudyImpl("Wrast 2008", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, citation);
    study1.setExternalId("http://www.fisheries.tamucc.edu/people_files/FINAL%20WRAST%20THESIS.pdf");
    Study study = nodeFactory.getOrCreateStudy(study1);
    try {
        LabeledCSVParser csvParser = parserFactory.createParser(LAVACA_BAY_DATA_SOURCE, CharsetConstant.UTF8);
        LengthParser parser = new LengthParserImpl(COLUMN_MAPPER.get(LENGTH_IN_MM));
        getPredatorSpecimenMap().clear();
        while (csvParser.getLine() != null) {
            addNextRecordToStudy(csvParser, study, COLUMN_MAPPER, parser);
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to create study [" + LAVACA_BAY_DATA_SOURCE + "]", e);
    } finally {
        getPredatorSpecimenMap().clear();
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 7 with LabeledCSVParser

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

the class StudyImporterForINaturalistTest method loadIgnoredInteractions.

@Test
public void loadIgnoredInteractions() throws IOException {
    LabeledCSVParser labeledCSVParser = importer.parserFactory.createParser(StudyImporterForINaturalist.TYPE_IGNORED_URI_DEFAULT, CharsetConstant.UTF8);
    List<Integer> typeMap1 = StudyImporterForINaturalist.buildTypesIgnored(labeledCSVParser);
    assertThat(typeMap1.contains(13), is(false));
    assertThat(typeMap1.contains(1378), is(true));
}
Also used : LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 8 with LabeledCSVParser

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

the class StudyImporterForINaturalistTest method loadInteractionMap.

@Test
public void loadInteractionMap() throws IOException {
    String resourceName = StudyImporterForINaturalist.TYPE_MAP_URI_DEFAULT;
    LabeledCSVParser labeledCSVParser = importer.parserFactory.createParser(resourceName, CharsetConstant.UTF8);
    Map<Integer, InteractType> typeMap = StudyImporterForINaturalist.buildTypeMap(resourceName, labeledCSVParser);
    assertThat(typeMap.get(13), is(InteractType.ATE));
    assertThat(typeMap.get(1685), is(InteractType.ATE));
    assertThat(typeMap.get(839), is(InteractType.PREYS_UPON));
}
Also used : InteractType(org.eol.globi.domain.InteractType) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 9 with LabeledCSVParser

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

the class SchemaControllerTest method interactionTypesCSV.

@Test
public void interactionTypesCSV() throws IOException {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    when(request.getParameter("type")).thenReturn("csv");
    String interactionTypes = new SchemaController().getInteractionTypes(request);
    LabeledCSVParser parser = CSVTSVUtil.createLabeledCSVParser(IOUtils.toInputStream(interactionTypes));
    assertThat(parser.getLabels(), is(new String[] { "interaction", "source", "target", "termIRI" }));
    while (parser.getLine() != null) {
        assertThat(parser.getValueByLabel("interaction"), is(notNullValue()));
        assertThat(parser.getValueByLabel("source"), is(notNullValue()));
        assertThat(parser.getValueByLabel("target"), is(notNullValue()));
        assertThat(parser.getValueByLabel("termIRI"), is(notNullValue()));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) Test(org.junit.Test)

Example 10 with LabeledCSVParser

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

the class TaxonMapParserTest method parse.

public static void parse(BufferedReader reader, TaxonMapListener listener) throws IOException {
    LabeledCSVParser labeledCSVParser = CSVTSVUtil.createLabeledCSVParser(reader);
    listener.start();
    while (labeledCSVParser.getLine() != null) {
        Taxon providedTaxon = TaxonMapParser.parseProvidedTaxon(labeledCSVParser);
        Taxon resolvedTaxon = TaxonMapParser.parseResolvedTaxon(labeledCSVParser);
        listener.addMapping(providedTaxon, resolvedTaxon);
    }
    listener.finish();
}
Also used : Taxon(org.eol.globi.domain.Taxon) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser)

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