From 98f0f992ed2ae63048c26e8d444600fd85ef0bbf Mon Sep 17 00:00:00 2001 From: Bart Hanssens Date: Tue, 9 Jul 2024 22:18:56 +0100 Subject: [PATCH] GH-5058: additional parser code (WIP) --- .../eclipse/rdf4j/rio/csvw/CSVWParser.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/rio/csvw/src/main/java/org/eclipse/rdf4j/rio/csvw/CSVWParser.java b/core/rio/csvw/src/main/java/org/eclipse/rdf4j/rio/csvw/CSVWParser.java index decd55d37a..b6b3870e97 100644 --- a/core/rio/csvw/src/main/java/org/eclipse/rdf4j/rio/csvw/CSVWParser.java +++ b/core/rio/csvw/src/main/java/org/eclipse/rdf4j/rio/csvw/CSVWParser.java @@ -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; @@ -214,6 +214,10 @@ private CellParser getCellParser(Model metadata, Resource column) { CellParser parser = CellParserFactory.create(datatype); + Optional format = getFormat(metadata, column); + if (format.isPresent()) { + parser.setFormat(format.get().stringValue()); + } Optional name = Models.getProperty(metadata, column, CSVW.NAME); if (!name.isPresent()) { throw new RDFParseException("Metadata file does not contain name for column " + column); @@ -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 getFormat(Model metadata, Resource column) { + Optional 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 *