oldaplib 0.3.1__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.
@@ -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 = ''