Skip to content
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

DESCRIBE query not working #479

Closed
nvitucci opened this issue Mar 24, 2015 · 8 comments · Fixed by #2221
Closed

DESCRIBE query not working #479

nvitucci opened this issue Mar 24, 2015 · 8 comments · Fixed by #2221
Labels
enhancement New feature or request SPARQL

Comments

@nvitucci
Copy link

Apparently DESCRIBE queries are not fully implemented yet? This is what I get with two different queries:

  1. g.query('DESCRIBE http://www.example.org/a')
    ...
    /usr/lib/python2.7/site-packages/rdflib/plugins/sparql/algebra.pyc in translate(q)
    530
    531 # all query types have a where part
    --> 532 M = translateGroupGraphPattern(q.where)
    533
    534 aggregate = False

/usr/lib/python2.7/site-packages/rdflib/plugins/sparql/algebra.pyc in translateGroupGraphPattern(graphPattern)
261 """
262
--> 263 if graphPattern.name == 'SubSelect':
264 return ToMultiSet(translate(graphPattern)[0])
265

AttributeError: 'NoneType' object has no attribute 'name'

  1. g.query('DESCRIBE ?s WHERE {?s ?p ?o FILTER (?s = http://www.example.org/a)}')

...
/usr/lib/python2.7/site-packages/rdflib/plugins/sparql/evaluate.pyc in evalPart(ctx, part)
260
261 elif part.name == 'DescribeQuery':
--> 262 raise Exception('DESCRIBE not implemented')
263
264 else:

Exception: DESCRIBE not implemented

The graph is created via this sequence:

import rdflib
from rdflib import RDF

ex = rdflib.Namespace('http://www.example.org/')
g = rdflib.Graph()
g.add((ex['a'], RDF['type'], ex['Cl']))

@gromgull
Copy link
Member

As the exception says DESCRIBE queries are not supported. It should be easy enough to implement, PRs are as always welcome :)

Without checking, but I think the first query should be DESCRIBE <http://example.org/a>. then you should get an exception saying it's not implemented there as well :)

@joernhees
Copy link
Member

describe needs CBDs, so should be based on the solution to #123

@fardokhtsadat
Copy link

Hello,

I am using rdflib version 6.0.2, and for describe queries, I get the following error:
Exception: DESCRIBE not implemented

Is this issue fixed or describe the queries are still not implemented in rdflib?

Best regards,
Fardokht

@ms1901
Copy link

ms1901 commented May 10, 2022

Hey!
As mentioned in the conversation above, DESCRIBE query implementation would require the use of CBDs. I have been working on implementing the DESCRIBE query, which returns a SPARQL result containing all triples with the query as our subject and object, along with the resolution of triples containing blank nodes. This implementation will return the result for DESCRIBE <http://example.org/a>.

@aucampia
Copy link
Member

aucampia commented May 12, 2022

@gargayush18
Copy link

Hey , I would also like to work on this issue.

@gargayush18
Copy link

One of the possible for this could be use of the multiple Select queries to find the solution for the Describe Query.
This will lead to the use of the exactly 2 select Queries.
Could be better explained with an example:
Example:
PREFIX foaf: http://xmlns.com/foaf/0.1/
DESCRIBE ?x
WHERE { ?x foaf:name "Alice" }

Now here we can use first Select Query to find the exact values of ?x.
this could be achieved through the Query:

PREFIX foaf: http://xmlns.com/foaf/0.1/
SELECT ?x
WHERE { ?x foaf:name "Alice" }

Lets suppose we get ?x as "www.example.org/Alice"

now can breakdown this? x into the prefix and corresponding value let's say : prefix: Alice in this case

Now run the query
PREFIX foaf: http://xmlns.com/foaf/0.1/
SELECT ?p ?q
WHERE {prefix:Alice ?p ?q }

This will return all the results related to the Alice and then this result can be formatted to produce the result .

@ghost
Copy link

ghost commented May 13, 2022

That approach could work but an implementation that aims to conform to SPARQL 1.1 spec would also have to observe SolutionModifier constraints:

DescribeQuery | ::= | "DESCRIBE" ( VarOrIri+  \| "*")  DatasetClause*  WhereClause?  SolutionModifier

aucampia pushed a commit that referenced this issue Feb 7, 2023
This adds an implementation for SPARQL DESCRIBE queries, using the built-in `cbd` method. I see there are several issues and PRs for DESCRIBE implementation. I believe this should close #479 and should resolve #1913, or at least pick up where it left off. It should also resolve #1096.

This implementation should support the full SPARQL specification for DESCRIBE; either explicit IRIs can be provided (with no WHERE clause), or variables projected from a WHERE clause can be provided, or variables projected from a WHERE clause AND explicit IRIs can be provided. If a WHERE clause is provided, it should be evaluated the same way as it would for a SELECT DISTINCT query (including dataset specifications).

The expected results for the test cases provided match the behaviour seen when running the same queries against the same data using ARQ.

A possible future extension would be to add a global option (similar to `rdflib.plugins.sparql.SPARQL_LOAD_GRAPHS`) to change the method used to describe resources instead of always using CBD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SPARQL
Projects
None yet
7 participants