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

Fix trix parser #1966

Merged
merged 7 commits into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/trix.py
Expand Up @@ -56,7 +56,7 @@ def startElementNS(self, name, qname, attrs):
% (name[0], TRIXNS)
)

if name[1] == "TriX":
if name[1].lower() == "trix":
if self.state == 0:
self.state = 1
else:
Expand Down Expand Up @@ -205,7 +205,7 @@ def endElementNS(self, name, qname):
self.graph = None
self.state = 1

elif name[1] == "TriX":
elif name[1].lower() == "trix":
self.state = 0

else:
Expand Down
42 changes: 42 additions & 0 deletions test/data/suites/trix/README
@@ -0,0 +1,42 @@
This README is adapted from the README of the W3C RDF Working Group's
TriG test suite and modified for use with RDFLib's informally-assembled
TrIX test suite. This test suite contains three kinds of tests:

Evaluation (rdft:TestTrixEval) - a pair of an input trig file
and reference ntriples file.

Positive syntax (rdft:TestTrixPositiveSyntax) - an input trig
file with no syntax errors.

Negative syntax (rdft:TestTrixNegativeSyntax) - an input trig
file with at least one syntax error.

The manifest.ttl file in this directory lists all of the tests in the
RDFLib TriX test suite. Each test is one of the above tests. All
tests have a name (mf:name) and an input (mf:action). The Evaluation
tests have an expected result (mf:result).

• An implementation passes an Evaluation test if it parses the input
into a graph, parses the expecte result into another graph, and
those two graphs are isomorphic (see
<http://www.w3.org/TR/rdf11-concepts/#graph-isomorphism>).

• An implementation passes a positive syntax test if it parses the
input.

• An implementation passes a negative syntax test if it fails to parse
the input.

The IRI for the test suite is <https://rdflib.github.io/tests/trix/>.
Per RFC 3986 section 5.1.3, the base IRI for parsing each file is the
retrieval IRI for that file. For example, the tests trig-subm-01 and
trig-subm-27 require relative IRI resolution against a base of
<https://rdflib.github.io/tests/trix/trig-subm-01.trix> and
<https://rdflib.github.io/tests/trix/strig-subm-27.trix> respectively.


Adapted from https://github.com/w3c/rdf-tests/blob/main/trig/README,
authors:

Eric Prud'hommeaux <eric+turtle@w3.org> - 11 June 2013.
Gregg Kellogg <gregg@greggkellogg.net> - 12 June 2013.
20 changes: 20 additions & 0 deletions test/data/suites/trix/extension1.xsl
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!-- Replaces any XML document by a hard-coded TriX document containing
one graph with one triple -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2004/03/trix/trix-1/"
xmlns:ex="http://example.com/#"
version="2.0">
<xsl:template match="/">
<TriX>
<graph>
<triple>
<qname>ex:a</qname>
<qname>ex:b</qname>
<qname>ex:c</qname>
</triple>
</graph>
</TriX>
</xsl:template>
</xsl:stylesheet>
33 changes: 33 additions & 0 deletions test/data/suites/trix/extension2.xsl
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!-- Expands <qname>ns:foo</qname> to <uri>.....foo</uri> using xmlns:ns -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2004/03/trix/trix-1/"
xmlns:trix="http://www.w3.org/2004/03/trix/trix-1/"
xmlns:ex="http://example.com/#"
version="2.0">

<!-- Expand qnames -->
<xsl:template match="trix:qname">
<uri>
<xsl:variable name="ns">
<xsl:value-of select="substring-before(text(),':')"/>
</xsl:variable>
<xsl:value-of select="namespace::*[local-name()=$ns]"/>
<xsl:value-of select="substring-after(text(),':')"/>
</uri>
</xsl:template>

<!-- Not necessary, but avoids namespace declarations scattered through
the result document -->
<xsl:template match="trix:TriX">
<TriX><xsl:apply-templates/></TriX>
</xsl:template>

<!-- This is a simple identity function -->
<xsl:template match="@*|*|processing-instruction()|comment()" priority="-2">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|processing-instruction()|comment()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>