+40
-11
lines changedFilter options
+40
-11
lines changed Original file line number Diff line number Diff line change
@@ -213,6 +213,15 @@
213
213
ZeroOrOne = "?"
214
214
215
215
216
+
def _n3(
217
+
arg: Union["URIRef", "Path"], namespace_manager: Optional["NamespaceManager"] = None
218
+
) -> str:
219
+
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
220
+
if isinstance(arg, (SequencePath, AlternativePath)) and len(arg.args) > 1:
221
+
return "(%s)" % arg.n3(namespace_manager)
222
+
return arg.n3(namespace_manager) # type: ignore[union-attr]
223
+
224
+
216
225
@total_ordering
217
226
class Path:
218
227
__or__: Callable[["Path", Union["URIRef", "Path"]], "AlternativePath"]
@@ -260,8 +269,7 @@ def __repr__(self) -> str:
260
269
return "Path(~%s)" % (self.arg,)
261
270
262
271
def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
263
-
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
264
-
return "^%s" % self.arg.n3(namespace_manager) # type: ignore[union-attr]
272
+
return "^%s" % _n3(self.arg, namespace_manager)
265
273
266
274
267
275
class SequencePath(Path):
@@ -318,8 +326,7 @@ def __repr__(self) -> str:
318
326
return "Path(%s)" % " / ".join(str(x) for x in self.args)
319
327
320
328
def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
321
-
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
322
-
return "/".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]
329
+
return "/".join(_n3(a, namespace_manager) for a in self.args)
323
330
324
331
325
332
class AlternativePath(Path):
@@ -345,8 +352,7 @@ def __repr__(self) -> str:
345
352
return "Path(%s)" % " | ".join(str(x) for x in self.args)
346
353
347
354
def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
348
-
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
349
-
return "|".join(a.n3(namespace_manager) for a in self.args) # type: ignore[union-attr]
355
+
return "|".join(_n3(a, namespace_manager) for a in self.args)
350
356
351
357
352
358
class MulPath(Path):
@@ -470,8 +476,7 @@ def __repr__(self) -> str:
470
476
return "Path(%s%s)" % (self.path, self.mod)
471
477
472
478
def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
473
-
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
474
-
return "%s%s" % (self.path.n3(namespace_manager), self.mod) # type: ignore[union-attr]
479
+
return "%s%s" % (_n3(self.path, namespace_manager), self.mod)
475
480
476
481
477
482
class NegatedPath(Path):
@@ -505,8 +510,7 @@ def __repr__(self) -> str:
505
510
return "Path(! %s)" % ",".join(str(x) for x in self.args)
506
511
507
512
def n3(self, namespace_manager: Optional["NamespaceManager"] = None) -> str:
508
-
# type error: Item "Path" of "Union[Path, URIRef]" has no attribute "n3" [union-attr]
509
-
return "!(%s)" % ("|".join(arg.n3(namespace_manager) for arg in self.args)) # type: ignore[union-attr]
513
+
return "!(%s)" % ("|".join(_n3(arg, namespace_manager) for arg in self.args))
510
514
511
515
512
516
class PathList(list):
Original file line number Diff line number Diff line change
@@ -54,15 +54,40 @@
54
54
"rdfs:subClassOf?",
55
55
),
56
56
(
57
-
RDF.type / RDFS.subClassOf * "*",
57
+
RDF.type / MulPath(RDFS.subClassOf, "*"),
58
58
f"<{RDF.type}>/<{RDFS.subClassOf}>*",
59
59
"rdf:type/rdfs:subClassOf*",
60
60
),
61
+
(
62
+
RDF.type / ((SequencePath(RDFS.subClassOf)) * "*"),
63
+
f"<{RDF.type}>/<{RDFS.subClassOf}>*",
64
+
"rdf:type/rdfs:subClassOf*",
65
+
),
66
+
(
67
+
RDF.type / RDFS.subClassOf * "*",
68
+
f"(<{RDF.type}>/<{RDFS.subClassOf}>)*",
69
+
"(rdf:type/rdfs:subClassOf)*",
70
+
),
61
71
(
62
72
-(RDF.type | RDFS.subClassOf),
63
73
f"!(<{RDF.type}>|<{RDFS.subClassOf}>)",
64
74
"!(rdf:type|rdfs:subClassOf)",
65
75
),
76
+
(
77
+
-(RDF.type | ((SequencePath(RDFS.subClassOf)) * "*")),
78
+
f"!(<{RDF.type}>|<{RDFS.subClassOf}>*)",
79
+
"!(rdf:type|rdfs:subClassOf*)",
80
+
),
81
+
(
82
+
SequencePath(RDFS.subClassOf),
83
+
f"<{RDFS.subClassOf}>",
84
+
"rdfs:subClassOf",
85
+
),
86
+
(
87
+
AlternativePath(RDFS.subClassOf),
88
+
f"<{RDFS.subClassOf}>",
89
+
"rdfs:subClassOf",
90
+
),
66
91
],
67
92
)
68
93
def test_paths_n3(
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4