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

preparedQuery error (specific in Python3) #545

Closed
suzuki-shm opened this issue Nov 18, 2015 · 1 comment
Closed

preparedQuery error (specific in Python3) #545

suzuki-shm opened this issue Nov 18, 2015 · 1 comment
Labels
bug Something isn't working SPARQL
Milestone

Comments

@suzuki-shm
Copy link

When I write this query, I got error in Python3.5
Query program is below.

from rdflib import Namespace
from rdflib.plugins import sparql
from rdflib.namespace import RDFS, OWL, DC, SKOS
query = sparql.prepareQuery(
        """
            SELECT DISTINCT ?property ?parent
            WHERE{
                ?property a owl:DeprecatedProperty .
                ?property dc:relation ?relation .
                ?property rdfs:subPropertyOf ?parent .
                ?property rdfs:label | skos:altLabel ?label . 
            }
        """,
        initNs = {"rdfs":RDFS, "owl":OWL, "dc":DC, "skos":SKOS})

Error log is below.

TypeError                                 Traceback (most recent call last)
<ipython-input-59-83c306286d37> in <module>()
     12             }
     13         """,
---> 14         initNs = {"rdfs":RDFS, "owl":OWL, "dc":DC, "skos":SKOS})

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/processor.py in prepareQuery(queryString, initNs, base)
     23     Parse and translate a SPARQL Query
     24     """
---> 25     return translateQuery(parseQuery(queryString), base, initNs)
     26 
     27 

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/algebra.py in translateQuery(q, base, initNs)
    742         q[1], visitPost=functools.partial(translatePName, prologue=prologue))
    743 
--> 744     P, PV = translate(q[1])
    745     datasetClause = q[1].datasetClause
    746     if q[1].name == 'ConstructQuery':

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/algebra.py in translate(q)
    531 
    532     # all query types have a where part
--> 533     M = translateGroupGraphPattern(q.where)
    534 
    535     aggregate = False

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/algebra.py in translateGroupGraphPattern(graphPattern)
    276             if not (g and g[-1].name == 'BGP'):
    277                 g.append(BGP())
--> 278             g[-1]["triples"] += triples(p.triples)
    279         else:
    280             g.append(p)

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/algebra.py in triples(l)
    129         raise Exception('these aint triples')
    130     return reorderTriples((l[x], l[x + 1], l[x + 2])
--> 131                           for x in range(0, len(l), 3))
    132 
    133 

/home/UserName/.pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/rdflib/plugins/sparql/algebra.py in reorderTriples(l)
    111     while i < len(l):
    112         l[i:] = sorted((_knownTerms(x[
--> 113                        1], varsknown, varscount), x[1]) for x in l[i:])
    114         t = l[i][0][0]  # top block has this many terms bound
    115         j = 0

TypeError: unorderable types: AlternativePath() < URIRef()

However, this preparedQuery has no problem in Python 2.7.10 , and This error is solved if query is modified by grouping triple pattern.
Modified query is below .

from rdflib import Namespace
from rdflib.plugins import sparql
from rdflib.namespace import RDFS, OWL, DC, SKOS
query = sparql.prepareQuery(
        """
            SELECT DISTINCT ?property ?parent
            WHERE{
                ?property a owl:DeprecatedProperty .
                ?property dc:relation ?relation .
                ?property rdfs:subPropertyOf ?parent .
                {?property rdfs:label | skos:altLabel ?label .}
            }
        """,
        initNs = {"rdfs":RDFS, "owl":OWL, "dc":DC, "skos":SKOS})

It looks like a bug.
regard.

@gromgull
Copy link
Member

This is essentially the same bug as this one:

#492

Path objects must be made comparable with all RDFLib terms.

@joernhees joernhees added bug Something isn't working SPARQL labels Nov 22, 2015
@joernhees joernhees added this to the rdflib 4.2.2 milestone Nov 22, 2015
gromgull added a commit that referenced this issue Nov 29, 2015
let paths be comparable against all nodes. Fixes #545
joernhees added a commit that referenced this issue Jan 28, 2016
* master: (49 commits)
  Update reference to "Emulating container types"
  Avoid class reference to imported function
  Prevent RDFa parser from failing on time elements with child nodes
  Second proposed fix for the broken top_level.txt
  make Prologue and Query new style classes
  DOC: minor typo in paramater
  DOC: unamed -> unnamed
  AuditableStore.commit does not call self.store.commit anymore
  ignore operations with no effect
  fixed trivial copy-paste bug
  added test cases for AuditableStore
  expanded path comparison ops in order to keep py2.6 support and not use total_ordering
  let paths be comparable against all nodes. Fixes #545
  re-introduces special handling for DCTERMS.title and test for it
  Fix initBindings handling. Fixes #294
  added .n3 methods for path objects
  Made ClosedNamespace (and _RDFNamespace) inherit from Namespace
  cleaned up trailing whitespace
  Small but nice SPARQL Optimisation fix
  test for #546 from_n3 trailing backslash
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SPARQL
Projects
None yet
Development

No branches or pull requests

3 participants