-
Notifications
You must be signed in to change notification settings - Fork 555
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
In using SERVICE, "string" variables get retrieved as NULL #1278
Comments
Thanks @chapai2021! I've been meaning to file an issue for these exact same issues. After some pdb'ing I saw that the regex for the service clause is only checking for 'service'. Not sure if a case-insensitive switch would have unintended side effects. But the missing string literals are quite strange. I checked the In addition to those two points (happy to re-submit this as a separate issue) I found that extraction of the url between the '<>' will go out of bounds when using comments within the service clause's scope. For example:
will result in the following url being used for the federated request:
The regex for this seems to be pretty permissive |
The |
Hi @nicholascar Could you explain more about the Is it fixed in 6.0.0? Do I need to upgrade RDFLib to a specific version? |
Answering my own question: The current But not the version 5.0.0: https://github.com/RDFLib/rdflib/blob/5.0.0/rdflib/plugins/sparql/evaluate.py#L280 |
Hi @vermonet, glad you got to this quickly and thanks very much for returning here to post your answer! |
I encountered the same issue with literals getting returned as NULL, more specifically literals that do not have their datatype defined. Those cases are not covered by the current implementation: rdflib/rdflib/plugins/sparql/evaluate.py Lines 384 to 395 in 6f2c11c
I would propose to use similar logic as is used by the JSON results parser (or even reuse those functions/methods): rdflib/rdflib/plugins/sparql/results/jsonresults.py Lines 89 to 107 in 6f2c11c
|
Fixes #1278 simple literals returned as NULL. The resolution uses same logic as here: https://github.com/RDFLib/rdflib/blob/6f2c11cd2c549d6410f9a1c948ab3a8dbf77ca00/rdflib/plugins/sparql/results/jsonresults.py#L89-L107 Co-authored-by: Mark van der Pas <mark.van.der.pas@semaku.com> Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
I was testing the federated SPARQL queries using "service". There are two issues:
Sorry, I do not have time to create a small reproducible example.
Below, two examples of querying the same SPARQL endpoint, one with
from pandas import DataFrame
from rdflib.plugins.sparql.processor import SPARQLResult
def sparql_results_to_df(results: SPARQLResult) -> DataFrame:
return DataFrame(
data=([None if x is None else x.toPython() for x in row] for row in results),
columns=[str(x) for x in results.vars],
)
qf="""
PREFIX tsmodel: http://siemens.com/tsmodel/
PREFIX vobj: http://siemens.com/tsmodel/VAROBJECTS#
"""
results=graph.query(qf)
df=sparql_results_to_df(results)
df.head(20)
x node_name idx
0 http://siemens.com/tsmodel/VAROBJECTS/idx=1 None 1
1 http://siemens.com/tsmodel/VAROBJECTS/idx=2 None 2
2 http://siemens.com/tsmodel/VAROBJECTS/idx=3 None 3
3 http://siemens.com/tsmodel/VAROBJECTS/idx=4 None 4
4 http://siemens.com/tsmodel/VAROBJECTS/idx=5 None 5
import sparql_dataframe
endpoint = "http://localhost:8080/sparql"
q = """
PREFIX tsmodel: http://siemens.com/tsmodel/
PREFIX vobj: http://siemens.com/tsmodel/VAROBJECTS#
SELECT ?x ?node_name ?idx {
?x a tsmodel:VAROBJECTS .
?x vobj:idx ?idx .
?x vobj:node_name ?node_name .
}
"""
df = sparql_dataframe.get(endpoint, q)
df.head()
0 http://siemens.com/tsmodel/VAROBJECTS/idx=1 ns=3;s="ultrasonicLeft" 1
1 http://siemens.com/tsmodel/VAROBJECTS/idx=2 ns=3;s="voltageL1-N" 2
2 http://siemens.com/tsmodel/VAROBJECTS/idx=3 ns=3;s="voltageL2-N" 3
3 http://siemens.com/tsmodel/VAROBJECTS/idx=4 ns=3;s="voltageL3-N" 4
4 http://siemens.com/tsmodel/VAROBJECTS/idx=5 ns=3;s="currentL1" 5
I do have more examples like this. As I have checked, "int", "float", "datetime" work fine. But, "string" variables are always get "NULL".
The text was updated successfully, but these errors were encountered: