Skip to content

Commit 6ed7029

Browse files
author
openMINDS pipeline
committed
build triggered by submodule version
1 parent d3228bb commit 6ed7029

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

openminds/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from collections import defaultdict
1212
import json
1313
from typing import Union
14+
15+
import rfc3987
16+
1417
from .registry import Registry
1518

1619

@@ -228,7 +231,7 @@ def __init__(self, value: Union[str, IRI]):
228231
iri = value.value
229232
else:
230233
iri = value
231-
if not iri.startswith("http"):
234+
if not rfc3987.match(iri, rule="IRI"):
232235
raise ValueError("Invalid IRI")
233236
self.value: str = iri
234237

@@ -243,3 +246,11 @@ def __str__(self):
243246

244247
def to_jsonld(self):
245248
return self.value
249+
250+
def validate(self, ignore=None):
251+
if ignore is None:
252+
ignore = []
253+
failures = defaultdict(list)
254+
if self.value.startswith("file") and "value" not in ignore:
255+
failures["value"].append("IRI points to a local file path")
256+
return failures

openminds/properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def validate(self, value, ignore=None):
119119
f"{self.name}: Expected {', '.join(t.__name__ for t in self.types)}, "
120120
f"value contains {type(item)}"
121121
)
122-
elif isinstance(item, Node):
122+
elif isinstance(item, (Node, IRI)):
123123
failures.update(item.validate(ignore=ignore))
124124
if self.min_items:
125125
if len(value) < self.min_items and "multiplicity" not in ignore:
@@ -151,7 +151,7 @@ def validate(self, value, ignore=None):
151151
f"{self.name}: Expected {', '.join(t.__name__ for t in self.types)}, "
152152
f"value is {type(value)}"
153153
)
154-
elif isinstance(value, Node):
154+
elif isinstance(value, (Node, IRI)):
155155
failures.update(value.validate(ignore=ignore))
156156
# todo: check formatting, multiline
157157
return failures

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ classifiers = [
1919
"Programming Language :: Python :: 3"
2020
]
2121
keywords = ["openMINDS", "Open Metadata Initiative", "metadata"]
22-
dependencies=[]
22+
dependencies=[
23+
"rfc3987"
24+
]
2325

2426
[project.optional-dependencies]
2527

0 commit comments

Comments
 (0)