naas-abi-core 1.5.0__py3-none-any.whl → 1.6.0__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.
@@ -70,6 +70,7 @@ class BaseModule(Generic[TConfig]):
70
70
  "configuration must be an instance of ModuleConfiguration"
71
71
  )
72
72
  logger.debug(f"Initializing module {self.__module__.split('.')[0]}")
73
+ self.module_path = self.__module__.split(".")[0]
73
74
  self._engine = engine
74
75
  self._configuration = configuration
75
76
 
@@ -349,6 +349,7 @@ def generate_python_code(classes: Dict[str, ClassInfo],
349
349
  " \"\"\"Base class for all RDF entities with URI and namespace management\"\"\"",
350
350
  " _namespace: ClassVar[str] = \"http://example.org/instance/\"",
351
351
  " _uri: str = \"\"",
352
+ " _object_properties: ClassVar[set[str]] = set()",
352
353
  " ",
353
354
  " model_config = {",
354
355
  " 'arbitrary_types_allowed': True,",
@@ -381,9 +382,12 @@ def generate_python_code(classes: Dict[str, ClassInfo],
381
382
  " if hasattr(self, '_class_uri'):",
382
383
  " g.add((subject, RDF.type, URIRef(self._class_uri)))",
383
384
  " ",
385
+ " object_props = getattr(self, '_object_properties', set())",
386
+ " ",
384
387
  " # Add properties",
385
388
  " if hasattr(self, '_property_uris'):",
386
389
  " for prop_name, prop_uri in self._property_uris.items():",
390
+ " is_object_prop = prop_name in object_props",
387
391
  " prop_value = getattr(self, prop_name, None)",
388
392
  " if prop_value is not None:",
389
393
  " if isinstance(prop_value, list):",
@@ -392,12 +396,16 @@ def generate_python_code(classes: Dict[str, ClassInfo],
392
396
  " # Add triples from related object",
393
397
  " g += item.rdf()",
394
398
  " g.add((subject, URIRef(prop_uri), URIRef(item._uri)))",
399
+ " elif is_object_prop and isinstance(item, (str, URIRef)):",
400
+ " g.add((subject, URIRef(prop_uri), URIRef(str(item))))",
395
401
  " else:",
396
402
  " g.add((subject, URIRef(prop_uri), Literal(item)))",
397
403
  " elif hasattr(prop_value, 'rdf'):",
398
404
  " # Add triples from related object",
399
405
  " g += prop_value.rdf()",
400
406
  " g.add((subject, URIRef(prop_uri), URIRef(prop_value._uri)))",
407
+ " elif is_object_prop and isinstance(prop_value, (str, URIRef)):",
408
+ " g.add((subject, URIRef(prop_uri), URIRef(str(prop_value))))",
401
409
  " else:",
402
410
  " g.add((subject, URIRef(prop_uri), Literal(prop_value)))",
403
411
  " ",
@@ -541,8 +549,16 @@ def generate_class_code(class_info: ClassInfo) -> List[str]:
541
549
  else:
542
550
  lines.append(" _property_uris: ClassVar[dict] = {}")
543
551
 
544
- if class_info.property_uris:
545
- lines.append("")
552
+ object_prop_names = sorted(
553
+ {prop.name for prop in properties_list if prop.property_type == "object"}
554
+ )
555
+ if object_prop_names:
556
+ names = ", ".join(f"'{name}'" for name in object_prop_names)
557
+ lines.append(f" _object_properties: ClassVar[set[str]] = {{{names}}}")
558
+ else:
559
+ lines.append(" _object_properties: ClassVar[set[str]] = set()")
560
+
561
+ lines.append("")
546
562
 
547
563
  # Add properties grouped by type for readability
548
564
  data_properties = sorted(
@@ -592,10 +608,11 @@ def generate_property_code(prop: PropertyInfo) -> str:
592
608
  # Determine type annotation and Pydantic Field
593
609
  if prop.property_type == 'object' and prop.range_class:
594
610
  if prop.cardinality == 'multiple':
595
- type_annotation = f"List[{prop.range_class}]"
611
+ type_annotation = f"List[Union[str, {prop.range_class}]]"
596
612
  default_value = "Field(default_factory=list)"
597
613
  else:
598
- type_annotation = f"Optional[{prop.range_class}]" if not prop.required else prop.range_class
614
+ inner = f"Union[str, {prop.range_class}]"
615
+ type_annotation = f"Optional[{inner}]" if not prop.required else inner
599
616
  default_value = "Field(default=None)" if not prop.required else "Field(...)"
600
617
  elif prop.property_type == 'data' and prop.datatype:
601
618
  if prop.cardinality == 'multiple':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naas-abi-core
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: Abi framework allowing you to build your AI system.
5
5
  Project-URL: Homepage, https://github.com/jupyter-naas/abi
6
6
  Project-URL: Repository, https://github.com/jupyter-naas/abi/tree/main/libs/naas-abi-core
@@ -33,7 +33,7 @@ naas_abi_core/integration/integration.py,sha256=tbdAV63Uisml9G8diZl20_JDlgJVFuLQ
33
33
  naas_abi_core/models/Model.py,sha256=s1Aj8Mcy113uhgYR4-lSfoyLnucOzOlnxKu6QKSwfeY,8223
34
34
  naas_abi_core/models/OpenRouter.py,sha256=BqDRnBlDmTdhE5cv7VsZ1IiZVad_lIltnnGt4V6MRuw,492
35
35
  naas_abi_core/models/OpenRouter_test.py,sha256=nLlVdBaBan0mkdbnF3vrWGJYr8zQAC7Fl3wLUc37Mvw,1168
36
- naas_abi_core/module/Module.py,sha256=UGNXZkwgD0xv7HrxTHH9eRXYPv8kuxqfMGAHgfgQJlM,9096
36
+ naas_abi_core/module/Module.py,sha256=fyZBU0rUwWuPR3LGjUm5v6eWNXrCWvv_QDkWVu9n_yE,9153
37
37
  naas_abi_core/module/ModuleAgentLoader.py,sha256=9FXcK8h0_0h4hU3gEjImUbNBBeYJ9HOEjYqKVdTl3ik,2050
38
38
  naas_abi_core/module/ModuleUtils.py,sha256=6wUHpbdl0y_16xvz7W-NSOaRyLW9N9zx2Lg_Jkg0eMM,707
39
39
  naas_abi_core/modules/templatablesparqlquery/README.md,sha256=Cpz3FPMc1q-P5HmQ7848er5_MRTHLDLqYqq0nFrs7Dw,6991
@@ -112,13 +112,13 @@ naas_abi_core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
112
112
  naas_abi_core/utils/onto2py/README.md,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
113
113
  naas_abi_core/utils/onto2py/__init__.py,sha256=mhTtX2gCv-IyWG71hiCYiOEbGOuDTssaOcqXxqySxn0,163
114
114
  naas_abi_core/utils/onto2py/__main__.py,sha256=b-brUMSGdg972Cr06V6BVIdSMTw17--h7b9zE3UPZ4E,696
115
- naas_abi_core/utils/onto2py/onto2py.py,sha256=_wn9qrrsWd8gO-BY4_jQJVfY87e9MJ2Er2Rf4FXcNls,24095
115
+ naas_abi_core/utils/onto2py/onto2py.py,sha256=omwUG0jFnk2ZQi5j1YHBQ4zvV38CH75U9DFWlVIrNiU,25096
116
116
  naas_abi_core/utils/onto2py/tests/ttl2py_test.py,sha256=5OZqSxPffjJYiX9T4rT1mV0PT1Qhf6goqEYT_mAPnaI,8055
117
117
  naas_abi_core/workflow/__init__.py,sha256=hZD58mCB1PApxITqftP_xgjxL7NeLvOfI-rJENg1ENs,250
118
118
  naas_abi_core/workflow/workflow.py,sha256=ZufSS073JztVl0OQRTqNyK7FepFvv7gXlc4j5FAEZCI,1216
119
119
  assets/favicon.ico,sha256=nWk8wrHZiJV3DeuWrP2MqilXxCuoNWKGtMZfYmEVQLw,666
120
120
  assets/logo.png,sha256=zUu9sNgMmtzJhfNCinDs85GP1LDNVfTy8kYLKRT_pxA,9334
121
- naas_abi_core-1.5.0.dist-info/METADATA,sha256=u--jb15TQ-2SKQ8UOo1sf0EX8qZJBP2StgZ67XuqCSA,17567
122
- naas_abi_core-1.5.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
123
- naas_abi_core-1.5.0.dist-info/entry_points.txt,sha256=IX0WUFxZuo1JU6H66fcRR6y7gYChMVw_XA9suPk9_1Q,70
124
- naas_abi_core-1.5.0.dist-info/RECORD,,
121
+ naas_abi_core-1.6.0.dist-info/METADATA,sha256=z_T4toUv563_v5rB_oNEKuTBv_yp08Tt1i3N1gr5uxk,17567
122
+ naas_abi_core-1.6.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
123
+ naas_abi_core-1.6.0.dist-info/entry_points.txt,sha256=IX0WUFxZuo1JU6H66fcRR6y7gYChMVw_XA9suPk9_1Q,70
124
+ naas_abi_core-1.6.0.dist-info/RECORD,,