Skip to content

Commit

Permalink
eclipse-rdf4jGH-5058: additional parser code (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
barthanssens committed Jul 10, 2024
1 parent 67252f9 commit a48f845
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,22 @@ private CellParser getCellParser(Model metadata, Resource column) {

CellParser parser = CellParserFactory.create(datatype);

Optional<Value> format = getFormat(metadata, column);
if (format.isPresent()) {
parser.setFormat(format.get().stringValue());
}
Optional<Value> name = Models.getProperty(metadata, column, CSVW.NAME);
if (!name.isPresent()) {
throw new RDFParseException("Metadata file does not contain name for column " + column);
}
parser.setName(name.get().stringValue());

Optional<Value> defaultVal = Models.getProperty(metadata, column, CSVW.DEFAULT);
if (defaultVal.isPresent()) {
parser.setDefaultValue(defaultVal.get().stringValue());
}

getFormat(metadata, column).ifPresent(v -> parser.setFormat(v.stringValue()));

Models.getProperty(metadata, column, CSVW.NAME)
.ifPresentOrElse(v -> parser.setName(v.stringValue()),
() -> new RDFParseException("Metadata file does not contain name for column " + column));

Models.getProperty(metadata, column, CSVW.DEFAULT).ifPresent(v -> parser.setDefaultValue(v.stringValue()));
Models.getProperty(metadata, column, CSVW.REQUIRED)
.ifPresent(v -> parser.setIsRequired(Boolean.parseBoolean(v.stringValue())));
Models.getProperty(metadata, column, CSVW.VALUE_URL).ifPresent(v -> parser.setValueURL(v.stringValue()));

// use a property from a vocabulary as predicate, or create a property relative to the namespace of the CSV
Optional<Value> propertyURL = Models.getProperty(metadata, column, CSVW.PROPERTY_URL);
String s = propertyURL.isPresent() ? propertyURL.get().stringValue() : "_local:" + parser.getName();
parser.setPropertyURL(metadata.getNamespaces(), s);

Optional<Value> valueURL = Models.getProperty(metadata, column, CSVW.VALUE_URL);
if (valueURL.isPresent()) {
parser.setValueURL(valueURL.get().stringValue());
}
return parser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
package org.eclipse.rdf4j.rio.csvw.parsers;

import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Set;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.util.Literals;
import org.eclipse.rdf4j.model.util.Values;
import org.eclipse.rdf4j.rio.RDFParseException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ public class CellParserFactory {
public static CellParser create(IRI datatype) {
CellParser p;

if (datatype.equals(XSD.DATE.getIri())) {
p = new CellParserDate();
} else if (datatype.equals(XSD.BOOLEAN.getIri())) {
p = new CellParserBoolean();
} else {
XSD xsdType = XSD.valueOf(datatype.toString());
if (xsdType == null) {
p = new CellParser();
} else {
switch(xsdType) {
case DATE:
case DATETIME:
p = new CellParserDate();
break;
case BOOLEAN:
p = new CellParserBoolean();
break;
default:
p = new CellParser();
}
}
p.setDataType(datatype);
return p;
Expand Down

0 comments on commit a48f845

Please sign in to comment.