Skip to content

Commit

Permalink
Merge branch 'master' into iwana-20220521T1742-more_sparql_typing
Browse files Browse the repository at this point in the history
  • Loading branch information
aucampia committed May 25, 2022
2 parents 54c0026 + 958b9a1 commit 3cdb550
Show file tree
Hide file tree
Showing 141 changed files with 12,689 additions and 25 deletions.
18 changes: 9 additions & 9 deletions rdflib/extras/infixowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ class Ontology(AnnotatableTerms):

def __init__(self, identifier=None, imports=None, comment=None, graph=None):
super(Ontology, self).__init__(identifier, graph)
self.imports = imports and imports or []
self.comment = comment and comment or []
self.imports = [] if imports is None else imports
self.comment = [] if comment is None else comment
if (self.identifier, RDF.type, OWL.Ontology) not in self.graph:
self.graph.add((self.identifier, RDF.type, OWL.Ontology))

Expand Down Expand Up @@ -959,12 +959,12 @@ def __init__(
):
self.graph.add((self.identifier, RDF.type, OWL.Class))

self.subClassOf = subClassOf and subClassOf or []
self.equivalentClass = equivalentClass and equivalentClass or []
self.disjointWith = disjointWith and disjointWith or []
self.subClassOf = [] if subClassOf is None else subClassOf
self.equivalentClass = [] if equivalentClass is None else equivalentClass
self.disjointWith = [] if disjointWith is None else disjointWith
if complementOf:
self.complementOf = complementOf
self.comment = comment and comment or []
self.comment = [] if comment is None else comment

def _get_extent(self, graph=None):
for member in (graph is None and self.graph or graph).subjects(
Expand Down Expand Up @@ -1306,7 +1306,7 @@ class OWLRDFListProxy(object):
def __init__(self, rdfList, members=None, graph=None):
if graph:
self.graph = graph
members = members and members or []
members = [] if members is None else members
if rdfList:
self._rdfList = Collection(self.graph, rdfList[0])
for member in members:
Expand Down Expand Up @@ -1418,7 +1418,7 @@ def isPrimitive(self):

def __init__(self, identifier=None, members=None, graph=None):
Class.__init__(self, identifier, graph=graph)
members = members and members or []
members = [] if members is None else members
rdfList = list(self.graph.objects(predicate=OWL.oneOf, subject=self.identifier))
OWLRDFListProxy.__init__(self, rdfList, members)

Expand Down Expand Up @@ -1985,7 +1985,7 @@ def __init__(
self.inverseOf = inverseOf
self.domain = domain
self.range = range
self.comment = comment and comment or []
self.comment = [] if comment is None else comment

def serialize(self, graph):
for fact in self.graph.triples((self.identifier, None, None)):
Expand Down
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/trix.py
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion rdflib/plugins/serializers/trix.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def serialize(
elif isinstance(self.store, Graph):
self._writeGraph(self.store)
else:
raise Exception("Unknown graph type: " + type(self.store))
raise Exception(f"Unknown graph type: {type(self.store)}")

self.writer.pop()
stream.write("\n".encode("latin-1"))
Expand Down
2 changes: 1 addition & 1 deletion rdflib/plugins/serializers/xmlwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def qname(self, uri):
for pre, ns in self.extra_ns.items():
if uri.startswith(ns):
if pre != "":
return ":".join(pre, uri[len(ns) :])
return ":".join([pre, uri[len(ns) :]])
else:
return uri[len(ns) :]

Expand Down
7 changes: 0 additions & 7 deletions rdflib/plugins/sparql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,6 @@ def expandCollection(terms):
)


def _hexExpand(match):
return chr(int(match.group(0)[1:], 16))


PN_LOCAL.setParseAction(lambda x: re.sub("(%s)" % PERCENT_re, _hexExpand, x[0]))


# [141] PNAME_LN ::= PNAME_NS PN_LOCAL
PNAME_LN = PNAME_NS + Param("localname", PN_LOCAL.leaveWhitespace())

Expand Down
42 changes: 42 additions & 0 deletions test/data/suites/trix/README
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 3cdb550

Please sign in to comment.