Skip to content

Commit

Permalink
Merge pull request #1386 from mwatts15/issue-873-rdf-namespace-does-n…
Browse files Browse the repository at this point in the history
…ot-allow-rdf-seq-valid-terms

Allowing Container Membership Properties in RDF namespace (#873)
  • Loading branch information
nicholascar committed Aug 13, 2021
2 parents 174c620 + 7135d38 commit e9fea54
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 66 deletions.
1 change: 1 addition & 0 deletions rdflib/namespace/_RDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RDF(DefinedNamespace):
"""

_fail = True
_underscore_num = True

# http://www.w3.org/1999/02/22-rdf-syntax-ns#List
nil: URIRef # The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it.
Expand Down
65 changes: 0 additions & 65 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,71 +288,6 @@ def _ipython_key_completions_(self):
return dir(self)


class _RDFNamespace(ClosedNamespace):
"""
Closed namespace for RDF terms
"""

def __new__(cls):
return super().__new__(
cls,
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
terms=[
# Syntax Names
"RDF",
"Description",
"ID",
"about",
"parseType",
"resource",
"li",
"nodeID",
"datatype",
# RDF Classes
"Seq",
"Bag",
"Alt",
"Statement",
"Property",
"List",
"PlainLiteral",
# RDF Properties
"subject",
"predicate",
"object",
"type",
"value",
"first",
"rest",
# and _n where n is a non-negative integer
# RDF Resources
"nil",
# Added in RDF 1.1
"XMLLiteral",
"HTML",
"langString",
# Added in JSON-LD 1.1
"JSON",
"CompoundLiteral",
"language",
"direction",
],
)

def term(self, name):
# Container membership properties
if name.startswith("_"):
try:
i = int(name[1:])
except ValueError:
pass
else:
if i > 0:
return URIRef(f"{self}_{i}")

return super().term(name)


XMLNS = Namespace("http://www.w3.org/XML/1998/namespace")


Expand Down
5 changes: 4 additions & 1 deletion test/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,7 @@ def test_contains_method(self):
)

ref = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
self.assertTrue(ref in RDF, "_RDFNamespace does not include rdf:type")
self.assertTrue(ref in RDF, "RDF does not include rdf:type")

ref = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#_1")
self.assertTrue(ref in RDF, "RDF does not include rdf:_1")

0 comments on commit e9fea54

Please sign in to comment.