Skip to content

Commit

Permalink
Working on RDFLib#955 BIND test does not emmediatly die in the parser…
Browse files Browse the repository at this point in the history
… code now
  • Loading branch information
JervenBolleman committed Mar 8, 2020
1 parent 179cfb2 commit d09193b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
3 changes: 0 additions & 3 deletions rdflib/plugins/sparql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ def _hexExpand(match):
# [84] VerbPath ::= Path
VerbPath = Path

# See
VarOrBlankNodeOrIriOrLitOrEmbTP = Var | BlankNode | iri | RDFLiteral | NumericLiteral | BooleanLiteral
EmbTP = Combine(Suppress('<<'), VarOrBlankNodeOrIriOrLitOrEmbTP + Verb + VarOrBlankNodeOrIriOrLitOrEmbTP, Suppress('>>'))

VarOrTermOrEmbTP = Var | GraphTerm | EmbTP

Expand Down
47 changes: 47 additions & 0 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,53 @@ def skolemize(self, authority=None, basepath=None):
skolem = "%s%s" % (basepath, text_type(self))
return URIRef(urljoin(authority, skolem))

class Triple(Identifier):
"""
Triple: Needed for RDF*
"""
__slots__ = ()

def __new__(cls, sid=None,
subject=None, predicate=None, object=None):
triple = Identifier.__new__(cls, [subject, predicate, object, sid])


def toPython(self):
return text_type(self)

def n3(self, namespace_manager=None):
return "_:%s" % self

def __getnewargs__(self):
return (text_type(self), )

if PY2:
def __str__(self):
return self.encode()

def __repr__(self):
if self.__class__ is BNode:
clsName = "rdflib.term.Triple"
else:
clsName = self.__class__.__name__
return """%s('%s')""" % (clsName, str(self))

def asQuad(self):
_subject = self.value[0]
_predicate = self.value[1]
_object = self.value[2]
_sid = self.value[3]
_rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
_type = URIRef('type',base=_rdf)
_rdf_object = URIRef('object', base=_rdf)
_rdf_predicate = URIRef('predicate', base=_rdf)
_rdf_subject = URIRef('subject', base=_rdf)
_rdf_statement = URIRef('Statement', base=_rdf)
return [[_sid, _type , _rdf_statement],
[_sid , _rdf_object, _object],
[_sid, _rdf_predicate, _predicate],
[_sid, _rdf_subject, _subject]]

class Literal(Identifier):
__doc__ = """
Expand Down
21 changes: 19 additions & 2 deletions test/test_sparql_star.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
from rdflib import Graph


def test_basic_sparql_star_subject():
g = Graph()
res = g.query('''SELECT * WHERE {
<< ?s ?p ?o >> ?p2 ?o2 .
}''')

def test_basic_sparql_star():

def test_basic_sparql_star_object():
g = Graph()
res = g.query('''SELECT * WHERE {
<<?s ?p ?o>> ?p2 ?o2 .
?s ?p << ?s2 ?p2 ?o2 >> .
}''')

def test_basic_sparql():
g = Graph()
res = g.query('''SELECT * WHERE {
?s ?p ?o .
}''')


def test_bind_sparql_star():
g = Graph()
res = g.query('''SELECT * WHERE { BIND(<< ?s2 ?p2 ?o2 >> AS ?b) }''')

0 comments on commit d09193b

Please sign in to comment.