oldaplib 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl

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.
@@ -72,7 +72,7 @@ class ResourceInstance:
72
72
  :type changeset: dict[Iri, AttributeChange]
73
73
  """
74
74
  _iri: Iri
75
- _values: dict[Iri, LangString | ObservableSet]
75
+ _values: dict[Xsd_QName, LangString | ObservableSet]
76
76
  _graph: Xsd_NCName
77
77
  _changeset: dict[Iri, AttributeChange]
78
78
 
@@ -104,7 +104,7 @@ class ResourceInstance:
104
104
  self._superclass_objs = {}
105
105
  self._changeset = {}
106
106
 
107
- def set_values(propclass: dict[Iri, HasProperty]):
107
+ def set_values(propclass: dict[Xsd_QName, HasProperty]):
108
108
  for prop_iri, hasprop in propclass.items():
109
109
  if kwargs.get(str(prop_iri)) or kwargs.get(prop_iri.fragment):
110
110
  value = kwargs[str(prop_iri)] if kwargs.get(str(prop_iri)) else kwargs[prop_iri.fragment]
@@ -143,20 +143,20 @@ class ResourceInstance:
143
143
  else:
144
144
  self.validate_value(self._values[prop_iri], hasprop.prop)
145
145
 
146
- def process_superclasses(superclass: dict[Iri, ResourceClass]):
146
+ def process_superclasses(superclass: dict[Xsd_QName, ResourceClass]):
147
147
  for sc_iri, sc in superclass.items():
148
148
  if sc.superclass:
149
149
  process_superclasses(sc.superclass)
150
- if sc.owl_class_iri == Iri("oldap:Thing", validate=False):
150
+ if sc.owl_class_iri == Xsd_QName("oldap:Thing", validate=False):
151
151
  timestamp = Xsd_dateTimeStamp()
152
- if not self._values.get(Iri('oldap:createdBy', validate=False)):
153
- self._values[Iri('oldap:createdBy', validate=False)] = ObservableSet({self._con.userIri})
154
- if not self._values.get(Iri('oldap:creationDate', validate=False)):
155
- self._values[Iri('oldap:creationDate', validate=False)] = ObservableSet({timestamp})
156
- if not self._values.get(Iri('oldap:lastModifiedBy', validate=False)):
157
- self._values[Iri('oldap:lastModifiedBy', validate=False)] = ObservableSet({self._con.userIri})
158
- if not self._values.get(Iri('oldap:lastModificationDate', validate=False)):
159
- self._values[Iri('oldap:lastModificationDate', validate=False)] = ObservableSet({timestamp})
152
+ if not self._values.get(Xsd_QName('oldap:createdBy', validate=False)):
153
+ self._values[Xsd_QName('oldap:createdBy', validate=False)] = ObservableSet({self._con.userIri})
154
+ if not self._values.get(Xsd_QName('oldap:creationDate', validate=False)):
155
+ self._values[Xsd_QName('oldap:creationDate', validate=False)] = ObservableSet({timestamp})
156
+ if not self._values.get(Xsd_QName('oldap:lastModifiedBy', validate=False)):
157
+ self._values[Xsd_QName('oldap:lastModifiedBy', validate=False)] = ObservableSet({self._con.userIri})
158
+ if not self._values.get(Xsd_QName('oldap:lastModificationDate', validate=False)):
159
+ self._values[Xsd_QName('oldap:lastModificationDate', validate=False)] = ObservableSet({timestamp})
160
160
  set_values(sc.properties)
161
161
  for iri, prop in sc.properties.items():
162
162
  self.properties[iri] = prop
@@ -289,7 +289,7 @@ class ResourceInstance:
289
289
  raise OldapErrorInconsistency(
290
290
  f'Property {property} with LESS_THAN={property[PropClassAttr.LESS_THAN_OR_EQUALS]} has invalid value: "{max_value}" NOT LESS_THAN "{min_other_value}".')
291
291
 
292
- def notifier(self, prop_iri: Iri):
292
+ def notifier(self, prop_iri: Xsd_QName):
293
293
  hasprop = self.properties[prop_iri]
294
294
  self.validate_value(self._values[prop_iri], hasprop)
295
295
 
@@ -329,14 +329,14 @@ class ResourceInstance:
329
329
  return False, f'Actor does not have {permission} in project "{self.project.projectShortName}".'
330
330
 
331
331
  def __get_value(self: Self, prefix: str, fragment: str) -> Xsd | ValueType | None:
332
- attr = Iri(Xsd_QName(prefix, fragment, validate=False), validate=False)
332
+ attr = Xsd_QName(prefix, fragment, validate=False)
333
333
  tmp = self._values.get(attr, None)
334
334
  if tmp is not None and str(attr) in {'oldap:createdBy', 'oldap:creationDate', 'oldap:lastModifiedBy', 'oldap:lastModificationDate'}:
335
335
  return next(iter(tmp))
336
336
  return tmp
337
337
 
338
338
  def __set_value(self: Self, value: ValueType | Xsd | None, prefix: str, fragment: str) -> None:
339
- prop_iri = Iri(Xsd_QName(prefix, fragment, validate=False), validate=False)
339
+ prop_iri = Xsd_QName(prefix, fragment, validate=False)
340
340
  hasprop = self.properties.get(prop_iri)
341
341
 
342
342
  #
@@ -388,7 +388,7 @@ class ResourceInstance:
388
388
  self._values[prop_iri] = convert2datatype(value, hasprop.prop.datatype)
389
389
 
390
390
  def __del_value(self: Self, prefix: str, fragment: str) -> None:
391
- prop_iri = Iri(Xsd_QName(prefix, fragment, validate=False), validate=False)
391
+ prop_iri = Xsd_QName(prefix, fragment, validate=False)
392
392
  hasprop = self.properties.get(prop_iri)
393
393
 
394
394
  if hasprop.get(HasPropertyAttr.MIN_COUNT): # testing for MIN_COUNT conformance
@@ -396,7 +396,7 @@ class ResourceInstance:
396
396
  raise OldapErrorValue(f'{self.name}: Property {prop_iri} with MIN_COUNT={hasprop[HasPropertyAttr.MIN_COUNT]} cannot be deleted.')
397
397
 
398
398
  self._changeset[prop_iri] = AttributeChange(self._values.get(prop_iri), Action.DELETE)
399
- attr = Iri(Xsd_QName(prefix, fragment, validate=False), validate=False)
399
+ attr = Xsd_QName(prefix, fragment, validate=False)
400
400
  del self._values[attr]
401
401
 
402
402
  @property
@@ -404,7 +404,7 @@ class ResourceInstance:
404
404
  return self._iri
405
405
 
406
406
  @property
407
- def changeset(self) -> dict[Iri, AttributeChange]:
407
+ def changeset(self) -> dict[Xsd_QName, AttributeChange]:
408
408
  return self._changeset
409
409
 
410
410
  def clear_changeset(self) -> None:
@@ -451,10 +451,10 @@ class ResourceInstance:
451
451
 
452
452
  timestamp = Xsd_dateTimeStamp()
453
453
  if self.name == "Thing":
454
- self._values[Iri('oldap:createdBy', validate=False)] = ObservableSet({self._con.userIri})
455
- self._values[Iri('oldap:creationDate', validate=False)] = ObservableSet({timestamp})
456
- self._values[Iri('oldap:lastModifiedBy', validate=False)] = ObservableSet({self._con.userIri})
457
- self._values[Iri('oldap:lastModificationDate', validate=False)] = ObservableSet({timestamp})
454
+ self._values[Xsd_QName('oldap:createdBy', validate=False)] = ObservableSet({self._con.userIri})
455
+ self._values[Xsd_QName('oldap:creationDate', validate=False)] = ObservableSet({timestamp})
456
+ self._values[Xsd_QName('oldap:lastModifiedBy', validate=False)] = ObservableSet({self._con.userIri})
457
+ self._values[Xsd_QName('oldap:lastModificationDate', validate=False)] = ObservableSet({timestamp})
458
458
 
459
459
  indent: int = 0
460
460
  indent_inc: int = 4
oldaplib/src/oldaplist.py CHANGED
@@ -383,7 +383,7 @@ class OldapList(Model):
383
383
  last_nodeiri = None
384
384
  for r in res:
385
385
  nodeiri = r['node']
386
- if last_nodeiri != nodeiri:
386
+ if last_nodeiri is None or last_nodeiri != nodeiri:
387
387
  prefix, id = str(nodeiri).split(':')
388
388
  ln = OldapListNode(con=self._con,
389
389
  **self.info,
@@ -55,7 +55,7 @@ class PermissionSet(Model):
55
55
  :type iri: Iri
56
56
  """
57
57
 
58
- __permset_iri: Iri | None
58
+ __permset_iri: Xsd_QName | None
59
59
  __project: Project | None
60
60
 
61
61
  def __init__(self, *,
@@ -112,7 +112,8 @@ class PermissionSet(Model):
112
112
  # The IRI of the permission set is a QName consisting of the prefix of the project (aka projectShortname)
113
113
  # and the permissionSetId. Thus, the same permission set ID could be used in different projects...
114
114
  #
115
- self.__permset_iri = Iri.fromPrefixFragment(self.__project.projectShortName, self._attributes[PermissionSetAttr.PERMISSION_SET_ID], validate=False)
115
+ self.__permset_iri = Xsd_QName(self.__project.projectShortName, self._attributes[PermissionSetAttr.PERMISSION_SET_ID])
116
+ #self.__permset_iri = Iri.fromPrefixFragment(self.__project.projectShortName, self._attributes[PermissionSetAttr.PERMISSION_SET_ID], validate=False)
116
117
 
117
118
  for attr in PermissionSetAttr:
118
119
  setattr(PermissionSet, attr.value.fragment, property(
@@ -182,7 +183,11 @@ class PermissionSet(Model):
182
183
  self._changeset[what] = AttributeChange(None, Action.MODIFY)
183
184
 
184
185
  @property
185
- def iri(self) -> Iri:
186
+ def iri(self) -> Xsd_QName:
187
+ return self.__permset_iri
188
+
189
+ @property
190
+ def qname(self) -> Xsd_QName:
186
191
  return self.__permset_iri
187
192
 
188
193
  def create(self, indent: int = 0, indent_inc: int = 4) -> None:
@@ -274,7 +279,7 @@ class PermissionSet(Model):
274
279
  @classmethod
275
280
  def read(cls, *,
276
281
  con: IConnection,
277
- iri: Iri | str | None = None,
282
+ qname: Xsd_QName | str | None = None,
278
283
  permissionSetId: Xsd_NCName | str | None = None,
279
284
  definedByProject: Project | Iri | Xsd_NCName | str | None = None,
280
285
  ignore_cache: bool = False) -> Self:
@@ -284,7 +289,7 @@ class PermissionSet(Model):
284
289
  an instance of the permission set if found.
285
290
 
286
291
  :param con: The connection object used to interact with the system.
287
- :param iri: The Internationalized Resource Identifier of the permission set. If provided,
292
+ :param qname: The Internationalized Resource Identifier of the permission set. If provided,
288
293
  it will be used to read the permission set.
289
294
  :param permissionSetId: The unique identifier of the permission set within a project.
290
295
  Required if `iri` is not provided.
@@ -302,8 +307,8 @@ class PermissionSet(Model):
302
307
  :raises OldapErrorInconsistency: Raised if the permission set contains inconsistencies
303
308
  in its data during retrieval.
304
309
  """
305
- if iri:
306
- permset_iri = Iri(iri, validate=True)
310
+ if qname:
311
+ permset_iri = Xsd_QName(qname, validate=True)
307
312
  elif permissionSetId and definedByProject:
308
313
  id = Xsd_NCName(permissionSetId, validate=True)
309
314
 
@@ -311,7 +316,7 @@ class PermissionSet(Model):
311
316
  project = definedByProject
312
317
  else:
313
318
  project = Project.read(con, definedByProject)
314
- permset_iri = Iri.fromPrefixFragment(project.projectShortName, permissionSetId, validate=False)
319
+ permset_iri = Xsd_QName(project.projectShortName, permissionSetId)
315
320
  else:
316
321
  raise OldapErrorValue('Either the parameter "iri" of both "permissionSetId" and "definedByProject" must be provided.')
317
322
  if not ignore_cache:
@@ -336,7 +341,7 @@ class PermissionSet(Model):
336
341
  if len(res) == 0:
337
342
  raise OldapErrorNotFound(f'No permission set "{permset_iri}"')
338
343
 
339
- permset_iri: Iri | None = None
344
+ permset_iri: Xsd_QName | None = None
340
345
  creator: Iri | None = None
341
346
  created: Xsd_dateTime | None = None
342
347
  contributor: Iri | None = None
@@ -470,7 +475,7 @@ class PermissionSet(Model):
470
475
  sparql += '}\n'
471
476
  jsonobj = con.query(sparql)
472
477
  res = QueryProcessor(context, jsonobj)
473
- permissionSets: list[Iri] = []
478
+ permissionSets: list[Xsd_QName] = []
474
479
  for r in res:
475
480
  if definedByProject:
476
481
  #context[r['projectShortName']] = r['namespaceIri']
@@ -58,18 +58,18 @@ from oldaplib.src.model import Model
58
58
  from oldaplib.src.helpers.attributechange import AttributeChange
59
59
  from oldaplib.src.xsd.xsd_string import Xsd_string
60
60
 
61
- PropTypes = Iri | OwlPropertyType | XsdDatatypes | LangString | Xsd_string | Xsd_integer | Xsd_boolean | LanguageIn | XsdSet | Numeric | None
61
+ PropTypes = Iri | Xsd_QName | OwlPropertyType | XsdDatatypes | LangString | Xsd_string | Xsd_integer | Xsd_boolean | LanguageIn | XsdSet | Numeric | None
62
62
  PropClassAttrContainer = dict[PropClassAttr, PropTypes]
63
- Attributes = dict[Iri, PropTypes]
63
+ Attributes = dict[Xsd_QName, PropTypes]
64
64
 
65
65
  @dataclass
66
66
  @serializer
67
67
  class HasPropertyData:
68
- refprop: Iri | None = None
68
+ refprop: Xsd_QName | None = None
69
69
  minCount: Xsd_nonNegativeInteger | None = None
70
70
  maxCount: Xsd_nonNegativeInteger | None = None
71
71
  order: Xsd_decimal | None = None
72
- group: Iri | None = None
72
+ group: Xsd_QName | None = None
73
73
 
74
74
  def create_shacl(self, indent: int = 0, indent_inc: int = 4):
75
75
  blank = ''
@@ -161,10 +161,10 @@ class PropertyClass(Model, Notify):
161
161
  _graph: Xsd_NCName
162
162
  _projectShortName: Xsd_NCName
163
163
  _projectIri: Iri
164
- _property_class_iri: Iri | None
164
+ _property_class_iri: Xsd_QName | None
165
165
  _statementProperty: Xsd_boolean
166
166
  _externalOntology: Xsd_boolean
167
- _internal: Iri | None
167
+ _internal: Xsd_QName | None
168
168
  _force_external: bool
169
169
  #_attributes: PropClassAttrContainer
170
170
  _test_in_use: bool
@@ -190,12 +190,12 @@ class PropertyClass(Model, Notify):
190
190
  contributor: Iri | None = None,
191
191
  modified: Xsd_dateTime | datetime | str | None = None,
192
192
  project: Project | Iri | Xsd_NCName | str,
193
- property_class_iri: Iri | str | None = None,
193
+ property_class_iri: Xsd_QName | str | None = None,
194
194
  notifier: Callable[[PropClassAttr], None] | None = None,
195
195
  notify_data: PropClassAttr | None = None,
196
196
  _statementProperty: bool | Xsd_boolean= False,
197
197
  _externalOntology: bool | Xsd_boolean = False,
198
- _internal: Iri | None = None, # DO NOT USE!! Only for serialization!
198
+ _internal: Xsd_QName | None = None, # DO NOT USE!! Only for serialization!
199
199
  _force_external: bool | None = None, # DO NOT USE!! Only for serialization!
200
200
  _from_triplestore: bool = False,
201
201
  validate: bool = False,
@@ -267,7 +267,7 @@ class PropertyClass(Model, Notify):
267
267
  context.use(self._projectShortName)
268
268
  self._graph = self._projectShortName
269
269
 
270
- self._property_class_iri = Iri(property_class_iri, validate=validate) if property_class_iri else None
270
+ self._property_class_iri = Xsd_QName(property_class_iri, validate=validate) if property_class_iri else None
271
271
  datatype = kwargs.get('datatype', None)
272
272
  if datatype and kwargs.get('inSet'):
273
273
  if datatype == XsdDatatypes.langString:
@@ -535,7 +535,7 @@ class PropertyClass(Model, Notify):
535
535
  return self._projectIri
536
536
 
537
537
  @property
538
- def property_class_iri(self) -> Iri:
538
+ def property_class_iri(self) -> Xsd_QName:
539
539
  """
540
540
  Return the Iri identifying the property
541
541
  :return: Iri identifying the property
@@ -553,7 +553,7 @@ class PropertyClass(Model, Notify):
553
553
  return self.__version
554
554
 
555
555
  @property
556
- def internal(self) -> Iri | None:
556
+ def internal(self) -> Xsd_QName | None:
557
557
  """
558
558
  Return the Iri of the ResourceClass, if the property is internal to a ResourceClass.
559
559
  If it is a standalone property, return None
@@ -685,7 +685,7 @@ class PropertyClass(Model, Notify):
685
685
  return False
686
686
 
687
687
  @staticmethod
688
- def process_triple(r: RowType, attributes: Attributes, propiri: Iri | None = None) -> None:
688
+ def process_triple(r: RowType, attributes: Attributes, propiri: Xsd_QName | None = None) -> None:
689
689
  """
690
690
  INTERNAL USE ONLY! Used for processing triple while rreading a property.
691
691
  :param r:
@@ -714,12 +714,11 @@ class PropertyClass(Model, Notify):
714
714
  raise OldapError(f'Invalid value for attribute {attriri}: {err}.')
715
715
  else:
716
716
  if attributes.get(attriri) is not None:
717
- print("===>", r)
718
717
  raise OldapError(f'Property ({propiri}) attribute "{attriri}" already defined (value="{r['value']}", type="{type(r['value']).__name__}").')
719
718
  attributes[attriri] = r['value']
720
719
 
721
720
  @staticmethod
722
- def __query_shacl(con: IConnection, graph: Xsd_NCName, property_class_iri: Iri) -> Attributes:
721
+ def __query_shacl(con: IConnection, graph: Xsd_NCName, property_class_iri: Xsd_QName) -> Attributes:
723
722
  context = Context(name=con.context_name)
724
723
  query = context.sparql_context
725
724
  query += f"""
@@ -751,22 +750,22 @@ class PropertyClass(Model, Notify):
751
750
  #
752
751
  # Create a set of all PropertyClassProp-strings, e.g. {"sh:path", "sh:datatype" etc.}
753
752
  #
754
- refprop: Iri | None = None
753
+ refprop: Xsd_QName | None = None
755
754
  minCount: Xsd_integer | None = None
756
755
  maxCount: Xsd_integer | None = None
757
756
  order: Xsd_decimal | None = None
758
- group: Iri | None = None
759
- propkeys = {Iri(x.value) for x in PropClassAttr}
757
+ group: Xsd_QName | None = None
758
+ propkeys = {Xsd_QName(x.value) for x in PropClassAttr}
760
759
  for key, val in attributes.items():
761
760
  if key == 'rdf:type':
762
761
  if val != 'sh:PropertyShape':
763
762
  raise OldapError(f'Inconsistency, expected "sh:PropertyType", got "{val}".')
764
763
  continue
765
764
  elif key == 'sh:path':
766
- if isinstance(val, Iri):
765
+ if isinstance(val, Xsd_QName):
767
766
  self._property_class_iri = val
768
767
  else:
769
- raise OldapError(f'Inconsistency in SHACL "sh:path" of "{self._property_class_iri}" ->"{val}"')
768
+ raise OldapError(f'Inconsistency in SHACL "sh:path" of "{self._property_class_iri}" ->"{val}" (type={type(val).__name__}).')
770
769
  elif key == 'schema:version':
771
770
  if isinstance(val, Xsd_string):
772
771
  self.__version = SemanticVersion.fromString(str(val))
@@ -804,7 +803,7 @@ class PropertyClass(Model, Notify):
804
803
  raise OldapError(f'Inconsistency in SHACL "oldap:externalOntology (type={type(val)}"')
805
804
  elif key == 'sh:node':
806
805
  if str(val).endswith("Shape"):
807
- refprop = Iri(str(val)[:-5], validate=False)
806
+ refprop = Xsd_QName(str(val)[:-5], validate=False)
808
807
  else:
809
808
  refprop = val
810
809
  elif key == 'sh:minCount':
@@ -816,7 +815,7 @@ class PropertyClass(Model, Notify):
816
815
  elif key == 'sh:group':
817
816
  group = val
818
817
  elif key in propkeys:
819
- attr = PropClassAttr.from_value(key.as_qname)
818
+ attr = PropClassAttr.from_value(key)
820
819
  if attr.datatype == Numeric:
821
820
  if not isinstance(val, (Xsd_integer, Xsd_float)):
822
821
  raise OldapErrorInconsistency(f'SHACL inconsistency: "{attr.value}" expects a "Xsd:integer" or "Xsd:float", but got "{type(val).__name__}".')
@@ -923,7 +922,7 @@ class PropertyClass(Model, Notify):
923
922
  @classmethod
924
923
  def read(cls, con: IConnection,
925
924
  project: Project | Iri | Xsd_NCName | str,
926
- property_class_iri: Iri | str,
925
+ property_class_iri: Xsd_QName | str,
927
926
  ignore_cache: bool = False) -> Self:
928
927
  """
929
928
  Reads a property from the triple store.
@@ -948,8 +947,8 @@ class PropertyClass(Model, Notify):
948
947
  """
949
948
  logger = get_logger()
950
949
 
951
- if not isinstance(property_class_iri, Iri):
952
- property_class_iri = Iri(property_class_iri)
950
+ if not isinstance(property_class_iri, Xsd_QName):
951
+ property_class_iri = Xsd_QName(property_class_iri)
953
952
  cache = CacheSingletonRedis()
954
953
  if not ignore_cache:
955
954
  tmp = cache.get(property_class_iri, connection=con)
@@ -1042,7 +1041,7 @@ class PropertyClass(Model, Notify):
1042
1041
 
1043
1042
  def create_shacl(self, *,
1044
1043
  timestamp: Xsd_dateTime,
1045
- owlclass_iri: Iri | None = None,
1044
+ owlclass_iri: Xsd_QName | None = None,
1046
1045
  haspropdata: HasPropertyData | None = None,
1047
1046
  indent: int = 0, indent_inc: int = 4) -> str:
1048
1047
  blank = ''
@@ -1255,7 +1254,7 @@ class PropertyClass(Model, Notify):
1255
1254
  f.write(f'{blank:{indent * indent_inc}}}}\n')
1256
1255
 
1257
1256
  def update_shacl(self, *,
1258
- owlclass_iri: Iri | None = None,
1257
+ owlclass_iri: Xsd_QName | None = None,
1259
1258
  timestamp: Xsd_dateTime,
1260
1259
  indent: int = 0, indent_inc: int = 4) -> str:
1261
1260
  blank = ''
@@ -1639,7 +1638,7 @@ class PropertyClass(Model, Notify):
1639
1638
  return sparql
1640
1639
 
1641
1640
  def delete_owl_subclass_str(self, *,
1642
- owlclass_iri: Iri,
1641
+ owlclass_iri: Xsd_QName,
1643
1642
  indent: int = 0, indent_inc: int = 4) -> str:
1644
1643
  blank = ''
1645
1644
  sparql = ''