ontolutils 0.2.9__tar.gz → 0.2.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ontolutils-0.2.9 → ontolutils-0.2.10}/PKG-INFO +1 -1
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/thing.py +6 -3
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils.egg-info/PKG-INFO +1 -1
- {ontolutils-0.2.9 → ontolutils-0.2.10}/setup.cfg +1 -1
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_classes.py +45 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/LICENSE +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/README.md +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/__init__.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/_version.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/cache.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/__init__.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/decorator.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/query_util.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/typing.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/classes/utils.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/__dev.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/__init__.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/_iana_utils.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/codemeta.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/m4i.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/obo.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/pivmeta.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/qudt_kind.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/qudt_unit.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/schema.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils/namespacelib/ssno.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils.egg-info/SOURCES.txt +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils.egg-info/dependency_links.txt +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils.egg-info/requires.txt +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/ontolutils.egg-info/top_level.txt +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/pyproject.toml +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/setup.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_decorator.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_namespaces.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_query.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_readme.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_typing.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_utils.py +0 -0
- {ontolutils-0.2.9 → ontolutils-0.2.10}/tests/test_version.py +0 -0
|
@@ -3,6 +3,7 @@ import json
|
|
|
3
3
|
import logging
|
|
4
4
|
import pathlib
|
|
5
5
|
import rdflib
|
|
6
|
+
import warnings
|
|
6
7
|
from datetime import datetime
|
|
7
8
|
from pydantic import HttpUrl, FileUrl, BaseModel, ConfigDict
|
|
8
9
|
from typing import Dict, Union, Optional
|
|
@@ -162,7 +163,7 @@ class Thing(ThingModel):
|
|
|
162
163
|
logger.debug('Initializing RDF graph to dump the Thing to JSON-LD')
|
|
163
164
|
|
|
164
165
|
# lets auto-generate the context
|
|
165
|
-
at_context: Dict = NamespaceManager.get(self.__class__, {})
|
|
166
|
+
at_context: Dict = NamespaceManager.get(self.__class__, {}).copy()
|
|
166
167
|
|
|
167
168
|
if context is None:
|
|
168
169
|
context = {}
|
|
@@ -204,6 +205,7 @@ class Thing(ThingModel):
|
|
|
204
205
|
|
|
205
206
|
uri_ref_manager = URIRefManager.get(obj.__class__, None)
|
|
206
207
|
at_context.update(NamespaceManager.get(obj.__class__, {}))
|
|
208
|
+
|
|
207
209
|
if uri_ref_manager is None:
|
|
208
210
|
return obj
|
|
209
211
|
|
|
@@ -381,8 +383,9 @@ class Thing(ThingModel):
|
|
|
381
383
|
from . import query
|
|
382
384
|
if data is not None and isinstance(data, str):
|
|
383
385
|
if 'http://schema.org/' in data:
|
|
384
|
-
|
|
385
|
-
|
|
386
|
+
warnings.warn('Replacing http with https in the JSON-LD data. '
|
|
387
|
+
'This is a workaround for the schema.org inconsistency.',
|
|
388
|
+
UserWarning)
|
|
386
389
|
data = data.replace('http://schema.org/', 'https://schema.org/')
|
|
387
390
|
return query(cls, source=source, data=data, limit=limit, context=context)
|
|
388
391
|
|
|
@@ -178,6 +178,51 @@ class TestNamespaces(unittest.TestCase):
|
|
|
178
178
|
'https://git.rwth-aachen.de/nfdi4ing/metadata4ing/metadata4ing/-/raw/master/m4i_context.jsonld'
|
|
179
179
|
)
|
|
180
180
|
|
|
181
|
+
def test_model_dump_jsonld_and_load_with_import(self):
|
|
182
|
+
@namespaces(foaf="http://xmlns.com/foaf/0.1/")
|
|
183
|
+
@urirefs(Agent='foaf:Agent',
|
|
184
|
+
mbox='foaf:mbox')
|
|
185
|
+
class Agent(Thing):
|
|
186
|
+
"""Pydantic Model for http://xmlns.com/foaf/0.1/Agent
|
|
187
|
+
Parameters
|
|
188
|
+
----------
|
|
189
|
+
mbox: EmailStr = None
|
|
190
|
+
Email address (foaf:mbox)
|
|
191
|
+
"""
|
|
192
|
+
mbox: EmailStr = None
|
|
193
|
+
|
|
194
|
+
agent = Agent(
|
|
195
|
+
label='Agent 1',
|
|
196
|
+
mbox='my@email.com'
|
|
197
|
+
)
|
|
198
|
+
ns = agent.namespaces
|
|
199
|
+
jsonld_string = agent.model_dump_jsonld(
|
|
200
|
+
context={
|
|
201
|
+
"@import": 'https://raw.githubusercontent.com/matthiasprobst/pivmeta/main/pivmeta_context.jsonld'
|
|
202
|
+
}
|
|
203
|
+
)
|
|
204
|
+
self.assertDictEqual(agent.namespaces, ns)
|
|
205
|
+
self.assertTrue('@import' in json.loads(jsonld_string)['@context'])
|
|
206
|
+
loaded_agent = Agent.from_jsonld(data=jsonld_string, limit=1)
|
|
207
|
+
self.assertDictEqual(loaded_agent.namespaces, ns)
|
|
208
|
+
self.assertEqual(loaded_agent.mbox, agent.mbox)
|
|
209
|
+
|
|
210
|
+
def test_schema_http(self):
|
|
211
|
+
@namespaces(foaf="http://xmlns.com/foaf/0.1/",
|
|
212
|
+
schema="https://schema.org/")
|
|
213
|
+
@urirefs(Agent='foaf:Agent',
|
|
214
|
+
name='schema:name')
|
|
215
|
+
class Agent(Thing):
|
|
216
|
+
name: str
|
|
217
|
+
|
|
218
|
+
agent = Agent(name='John Doe')
|
|
219
|
+
self.assertEqual(agent.name, 'John Doe')
|
|
220
|
+
agent_jsonld = agent.model_dump_jsonld()
|
|
221
|
+
print(agent_jsonld.replace('https://schema', 'http://schema'))
|
|
222
|
+
with self.assertWarns(UserWarning):
|
|
223
|
+
agent.from_jsonld(data=agent_jsonld.replace('https://schema', 'http://schema'),
|
|
224
|
+
limit=1)
|
|
225
|
+
|
|
181
226
|
def test_model_dump_jsonld_nested(self):
|
|
182
227
|
@namespaces(foaf="http://xmlns.com/foaf/0.1/")
|
|
183
228
|
@urirefs(Agent='foaf:Agent',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|