use of org.apache.jena.atlas.csv.CSVParser in project jena by apache.
the class AbstractPropertyTableBuilderTest method testFillPropertyTable.
@Test
public void testFillPropertyTable() {
CSVParser iterator = csv("a,b\nc,d\ne,f");
PropertyTableBuilder.fillPropertyTable(table, iterator, csvFilePath);
Assert.assertEquals(3, table.getColumns().size());
containsColumn(PropertyTableBuilder.CSV_ROW_NODE);
containsColumn("a");
containsColumn("b");
Assert.assertEquals(2, table.getAllRows().size());
containsValue(0, "a", "c");
containsValue(0, "b", "d");
containsValue(1, "a", "e");
containsValue(1, "b", "f");
}
use of org.apache.jena.atlas.csv.CSVParser in project jena by apache.
the class AbstractPropertyTableBuilderTest method testIrregularTable3.
@Test
public void testIrregularTable3() {
CSVParser iterator = csv("a,b\n,d\ne,f");
PropertyTableBuilder.fillPropertyTable(table, iterator, csvFilePath);
Assert.assertEquals(3, table.getColumns().size());
containsColumn(PropertyTableBuilder.CSV_ROW_NODE);
containsColumn("a");
containsColumn("b");
Assert.assertEquals(2, table.getAllRows().size());
nullValue(0, "a");
containsValue(0, "b", "d");
containsValue(1, "a", "e");
containsValue(1, "b", "f");
}
use of org.apache.jena.atlas.csv.CSVParser in project jena by apache.
the class AbstractPropertyTableBuilderTest method testIrregularTable1.
@Test
public void testIrregularTable1() {
CSVParser iterator = csv("a,b\nc\ne,f");
PropertyTableBuilder.fillPropertyTable(table, iterator, csvFilePath);
Assert.assertEquals(3, table.getColumns().size());
containsColumn(PropertyTableBuilder.CSV_ROW_NODE);
containsColumn("a");
containsColumn("b");
Assert.assertEquals(2, table.getAllRows().size());
containsValue(0, "a", "c");
nullValue(0, "b");
containsValue(1, "a", "e");
containsValue(1, "b", "f");
}
use of org.apache.jena.atlas.csv.CSVParser in project jena by apache.
the class ReaderRIOTCSV method parse.
public void parse() {
sink.start();
CSVParser parser = (input != null) ? CSVParser.create(input) : CSVParser.create(reader);
ArrayList<Node> predicates = new ArrayList<>();
int rowNum = 0;
for (List<String> row : parser) {
if (rowNum == 0) {
for (String column : row) {
String uri = IRIResolver.resolveString(filename) + "#" + toSafeLocalname(column);
Node predicate = this.maker.createURI(uri, rowNum, 0);
predicates.add(predicate);
}
} else {
//Node subject = this.profile.createBlankNode(null, -1, -1);
Node subject = calculateSubject(rowNum, filename);
Node predicateRow = this.maker.createURI(CSV_ROW, -1, -1);
Node objectRow = this.maker.createTypedLiteral((rowNum + ""), XSDDatatype.XSDinteger, rowNum, 0);
sink.triple(this.maker.createTriple(subject, predicateRow, objectRow, rowNum, 0));
for (int col = 0; col < row.size() && col < predicates.size(); col++) {
Node predicate = predicates.get(col);
String columnValue = row.get(col).trim();
if ("".equals(columnValue)) {
continue;
}
Node o;
try {
// Try for a double.
Double.parseDouble(columnValue);
o = NodeFactory.createLiteral(columnValue, XSDDatatype.XSDdouble);
} catch (Exception e) {
o = NodeFactory.createLiteral(columnValue);
}
sink.triple(this.maker.createTriple(subject, predicate, o, rowNum, col));
}
}
rowNum++;
}
sink.finish();
}
use of org.apache.jena.atlas.csv.CSVParser in project jena by apache.
the class ReaderRIOTCSV method parse.
public void parse() {
sink.start();
CSVParser parser = (input != null) ? CSVParser.create(input) : CSVParser.create(reader);
ArrayList<Node> predicates = new ArrayList<>();
int rowNum = 0;
for (List<String> row : parser) {
if (rowNum == 0) {
for (String column : row) {
String uri = IRIResolver.resolveString(filename) + "#" + toSafeLocalname(column);
Node predicate = this.profile.createURI(uri, rowNum, 0);
predicates.add(predicate);
}
} else {
//Node subject = this.profile.createBlankNode(null, -1, -1);
Node subject = calculateSubject(rowNum, filename);
Node predicateRow = this.profile.createURI(CSV_ROW, -1, -1);
Node objectRow = this.profile.createTypedLiteral((rowNum + ""), XSDDatatype.XSDinteger, rowNum, 0);
sink.triple(this.profile.createTriple(subject, predicateRow, objectRow, rowNum, 0));
for (int col = 0; col < row.size() && col < predicates.size(); col++) {
Node predicate = predicates.get(col);
String columnValue = row.get(col).trim();
if ("".equals(columnValue)) {
continue;
}
Node o;
try {
// Try for a double.
Double.parseDouble(columnValue);
o = NodeFactory.createLiteral(columnValue, XSDDatatype.XSDdouble);
} catch (Exception e) {
o = NodeFactory.createLiteral(columnValue);
}
sink.triple(this.profile.createTriple(subject, predicate, o, rowNum, col));
}
}
rowNum++;
}
sink.finish();
}
Aggregations