Search in sources :

Example 1 with CSVParse

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

the class CSVTSVUtilTest method readQuotesAgain.

@Test
public void readQuotesAgain() throws IOException {
    CSVParse csvParser = CSVTSVUtil.createCSVParse(IOUtils.toInputStream("\"hello \"\"world\"\"\""));
    assertThat(csvParser.nextValue(), is("hello \"world\""));
}
Also used : CSVParse(com.Ostermiller.util.CSVParse) Test(org.junit.Test)

Example 2 with CSVParse

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

the class TermLookupServiceImpl method buildMapping.

private void buildMapping(List<URI> uriList) throws TermLookupServiceException {
    mapping = new HashMap<>();
    for (URI uri : uriList) {
        try {
            String response = contentToString(uri);
            CSVParse parser = CSVTSVUtil.createCSVParse(new StringReader(response));
            parser.changeDelimiter(getDelimiter());
            if (hasHeader()) {
                parser = CSVTSVUtil.createLabeledCSVParser(parser);
            }
            String[] line;
            while ((line = parser.getLine()) != null) {
                if (line.length < 4) {
                    LOG.info("line: [" + parser.getLastLineNumber() + "] in [" + uriList + "] contains less than 4 columns");
                } else {
                    String sourceName = line[1];
                    String targetId = line[2];
                    String targetName = line[3];
                    if (StringUtils.isNotBlank(sourceName) && StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(targetName)) {
                        List<Term> terms = mapping.computeIfAbsent(sourceName, k -> new ArrayList<>());
                        terms.add(new TermImpl(targetId, targetName));
                    }
                }
            }
        } catch (IOException e) {
            throw new TermLookupServiceException("failed to retrieve mapping from [" + uriList + "]", e);
        }
    }
}
Also used : TermLookupServiceException(org.eol.globi.service.TermLookupServiceException) CSVParse(com.Ostermiller.util.CSVParse) StringReader(java.io.StringReader) Term(org.eol.globi.domain.Term) IOException(java.io.IOException) URI(java.net.URI) TermImpl(org.eol.globi.domain.TermImpl)

Example 3 with CSVParse

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

the class StudyImporterForMetaTable method importTable.

public static void importTable(InteractionListener interactionListener, TableParserFactory tableFactory, JsonNode tableConfig, Dataset dataset, ImportLogger importLogger) throws IOException, StudyImporterException {
    if (tableConfig.has("tableSchema")) {
        List<Column> columns = columnsForSchema(tableConfig, tableConfig.get("tableSchema"), dataset);
        final CSVParse csvParse = tableFactory.createParser(tableConfig, dataset);
        importAll(interactionListener, columns, csvParse, tableConfig, importLogger);
    }
}
Also used : CSVParse(com.Ostermiller.util.CSVParse)

Aggregations

CSVParse (com.Ostermiller.util.CSVParse)3 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 Term (org.eol.globi.domain.Term)1 TermImpl (org.eol.globi.domain.TermImpl)1 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)1 Test (org.junit.Test)1