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 9, 2024
1 parent 26b6826 commit 98f0f99
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.csvw.parsers.CellParserFactory;
import org.eclipse.rdf4j.rio.csvw.parsers.CellParser;
import org.eclipse.rdf4j.rio.csvw.parsers.CellParserFactory;
import org.eclipse.rdf4j.rio.helpers.AbstractRDFParser;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -214,6 +214,10 @@ 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);
Expand Down Expand Up @@ -262,6 +266,25 @@ private IRI getDatatypeIRI(Model metadata, Resource column) {
return XSD.valueOf(datatype.stringValue().toUpperCase()).getIri();
}

/**
* Get IRI of base or derived datatype
*
* @param metadata
* @param column
* @return
*/
private Optional<Value> getFormat(Model metadata, Resource column) {
Optional<Value> val = Models.getProperty(metadata, column, CSVW.DATATYPE);
if (val.isPresent()) {
Value datatype = val.get();
// derived datatype
if (datatype.isBNode()) {
val = Models.getProperty(metadata, (Resource) datatype, CSVW.FORMAT);
}
}
return val;
}

/**
* Get "about" URL template, to be used to create the subject of the triples
*
Expand Down

0 comments on commit 98f0f99

Please sign in to comment.