ontolutils 0.2.7__tar.gz → 0.2.8__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 (39) hide show
  1. {ontolutils-0.2.7 → ontolutils-0.2.8}/PKG-INFO +1 -1
  2. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/thing.py +93 -89
  3. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/__dev.py +16 -14
  4. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/pivmeta.py +6 -2
  5. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils.egg-info/PKG-INFO +1 -1
  6. {ontolutils-0.2.7 → ontolutils-0.2.8}/setup.cfg +1 -1
  7. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_classes.py +46 -49
  8. {ontolutils-0.2.7 → ontolutils-0.2.8}/LICENSE +0 -0
  9. {ontolutils-0.2.7 → ontolutils-0.2.8}/README.md +0 -0
  10. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/__init__.py +0 -0
  11. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/_version.py +0 -0
  12. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/cache.py +0 -0
  13. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/__init__.py +0 -0
  14. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/decorator.py +0 -0
  15. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/query_util.py +0 -0
  16. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/typing.py +0 -0
  17. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/classes/utils.py +0 -0
  18. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/__init__.py +0 -0
  19. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/_iana_utils.py +0 -0
  20. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/codemeta.py +0 -0
  21. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/m4i.py +0 -0
  22. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/obo.py +0 -0
  23. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/qudt_kind.py +0 -0
  24. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/qudt_unit.py +0 -0
  25. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/schema.py +0 -0
  26. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils/namespacelib/ssno.py +0 -0
  27. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils.egg-info/SOURCES.txt +0 -0
  28. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils.egg-info/dependency_links.txt +0 -0
  29. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils.egg-info/requires.txt +0 -0
  30. {ontolutils-0.2.7 → ontolutils-0.2.8}/ontolutils.egg-info/top_level.txt +0 -0
  31. {ontolutils-0.2.7 → ontolutils-0.2.8}/pyproject.toml +0 -0
  32. {ontolutils-0.2.7 → ontolutils-0.2.8}/setup.py +0 -0
  33. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_decorator.py +0 -0
  34. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_namespaces.py +0 -0
  35. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_query.py +0 -0
  36. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_readme.py +0 -0
  37. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_typing.py +0 -0
  38. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_utils.py +0 -0
  39. {ontolutils-0.2.7 → ontolutils-0.2.8}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ontolutils
3
- Version: 0.2.7
3
+ Version: 0.2.8
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
@@ -25,94 +25,6 @@ class ThingModel(BaseModel, abc.ABC):
25
25
  """Returns the HTML representation of the class"""
26
26
 
27
27
 
28
- def serialize_fields(
29
- obj: Union[ThingModel, int, str, float, bool, datetime],
30
- exclude_none: bool = True
31
- ) -> Union[Dict, int, str, float, bool]:
32
- """Serializes the fields of a Thing object into a json-ld
33
- dictionary (without context!). Note, that IDs can automatically be
34
- generated (with a local prefix)
35
-
36
- Parameter
37
- ---------
38
- obj: Union[ThingModel, int, str, float, bool, datetime]
39
- The object to serialize (a subclass of ThingModel). All other types will
40
- be returned as is. One exception is datetime, which will be serialized
41
- to an ISO string.
42
- exclude_none: bool=True
43
- If True, fields with None values will be excluded from the
44
- serialization
45
-
46
- Returns
47
- -------
48
- Union[Dict, int, str, float, bool]
49
- The serialized fields or the object as is
50
- """
51
- if isinstance(obj, (int, str, float, bool)):
52
- return obj
53
- if isinstance(obj, datetime):
54
- return obj.isoformat()
55
-
56
- uri_ref_manager = URIRefManager.get(obj.__class__, None)
57
- if uri_ref_manager is None:
58
- return obj
59
-
60
- try:
61
- if exclude_none:
62
- serialized_fields = {}
63
- for k in obj.model_fields:
64
- value = getattr(obj, k)
65
- if value is not None and k not in ('id', '@id'):
66
- iri = uri_ref_manager[k]
67
- if _is_http_url(iri):
68
- serialized_fields[k] = value
69
- else:
70
- serialized_fields[iri] = value
71
- else:
72
- serialized_fields = {}
73
- for k in obj.model_fields:
74
- value = getattr(obj, k)
75
- if value not in ('id', '@id'):
76
- iri = uri_ref_manager[k]
77
- if _is_http_url(iri):
78
- serialized_fields[k] = value
79
- else:
80
- serialized_fields[iri] = value
81
- except AttributeError as e:
82
- raise AttributeError(f"Could not serialize {obj} ({obj.__class__}). Orig. err: {e}") from e
83
-
84
- if obj.model_config['extra'] == 'allow':
85
- for k, v in obj.model_extra.items():
86
- iri = uri_ref_manager.get(k, k)
87
- if _is_http_url(iri):
88
- serialized_fields[k] = v
89
- else:
90
- serialized_fields[iri] = v
91
-
92
- # datetime
93
- for k, v in serialized_fields.copy().items():
94
- _field = serialized_fields.pop(k)
95
- key = k
96
- if isinstance(v, datetime):
97
- serialized_fields[key] = serialize_fields(v)
98
- elif isinstance(v, Thing):
99
- serialized_fields[key] = serialize_fields(v, exclude_none=exclude_none)
100
- elif isinstance(v, list):
101
- serialized_fields[key] = [serialize_fields(i, exclude_none=exclude_none) for i in v]
102
- else:
103
- serialized_fields[key] = str(v)
104
-
105
- _type = URIRefManager[obj.__class__].get(obj.__class__.__name__, obj.__class__.__name__)
106
-
107
- out = {"@type": _type, **serialized_fields}
108
- # if no ID is given, generate a local one:
109
- if obj.id is not None:
110
- out["@id"] = obj.id
111
- else:
112
- out["@id"] = rdflib.BNode()
113
- return out
114
-
115
-
116
28
  @namespaces(owl='http://www.w3.org/2002/07/owl#',
117
29
  rdfs='http://www.w3.org/2000/01/rdf-schema#')
118
30
  @urirefs(Thing='owl:Thing', label='rdfs:label')
@@ -166,9 +78,101 @@ class Thing(ThingModel):
166
78
 
167
79
  logger.debug(f'The context is "{at_context}".')
168
80
 
81
+ def serialize_fields(
82
+ obj: Union[ThingModel, int, str, float, bool, datetime],
83
+ exclude_none: bool = True
84
+ ) -> Union[Dict, int, str, float, bool]:
85
+ """Serializes the fields of a Thing object into a json-ld
86
+ dictionary (without context!). Note, that IDs can automatically be
87
+ generated (with a local prefix)
88
+
89
+ Parameter
90
+ ---------
91
+ obj: Union[ThingModel, int, str, float, bool, datetime]
92
+ The object to serialize (a subclass of ThingModel). All other types will
93
+ be returned as is. One exception is datetime, which will be serialized
94
+ to an ISO string.
95
+ exclude_none: bool=True
96
+ If True, fields with None values will be excluded from the
97
+ serialization
98
+
99
+ Returns
100
+ -------
101
+ Union[Dict, int, str, float, bool]
102
+ The serialized fields or the object as is
103
+ """
104
+ if isinstance(obj, (int, str, float, bool)):
105
+ return obj
106
+ if isinstance(obj, datetime):
107
+ return obj.isoformat()
108
+
109
+ uri_ref_manager = URIRefManager.get(obj.__class__, None)
110
+ at_context.update(NamespaceManager.get(obj.__class__, {}))
111
+ if uri_ref_manager is None:
112
+ return obj
113
+
114
+ try:
115
+ if exclude_none:
116
+ serialized_fields = {}
117
+ for k in obj.model_dump(exclude_none=True):
118
+ value = getattr(obj, k)
119
+ if value is not None and k not in ('id', '@id'):
120
+ iri = uri_ref_manager.get(k, k)
121
+ if _is_http_url(iri):
122
+ serialized_fields[iri] = value
123
+ if isinstance(value, str): # this turn URLs into base strings
124
+ serialized_fields[iri] = str(value)
125
+ else:
126
+ serialized_fields[iri] = value
127
+ else:
128
+ serialized_fields = {}
129
+ for k in obj.model_dump(exclude_none=True):
130
+ value = getattr(obj, k)
131
+ if value not in ('id', '@id'):
132
+ iri = uri_ref_manager[k]
133
+ if _is_http_url(iri):
134
+ serialized_fields[k] = value
135
+ else:
136
+ serialized_fields[iri] = value
137
+ except AttributeError as e:
138
+ raise AttributeError(f"Could not serialize {obj} ({obj.__class__}). Orig. err: {e}") from e
139
+
140
+ if obj.model_config['extra'] == 'allow':
141
+ for k, v in obj.model_extra.items():
142
+ iri = uri_ref_manager.get(k, k)
143
+ if _is_http_url(iri):
144
+ serialized_fields[k] = v
145
+ else:
146
+ serialized_fields[iri] = v
147
+
148
+ # datetime
149
+ for k, v in serialized_fields.copy().items():
150
+ _field = serialized_fields.pop(k)
151
+ key = k
152
+ if isinstance(v, datetime):
153
+ serialized_fields[key] = serialize_fields(v)
154
+ elif isinstance(v, Thing):
155
+ serialized_fields[key] = serialize_fields(v, exclude_none=exclude_none)
156
+ elif isinstance(v, list):
157
+ serialized_fields[key] = [serialize_fields(i, exclude_none=exclude_none) for i in v]
158
+ else:
159
+ serialized_fields[key] = str(v)
160
+
161
+ _type = URIRefManager[obj.__class__].get(obj.__class__.__name__, obj.__class__.__name__)
162
+
163
+ out = {"@type": _type, **serialized_fields}
164
+ # if no ID is given, generate a local one:
165
+ if obj.id is not None:
166
+ out["@id"] = obj.id
167
+ else:
168
+ out["@id"] = rdflib.BNode()
169
+ return out
170
+
171
+ serialization = serialize_fields(self, exclude_none=exclude_none)
172
+
169
173
  jsonld = {
170
174
  "@context": at_context,
171
- **serialize_fields(self, exclude_none=exclude_none)
175
+ **serialization
172
176
  }
173
177
  return jsonld
174
178
 
@@ -300,29 +300,31 @@ def build_namespace_files():
300
300
  # f.write('from ._version import __version__\n')
301
301
 
302
302
  with open(__package_dir__ / '__init__.py', 'a') as f:
303
- m4i()
304
- f.write('from .m4i import M4I\n')
303
+ if False:
304
+ m4i()
305
+ f.write('from .m4i import M4I\n')
305
306
 
306
- obo()
307
- f.write('from .obo import OBO\n')
307
+ obo()
308
+ f.write('from .obo import OBO\n')
308
309
 
309
- qudt_unit()
310
- f.write('from .qudt_unit import QUDT_UNIT\n')
310
+ qudt_unit()
311
+ f.write('from .qudt_unit import QUDT_UNIT\n')
311
312
 
312
- qudt_quantitykind()
313
- f.write('from .qudt_kind import QUDT_KIND\n')
313
+ qudt_quantitykind()
314
+ f.write('from .qudt_kind import QUDT_KIND\n')
314
315
 
315
316
  pivmeta()
316
317
  f.write('from .pivmeta import PIVMETA\n')
317
318
 
318
- codemeta()
319
- f.write('from .codemeta import CODEMETA\n')
319
+ if False:
320
+ codemeta()
321
+ f.write('from .codemeta import CODEMETA\n')
320
322
 
321
- schema()
322
- f.write('from .schema import SCHEMA\n')
323
+ schema()
324
+ f.write('from .schema import SCHEMA\n')
323
325
 
324
- ssno()
325
- f.write('from .ssno import SSNO\n')
326
+ ssno()
327
+ f.write('from .ssno import SSNO\n')
326
328
 
327
329
  for jld in __package_dir__.glob('*.jsonld'):
328
330
  jld.unlink()
@@ -7,8 +7,8 @@ class LanguageExtension:
7
7
 
8
8
  class PIVMETA(DefinedNamespace):
9
9
  # uri = "https://w3id.org/nfdi4ing/metadata4ing#"
10
- # Generated with None version 0.2.0a3
11
- # Date: 2024-03-09 20:30:58.080699
10
+ # Generated with None version 0.2.8
11
+ # Date: 2024-03-21 14:56:33.894991
12
12
  _fail = True
13
13
  time: URIRef # ['time']
14
14
  BackgroundImageGeneration: URIRef # ['background image generation']
@@ -44,10 +44,12 @@ class PIVMETA(DefinedNamespace):
44
44
  fnumber: URIRef # ['fnumber']
45
45
  numberOfRecords: URIRef # ['number of records']
46
46
  ExperimentalImage: URIRef # ['experimental image']
47
+ GaussWindowWeightingFunction: URIRef # ['gauss']
47
48
  Interpolation: URIRef # ['interpolation']
