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 ee04b0d commit 67252f9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2024 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
package org.eclipse.rdf4j.rio.csvw.parsers;

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.Values;

/**
*
* @author Bart Hanssens
*/
public class CellParserBoolean extends CellParser {
private String valueTrue;
private String valueFalse;

@Override
public void setFormat(String format) {
String[] values = format.split("\\|");
valueTrue = values[0];
valueFalse = values[1];
}

@Override
public Value parse(String cell) {
String s = cell;
if ((s == null || s.isEmpty()) && (defaultValue != null)) {
s = defaultValue;
}
return Values.literal(valueTrue.equals(s) ? "true" : "false", dataType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ public void setFormat(String format) {
formatter = DateTimeFormatter.ofPattern(format);
}

/**
* Get the value from a cell
*
* @param cell
* @return
*/
@Override
public Value parse(String cell) {
String s = cell;
if ((s == null || s.isEmpty()) && (defaultValue != null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static CellParser create(IRI datatype) {

if (datatype.equals(XSD.DATE.getIri())) {
p = new CellParserDate();
} else if (datatype.equals(XSD.BOOLEAN.getIri())) {
p = new CellParserBoolean();
} else {
p = new CellParser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
*/
@ExtendWith(MockServerExtension.class)
public class CSVWMetadataFinderTest extends AbstractTest {
private MockServerClient client;

@BeforeEach
public void init(MockServerClient client) throws IOException {
this.client = client;
Expand Down
5 changes: 4 additions & 1 deletion core/rio/csvw/src/test/resources/painters-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"format": "d/M/yyyy"
} },
{ "name": "maried",
"datatype": "boolean" },
"datatype": {
"base": "boolean",
"format": "Yes|No"
} },
{ "name": "languages",
"separator": " " }
],
Expand Down
6 changes: 3 additions & 3 deletions core/rio/csvw/src/test/resources/painters.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"wikidata_id","first_name","last_name,country_id","country_name_nl","country_name_en","date_of_birth","married","languages"
"Q5582","Vincent","van Gogh","Q29999","Nederland","The Netherlands","30/3/1853","false","dutch french"
"Q164712","Paul,Delvaux","Q31","België","Belgium","23/9/1897","true",french"
"Q46408","Georgia","O'Keeffe","Q30","Verenigde Staten","United States","15/11/1887","true","english"
"Q5582","Vincent","van Gogh","Q29999","Nederland","The Netherlands","30/3/1853","No","dutch french"
"Q164712","Paul","Delvaux","Q31","België","Belgium","23/9/1897","Yes","french"
"Q46408","Georgia","O'Keeffe","Q30","Verenigde Staten","United States","15/11/1887","Yes","english"

0 comments on commit 67252f9

Please sign in to comment.