-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RDF4j driver: Literals with datatype xsd:boolean not converted correctly to java types #1337
Comments
If the triples are inserted manually as physical triples, does the problem occur when querying via RDF4J, as I doubt the problem would be due to the data coming from Linked Data Views? Also, are the Linked Data Views generated as transient/virtual or physical triples? If you run the query via the Virtuoso SPARQL endpoint, is the data returned as expected? Do you have sample RDF4J code to show how the query is being expected in RDF4J? |
The issue is linked data view related. e.g., inserting a normal triple
gives
instead of the above. test(){
try (RepositoryConnection conn = managedVirtuoso.getRepository().getConnection()) {
TupleQuery tq = conn.prepareTupleQuery(
"SELECT ?s (datatype(?o) AS ?p) ?o WHERE { GRAPH ?g {?s <http://purl.uniprot.org/core/obsolete> ?o }}");
try (TupleQueryResult evaluate = tq.evaluate()) {
while (evaluate.hasNext()) {
printRes(evaluate.next());
}
}
}
}
private void printRes(BindingSet next) {
System.out.print(next.getBinding("s").getValue().stringValue());
System.out.print("\t");
System.out.print(next.getBinding("p").getValue().stringValue());
System.out.print("\t");
Binding ob = next.getBinding("o");
if (ob == null) {
System.err.println("missing");
} else {
Value object = ob.getValue();
System.out.print(object.stringValue());
if (object.isLiteral()) {
System.out.print(" (" + ((Literal) object).getDatatype() + ")");
}
System.out.println();
}
} The isql commandline is correct in both cases. It is only when running the query via RDF4j that the datatype is not correctly picked up in the linked data view. Using an SQL |
I am not sure? the mapped tables are in virtuoso itself. |
OK, we are looking into this. I suspect the Linked Data Views would be virtual triples, i.e., dynamically generated at query time, which they would be by default, as there is a specific additional step required to materialise them as physical triples. |
Can you provide the Literal classes & views quad map that was used to generate the Linked Data View that is causing this issue in the RDF4J java types being returned? |
@HughWilliams Trying to create a minimal example to reproduce. I noticed something odd using just isql, no RDF4j.
This has no results
This does
|
Development provided the following script which shows the correct datatype and boolean values via command line
The Java/RDF4J program returns proper results:
|
@HughWilliams is there a comma missing in
|
The literal class definition is
Also it is appropriate the inverse to understand integer as input when used for literal filtering on boolean
HTH |
Coming back to this because I am still getting the error :( Removing rdf4j from the picture and using just the jdbc connection. java.sql.Statement statement = ((VirtuosoRepositoryConnection)repository .getConnection()).getQuadStoreConnection().createStatement();
try {
ResultSet execute = statement.executeQuery("SPARQL define input:storage virtrdf:uniparc SELECT ?s (datatype(?o) AS ?p) ?o WHERE { GRAPH ?g {?s <http://purl.uniprot.org/core/obsolete> ?o }}");
while(execute.next()) {
var s = execute.getObject(1);
var p =execute.getString(2);
var o = execute.getObject(3);
System.out.print(s);
System.out.print(",");
System.out.print(s.getClass());
System.out.print("\t");
System.out.print(p);
System.out.print(",");
System.out.print(p.getClass());
System.out.print("\t");
System.out.print(o);
System.out.print(",");
System.out.print(o.getClass());
System.out.println();
}
} finally {
statement.close();
} I have the output that 's' is a VirtuosoExtendedString, 'p' or the dataatype is a java.lang.String and the same for the 'o' object. And this is with the boolean conversion code as given by @imitko . The raw query log is:
|
Starting with a linked data view (in case this is important)
I have this native result
Running the same query via the RDF4j driver I get
http://purl.uniprot.org/uniparc/UPI0000000001#MD56329AB26D04CBB442AE0D418712AC2F2 http://www.w3.org/2001/XMLSchema#boolean true (http://www.w3.org/2001/XMLSchema#string)
http://purl.uniprot.org/uniparc/UPI0000000001#MD5531CD9580E20E9C98B967AC7FFB6DB7A http://www.w3.org/2001/XMLSchema#boolean true (http://www.w3.org/2001/XMLSchema#string)
The datatype of the literal value has returned to the default value of xsd:string. This might be due to the castValue method only expecting '0' and '1' as the literal values and not 'true' and 'false'
The text was updated successfully, but these errors were encountered: