Skip to content

Commit

Permalink
enabled trig eval tests and fixed up trig parser
Browse files Browse the repository at this point in the history
  • Loading branch information
gromgull committed Dec 30, 2013
1 parent 5df7a0e commit 6b4622d
Show file tree
Hide file tree
Showing 3 changed files with 2,739 additions and 5 deletions.
29 changes: 26 additions & 3 deletions rdflib/plugins/parsers/trig.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from rdflib import ConjunctiveGraph
from rdflib.parser import Parser
from .notation3 import SinkParser, RDFSink, becauseSubexpression
from .notation3 import SinkParser, RDFSink


def becauseSubGraph(*args, **kwargs): pass


class TrigSinkParser(SinkParser):
Expand Down Expand Up @@ -29,8 +32,28 @@ def directiveOrStatement(self, argstr, h):
if j >= 0:
return self.checkDot(argstr, j)


return j

def labelOrSubject(self, argstr, i, res):
j = self.skipSpace(argstr, i)
if j < 0:
return j # eof
i = j

j = self.uri_ref2(argstr, i, res)
if j >= 0:
return j

if argstr[i] == '[':
j = self.skipSpace(argstr, i+1)
if j < 0:
self.BadSyntax(argstr, i,
"Expected ] got EOF")
if argstr[j] == ']':
res.append(self.blankNode())
return j+1
return -1

def graph(self, argstr, i):
"""
Expand All @@ -47,7 +70,7 @@ def graph(self, argstr, i):
if j >= 0: i = j

r = []
j = self.node(argstr, i, r)
j = self.labelOrSubject(argstr, i, r)
if j >= 0:
graph = r[0]
i = j
Expand Down Expand Up @@ -77,7 +100,7 @@ def graph(self, argstr, i):
oldParentContext = self._parentContext
self._parentContext = self._context
reason2 = self._reason2
self._reason2 = becauseSubexpression
self._reason2 = becauseSubGraph
self._context = self._store.newGraph(graph)

while 1:
Expand Down
18 changes: 16 additions & 2 deletions test/test_trig_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from rdflib import ConjunctiveGraph
from rdflib.namespace import split_uri
from rdflib.compare import graph_diff, isomorphic

from manifest import nose_tests, RDFT
Expand All @@ -14,7 +15,9 @@ def trig(test):
g = ConjunctiveGraph()

try:
g.parse(test.action, format='trig')
base = 'http://www.w3.org/2013/TriGTests/'+split_uri(test.action)[1]

g.parse(test.action, publicID=base, format='trig')
if not test.syntax:
raise AssertionError("Input shouldn't have parsed!")

Expand All @@ -23,8 +26,19 @@ def trig(test):
res.parse(test.result, format='nquads')

if verbose:


both, first, second = graph_diff(g,res)
if not first and not second: return

print '==============================='
print 'TriG'
print g.serialize(format='nquads')
print '==============================='
print 'NQuads'
print res.serialize(format='nquads')
print '==============================='

print "Diff:"
#print "%d triples in both"%len(both)
print "TriG Only:"
Expand All @@ -46,7 +60,7 @@ def trig(test):
testers = {
RDFT.TestTrigPositiveSyntax: trig,
RDFT.TestTrigNegativeSyntax: trig,
# RDFT.TestTrigEval: trig,
RDFT.TestTrigEval: trig,
RDFT.TestTrigNegativeEval: trig
}

Expand Down
Loading

0 comments on commit 6b4622d

Please sign in to comment.