48
49
  LeftRightFlip: URIRef # ['left right flip']
49
50
  ReEvaluateWithLargerSample: URIRef # ['re-evaluate with larger sample']
50
51
  SplitImage: URIRef # ['split image']
52
+ SquareWindowWeightingFunction: URIRef # ['square']
51
53
  SyntheticImage: URIRef # ['synthetic image']
52
54
  TopBottomFlip: URIRef # ['top bottom flip']
53
55
  TryLowerOrderPeaks: URIRef # ['try lower order peaks']
@@ -141,10 +143,12 @@ setattr(PIVMETA, "filename_pattern", PIVMETA.filenamePattern)
141
143
  setattr(PIVMETA, "fnumber", PIVMETA.fnumber)
142
144
  setattr(PIVMETA, "number_of_records", PIVMETA.numberOfRecords)
143
145
  setattr(PIVMETA, "experimental_image", PIVMETA.ExperimentalImage)
146
+ setattr(PIVMETA, "gauss", PIVMETA.GaussWindowWeightingFunction)
144
147
  setattr(PIVMETA, "interpolation", PIVMETA.Interpolation)
145
148
  setattr(PIVMETA, "left_right_flip", PIVMETA.LeftRightFlip)
146
149
  setattr(PIVMETA, "re-evaluate_with_larger_sample", PIVMETA.ReEvaluateWithLargerSample)
147
150
  setattr(PIVMETA, "split_image", PIVMETA.SplitImage)
151
+ setattr(PIVMETA, "square", PIVMETA.SquareWindowWeightingFunction)
148
152
  setattr(PIVMETA, "synthetic_image", PIVMETA.SyntheticImage)
149
153
  setattr(PIVMETA, "top_bottom_flip", PIVMETA.TopBottomFlip)
150
154
  setattr(PIVMETA, "try_lower_order_peaks", PIVMETA.TryLowerOrderPeaks)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ontolutils
3
- Version: 0.2.7
3
+ Version: 0.2.8
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.2.7
3
+ version = 0.2.8
4
4
  author = Matthias Probst
5
5
  author_email = matthias.probst@kit.edu
6
6
  description = Utility library for the work with ontologies.
@@ -1,11 +1,8 @@
1
- import datetime
2
1
  import json
3
2
  import logging
4
3
  import pydantic
5
4
  import unittest
6
5
  from pydantic import EmailStr
7
- from rdflib import FOAF
8
- from typing import List
9
6
 
10
7
  from ontolutils import Thing, urirefs, namespaces
11
8
  from ontolutils import set_logging_level
@@ -38,48 +35,48 @@ class TestNamespaces(unittest.TestCase):
38
35
  thing2 = Thing(label='Thing 2', id='http://example.com/thing2')
39
36
  self.assertTrue(thing1 < thing2)
40
37
 
