ontolutils 0.3.0__tar.gz → 0.4.0__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.
Files changed (40) hide show
  1. {ontolutils-0.3.0 → ontolutils-0.4.0}/PKG-INFO +1 -1
  2. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/thing.py +11 -13
  3. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils.egg-info/PKG-INFO +1 -1
  4. {ontolutils-0.3.0 → ontolutils-0.4.0}/setup.cfg +1 -1
  5. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_classes.py +6 -8
  6. {ontolutils-0.3.0 → ontolutils-0.4.0}/LICENSE +0 -0
  7. {ontolutils-0.3.0 → ontolutils-0.4.0}/README.md +0 -0
  8. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/__init__.py +0 -0
  9. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/_version.py +0 -0
  10. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/cache.py +0 -0
  11. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/__init__.py +0 -0
  12. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/decorator.py +0 -0
  13. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/query_util.py +0 -0
  14. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/typing.py +0 -0
  15. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/classes/utils.py +0 -0
  16. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/__dev.py +0 -0
  17. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/__init__.py +0 -0
  18. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/_iana_utils.py +0 -0
  19. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/codemeta.py +0 -0
  20. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/m4i.py +0 -0
  21. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/obo.py +0 -0
  22. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/qudt_kind.py +0 -0
  23. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/qudt_unit.py +0 -0
  24. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/schema.py +0 -0
  25. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/namespacelib/ssno.py +0 -0
  26. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/utils/__init__.py +0 -0
  27. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils/utils/qudt_units.py +0 -0
  28. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils.egg-info/SOURCES.txt +0 -0
  29. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils.egg-info/dependency_links.txt +0 -0
  30. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils.egg-info/requires.txt +0 -0
  31. {ontolutils-0.3.0 → ontolutils-0.4.0}/ontolutils.egg-info/top_level.txt +0 -0
  32. {ontolutils-0.3.0 → ontolutils-0.4.0}/pyproject.toml +0 -0
  33. {ontolutils-0.3.0 → ontolutils-0.4.0}/setup.py +0 -0
  34. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_decorator.py +0 -0
  35. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_namespaces.py +0 -0
  36. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_query.py +0 -0
  37. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_readme.py +0 -0
  38. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_typing.py +0 -0
  39. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_utils.py +0 -0
  40. {ontolutils-0.3.0 → ontolutils-0.4.0}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ontolutils
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Utility library for the work with ontologies.
5
5
  Home-page: https://github.com/matthiasprobst/ontology-utils
6
6
  Author: Matthias Probst
@@ -7,7 +7,7 @@ from datetime import datetime
7
7
  from typing import Dict, Union, Optional
8
8
 
9
9
  import rdflib
10
- from pydantic import HttpUrl, FileUrl, BaseModel, ConfigDict
10
+ from pydantic import HttpUrl, FileUrl, BaseModel, ConfigDict, field_validator, Field
11
11
  from rdflib.plugins.shared.jsonld.context import Context
12
12
 
13
13
  from .decorator import urirefs, namespaces, URIRefManager, NamespaceManager, _is_http_url
@@ -44,7 +44,8 @@ def resolve_iri(key_or_iri: str, context: Context) -> Optional[str]:
44
44
  return 'http://www.w3.org/2000/01/rdf-schema#label'
45
45
  return
46
46
 
47
-
47
+ def build_blank_n3():
48
+ return rdflib.BNode().n3()
48
49
  @namespaces(owl='http://www.w3.org/2002/07/owl#',
49
50
  rdfs='http://www.w3.org/2000/01/rdf-schema#')
50
51
  @urirefs(Thing='owl:Thing', label='rdfs:label')
@@ -94,9 +95,16 @@ class Thing(ThingModel):
94
95
  >>> # For further information visit https://errors.pydantic.dev/2.4/v/string_type
95
96
 
