SANSA-Stack/Archived-SANSA-Examples

Error when querying SPARQL endpoint using the sparqlify example

Closed this issue · 5 comments

I have converted the pizza ontology (https://protege.stanford.edu/ontologies/pizza/pizza.owl) to n-triples using OWL api and then gave it as input to the sparqlify example. It sets up the sparql endpoint ok and generic queries execute without problem, such as:

SELECT * WHERE {
  ?s ?p ?o .
}

however when I try to search for a literal with a language tag:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT * WHERE {
  ?s rdfs:label "American"@en .
}

I get an error:

Exception in thread "Thread-45" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: No SQL conversion found for NodeValue: "American"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString> ( http://www.w3.org/1999/02/22-rdf-syntax-ns#langString)
	at org.aksw.jena_sparql_api.web.utils.RunnableAsyncResponseSafe.run(RunnableAsyncResponseSafe.java:29)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: No SQL conversion found for NodeValue: "American"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString> ( http://www.w3.org/1999/02/22-rdf-syntax-ns#langString)
	at org.aksw.jena_sparql_api.web.servlets.SparqlEndpointBase$3.run(SparqlEndpointBase.java:354)
	at org.aksw.jena_sparql_api.web.utils.RunnableAsyncResponseSafe.run(RunnableAsyncResponseSafe.java:26)
	... 1 more
Caused by: java.lang.RuntimeException: No SQL conversion found for NodeValue: "American"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString> ( http://www.w3.org/1999/02/22-rdf-syntax-ns#langString)
	at org.aksw.sparqlify.core.cast.TypeSystemImpl.convertSql(TypeSystemImpl.java:231)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.translate(TypedExprTransformerImpl.java:766)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:268)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:320)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:277)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:320)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:277)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:320)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:277)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:320)
	at org.aksw.sparqlify.core.cast.TypedExprTransformerImpl.rewrite(TypedExprTransformerImpl.java:229)
	at org.aksw.sparqlify.util.SqlTranslatorImpl2.translate(SqlTranslatorImpl2.java:73)
	at org.aksw.sparqlify.core.algorithms.MappingOpsImpl.createExprSqlRewrites(MappingOpsImpl.java:481)
	at org.aksw.sparqlify.core.algorithms.MappingOpsImpl.createSqlConditionItems(MappingOpsImpl.java:500)
	at org.aksw.sparqlify.core.algorithms.MappingOpsImpl.createSqlCondition(MappingOpsImpl.java:522)
	at org.aksw.sparqlify.core.algorithms.MappingOpsImpl.filter(MappingOpsImpl.java:1276)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:161)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:324)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewriteList(OpMappingRewriterImpl.java:91)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:101)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:336)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:207)
	at org.aksw.sparqlify.core.algorithms.OpMappingRewriterImpl.rewrite(OpMappingRewriterImpl.java:320)
	at org.aksw.sparqlify.core.interfaces.SparqlSqlOpRewriterImpl.rewrite(SparqlSqlOpRewriterImpl.java:98)
	at org.aksw.sparqlify.core.algorithms.SparqlSqlStringRewriterImpl.rewrite(SparqlSqlStringRewriterImpl.java:44)
	at net.sansa_stack.query.spark.sparqlify.QueryExecutionSparqlifySpark.executeCoreSelect(QueryExecutionSparqlifySpark.java:39)
	at org.aksw.jena_sparql_api.core.QueryExecutionBaseSelect.execSelect(QueryExecutionBaseSelect.java:378)
	at org.aksw.jena_sparql_api.web.servlets.ProcessQuery.processQuery(ProcessQuery.java:121)
	at org.aksw.jena_sparql_api.web.servlets.ProcessQuery.processQuery(ProcessQuery.java:79)
	at org.aksw.jena_sparql_api.web.servlets.SparqlEndpointBase$3.run(SparqlEndpointBase.java:351)
	... 2 more

this seems to be valid syntax (https://www.w3.org/TR/rdf-sparql-query/#matchingRDFLiterals) so might be a bug

Ok an update: rewriting it as this works:

SELECT * {
?s ?p ?o .
    FILTER (str(?o) = "American")
    FILTER (lang(?o) = 'en')
}

I think it is related to the "@" symbol being in the string sent to the server and the protocol complains about it? Maybe this is related?

17/11/20 18:10:19 WARN WebComponent: A servlet request to the URI http://localhost:7531/sparql?query=SELECT+%2A+%7B%0D%0A%3Fs+%3Fp+%22American%22%40en+.%0D%0A%7D contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

While it could be an encoding error related to the server request, it is also likely that this is either a missing feature or a regression back at the time when Jena added support of RDF1.1. Will investigate.

I guess it's because of rdf:langString literal. Not sure how Sparqlify handles literals with this datatype.

Added potential fix to the underlying jena-sparql-api SmartDataAnalytics/jena-sparql-api@c2f4b90

Closing it as it should be fixed.