SPARQL issue

16 views
Skip to first unread message

richarddi...@gmail.com

unread,
Jun 21, 2022, 1:41:12 PM6/21/22
to rdflib-dev
What is wrong with the following? I would expect 233.33 in the last variable.

Thank you.

d = Graph().parse(data = """
""")

q = """

SELECT (SUM(?value1) AS ?nominator) (COUNT(?s1) AS ?denominator) (?nominator / ?denominator AS ?indicator)

WHERE
{
        ?s1 <http://purl.org#val1> ?value1 .
}

"""
for r in d.query(q):
    print(r)

(rdflib.term.Literal('700', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#decimal')), rdflib.term.Literal('3', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')), None)

Nicholas Car

unread,
Jun 21, 2022, 10:44:48 PM6/21/22
to rdfli...@googlegroups.com
This is a SPARQL problem (well understanding issue) not an RDFLib thing. I'll give you the answer here but please ask these sort of issues on stackoverflow (tagged with 'rdflib') not on this development mailing list!

You need this query so that the indicator variable can be calculated on the back of variables with known values:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>


SELECT (?nominator / ?denominator AS ?indicator)

WHERE {
    SELECT (SUM(?value1) AS ?nominator) (COUNT(?s1) AS ?denominator)
    WHERE {
     ?s1 <http://purl.org#val1> ?value1 .
    }
}
Then you get:

(rdflib.term.Literal('233.3333333333333333333333333', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#decimal')),)


Cheers, Nick
--
Dr Nicholas Car
Data Architect & Semantic Web Specialist
Kurrawong AI
0477 560 177

Honorary Lecturer
College of Engineering & Computer Science
Australian National University
--

------- Original Message -------
--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/fa626618-35e3-48fa-936b-e8ee2a79997en%40googlegroups.com.

Richard Dijkstra

unread,
Jun 22, 2022, 2:20:30 AM6/22/22
to rdfli...@googlegroups.com
Nicholas,

Thank you for the reply. I did state the question here because other sparql engines do give the answer to the first query form.

So I have to check the sparql spec’s.

Regards, Richard 

Op 22 jun. 2022 om 04:44 heeft Nicholas Car <ni...@kurrawong.net> het volgende geschreven:



Nicholas Car

unread,
Jun 22, 2022, 3:03:10 AM6/22/22
to rdfli...@googlegroups.com
OK, if it works as you have it elsewhere, then this indeed could be an RDFLib SPARQL implementation issue.

Please do check the specs and let us know!


------- Original Message -------
Reply all
Reply to author
Forward
0 new messages