41
- def test_serialize_fields(self):
42
- from ontolutils.classes.thing import serialize_fields
43
- self.assertEqual(serialize_fields(1), 1)
44
- self.assertEqual(serialize_fields(1.1), 1.1)
45
- self.assertEqual(serialize_fields('1'), '1')
46
- self.assertEqual(serialize_fields(True), True)
47
- thing = Thing(label='Thing 1')
48
-
49
- class RandomClass:
50
- """Random Class"""
51
-
52
- rc = RandomClass()
53
- self.assertEqual(serialize_fields(rc), rc)
54
-
55
- self.assertDictEqual(serialize_fields(Thing(id='_:b1', label='Thing 1')),
56
- {'@type': 'owl:Thing', 'rdfs:label': 'Thing 1', '@id': '_:b1'})
57
-
58
- @namespaces(owl='http://www.w3.org/2002/07/owl#',
59
- local='http://example.org/')
60
- @urirefs(Process='local:Process',
61
- startTime='local:startTime',
62
- listOfTimes='local:listOfTimes')
63
- class Process(Thing):
64
- """Process Thing"""
65
- startTime: datetime.datetime = None
66
- listOfTimes: List[datetime.datetime] = None
67
-
68
- process = Process(id='_:b1', label='Process 1',
69
- startTime=datetime.datetime(2021, 1, 1))
70
- self.assertEqual(serialize_fields(process),
71
- {'@type': 'local:Process', 'rdfs:label': 'Process 1', 'local:startTime': '2021-01-01T00:00:00',
72
- '@id': '_:b1'})
73
-
74
- process = Process(id='_:b1',
75
- label='Process 1',
76
- listOfTimes=[datetime.datetime(2021, 1, 1),
77
- datetime.datetime(2021, 1, 2)])
78
-
79
- self.assertEqual(serialize_fields(process),
80
- {'@type': 'local:Process', 'rdfs:label': 'Process 1',
81
- 'local:listOfTimes': ['2021-01-01T00:00:00', '2021-01-02T00:00:00'],
82
- '@id': '_:b1'})
38
+ # def test_serialize_fields(self):
39
+ # from ontolutils.classes.thing import serialize_fields
40
+ # self.assertEqual(serialize_fields(1), 1)
41
+ # self.assertEqual(serialize_fields(1.1), 1.1)
42
+ # self.assertEqual(serialize_fields('1'), '1')
43
+ # self.assertEqual(serialize_fields(True), True)
44
+ # thing = Thing(label='Thing 1')
45
+ #
46
+ # class RandomClass:
47
+ # """Random Class"""
48
+ #
49
+ # rc = RandomClass()
50
+ # self.assertEqual(serialize_fields(rc), rc)
51
+ #
52
+ # self.assertDictEqual(serialize_fields(Thing(id='_:b1', label='Thing 1')),
53
+ # {'@type': 'owl:Thing', 'rdfs:label': 'Thing 1', '@id': '_:b1'})
54
+ #
55
+ # @namespaces(owl='http://www.w3.org/2002/07/owl#',
56
+ # local='http://example.org/')
57
+ # @urirefs(Process='local:Process',
58
+ # startTime='local:startTime',
59
+ # listOfTimes='local:listOfTimes')
60
+ # class Process(Thing):
61
+ # """Process Thing"""
62
+ # startTime: datetime.datetime = None
63
+ # listOfTimes: List[datetime.datetime] = None
64
+ #
65
+ # process = Process(id='_:b1', label='Process 1',
66
+ # startTime=datetime.datetime(2021, 1, 1))
67
+ # self.assertEqual(serialize_fields(process),
68
+ # {'@type': 'local:Process', 'rdfs:label': 'Process 1', 'local:startTime': '2021-01-01T00:00:00',
69
+ # '@id': '_:b1'})
70
+ #
71
+ # process = Process(id='_:b1',
72
+ # label='Process 1',
73
+ # listOfTimes=[datetime.datetime(2021, 1, 1),
74
+ # datetime.datetime(2021, 1, 2)])
75
+ #
76
+ # self.assertEqual(serialize_fields(process),
77
+ # {'@type': 'local:Process', 'rdfs:label': 'Process 1',
78
+ # 'local:listOfTimes': ['2021-01-01T00:00:00', '2021-01-02T00:00:00'],
79
+ # '@id': '_:b1'})
83
80
 
84
81
  def test__repr_html_(self):
85
82
  thing = Thing(label='Thing 1')
@@ -227,7 +224,8 @@ class TestNamespaces(unittest.TestCase):
227
224
  foaf="http://xmlns.com/foaf/0.1/")
228
225
  @urirefs(Person='prov:Person',
229
226
  firstName='foaf:firstName',
230
- lastName=FOAF.lastName,
227
+ # lastName=FOAF.lastName,
228
+ lastName='foaf:lastName',
231
229
  mbox='foaf:mbox')
232
230
  class Person(Thing):
233
231
  firstName: str
@@ -239,14 +237,13 @@ class TestNamespaces(unittest.TestCase):
239
237
  "@context": {
240
238
  "owl": "http://www.w3.org/2002/07/owl#",
241
239
  "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
242
- "lastName": "http://xmlns.com/foaf/0.1/",
240
+ "foaf": "http://xmlns.com/foaf/0.1/",
243
241
  "prov": "http://www.w3.org/ns/prov#",
244
- "foaf": "http://xmlns.com/foaf/0.1/"
245
242
  },
246
243
  "@id": "local:cde4c79c-21f2-4ab7-b01d-28de6e4aade4",
247
244
  "@type": "prov:Person",
248
245
  "foaf:firstName": "John",
249
- "lastName": "Doe"
246
+ "foaf:lastName": "Doe"
250
247
  }
251
248
  print(p.model_dump_jsonld())
252
249
 
File without changes
File without changes
File without changes
File without changes