96
97
  """
97
- id: Union[str, HttpUrl, FileUrl, BlankNodeType, None] = None # @id
98
+ id: Optional[Union[str, HttpUrl, FileUrl, BlankNodeType, None]] = Field(default_factory=build_blank_n3) # @id
98
99
  label: str = None # rdfs:label
99
100
 
101
+ @field_validator('id')
102
+ @classmethod
103
+ def _id(cls, id: Optional[Union[str, HttpUrl, FileUrl, BlankNodeType]]) -> str:
104
+ if id is None:
105
+ return rdflib.BNode().n3()
106
+ return str(id)
107
+
100
108
  def __lt__(self, other: ThingModel) -> bool:
101
109
  """Less than comparison. Useful to sort Thing objects.
102
110
  Comparison can only be done with other Thing objects and if an ID is given.
@@ -107,16 +115,6 @@ class Thing(ThingModel):
107
115
  return False
108
116
  return self.id <= other.id
109
117
 
110
- def pop_blank_node_id(self) -> Union[None, str]:
111
- """Remove the ID if it is blank node"""
112
- if self.id is None:
113
- return
114
- if self.id.startswith('http'):
115
- return
116
- _id = self.id
117
- self.id = None
118
- return _id
119
-
120
118
  def get_jsonld_dict(self,
121
119
  context: Optional[Union[Dict, str]] = None,
122
120
  exclude_none: bool = True,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ontolutils
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Utility library for the work with ontologies.
5
5
  Home-page: https://github.com/matthiasprobst/ontology-utils
6
6
  Author: Matthias Probst
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ontolutils
3
- version = 0.3.0
3
+ version = 0.4.0
4
4
  author = Matthias Probst
5
5
  author_email = matthias.probst@kit.edu
6
6
  description = Utility library for the work with ontologies.
@@ -170,9 +170,9 @@ class TestNamespaces(unittest.TestCase):
170
170
  p183_from_jsonld.height
171
171
 
172
172
  def test_sort_classes(self):
173
- thing1 = Thing(label='Thing 1')
174
- thing2 = Thing(label='Thing 2')
175
- self.assertFalse(thing1 < thing2)
173
+ thing1 = Thing(label='Thing 1', id='_:1')
174
+ thing2 = Thing(label='Thing 2', id='_:2')
175
+ self.assertFalse(thing1 > thing2)
176
176
  with self.assertRaises(TypeError):
177
177
  thing1 < 4
178
178
  thing1 = Thing(label='Thing 1', id='http://example.com/thing1')
@@ -181,7 +181,7 @@ class TestNamespaces(unittest.TestCase):
181
181
 
182
182
  def test__repr_html_(self):
183
183
  thing = Thing(label='Thing 1')
184
- self.assertEqual(thing._repr_html_(), 'Thing(label=Thing 1)')
184
+ self.assertEqual(thing._repr_html_(), f'Thing(id={thing.id}, label=Thing 1)')
185
185
 
186
186
  def test_thing_get_jsonld_dict(self):
187
187
  with self.assertRaises(pydantic.ValidationError):
@@ -238,7 +238,7 @@ class TestNamespaces(unittest.TestCase):
238
238
 
239
239
  jsonld_str2 = agent.model_dump_jsonld(rdflib_serialize=True) # will assign blank node! Pop it later
240
240
  jsonld_str2_dict = json.loads(jsonld_str2)
241
- self.assertNotEqual(
241
+ self.assertDictEqual(
242
242
  json.loads(jsonld_str1),
243
243
  jsonld_str2_dict
244
244
  )
@@ -288,7 +288,7 @@ class TestNamespaces(unittest.TestCase):
288
288
  label='Agent 1',
289
289
  mbox='my@email.com'
290
290
  )
291
- self.assertEqual(agent.id, None)
291
+ self.assertNotEqual(agent.id, None)
292
292
  ns = agent.namespaces
293
293
  jsonld_string = agent.model_dump_jsonld(
294
294
  context={
@@ -306,8 +306,6 @@ class TestNamespaces(unittest.TestCase):
306
306
  self.assertEqual(thing.label, 'Agent 1')
307
307
  self.assertTrue(thing.id.startswith('_:'))
308
308
  _id = thing.id
309
- self.assertEqual(thing.pop_blank_node_id(), _id)
310
- self.assertEqual(thing.id, None)
311
309
 
312
310
  def test_schema_http(self):
313
311
  @namespaces(foaf="http://xmlns.com/foaf/0.1/",
File without changes
File without changes
File without changes
File without changes