Repository: RDFLib/rdflib

Issue:
RDF namespace does not allow rdf:Seq valid terms
Hi,

According to the [RDFS recommendation](https://www.w3.org/TR/rdf-schema/#ch_collectionvocab), elements of an rdf:Seq can be ordered by using predicates of the form:

`C rdf:_nnn O`

"where `nnn` is the decimal representation of an integer greater than 0 with no leading zeros". However in rdflibish notation these do not work:

```
>>> RDF["_1"]
Exception: term '_1' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
>>> RDF._1
Exception: term '_1' not in namespace 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
```

My current workaround is to mint new URIRefs for these, but I guess a more elegant solution could be provided?

Thanks,
Albert


Discussion:

Patch:
diff --git a/rdflib/namespace/_RDF.py b/rdflib/namespace/_RDF.py
index 61bc4a58..f79d75a7 100644
--- a/rdflib/namespace/_RDF.py
+++ b/rdflib/namespace/_RDF.py
@@ -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.
diff --git a/rdflib/namespace/__init__.py b/rdflib/namespace/__init__.py
index 62a2a946..23f4ec0e 100644
--- a/rdflib/namespace/__init__.py
+++ b/rdflib/namespace/__init__.py
@@ -288,71 +288,6 @@ class ClosedNamespace(Namespace):
         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")
 
 


Test patch:
diff --git a/test/test_namespace.py b/test/test_namespace.py
index 23fdb1e2..76f5bbf1 100644
--- a/test/test_namespace.py
+++ b/test/test_namespace.py
@@ -241,4 +241,7 @@ class NamespacePrefixTest(unittest.TestCase):
         )
 
         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")