cognite-neat 0.78.0__py3-none-any.whl → 0.78.1__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.

Potentially problematic release.


This version of cognite-neat might be problematic. Click here for more details.

cognite/neat/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.78.0"
1
+ __version__ = "0.78.1"
@@ -7,6 +7,7 @@ from rdflib import Literal as RdfLiteral
7
7
 
8
8
  import cognite.neat.rules.issues as issues
9
9
  from cognite.neat.constants import PREFIXES
10
+ from cognite.neat.graph.stores import NeatGraphStoreBase
10
11
  from cognite.neat.rules.importers._base import BaseImporter, Rules, _handle_issues
11
12
  from cognite.neat.rules.issues import IssueList
12
13
  from cognite.neat.rules.models import InformationRules, RoleTypes
@@ -42,13 +43,23 @@ class InferenceImporter(BaseImporter):
42
43
  """
43
44
 
44
45
  def __init__(
45
- self, issue_list: IssueList, graph: Graph, max_number_of_instance: int = -1, make_compliant: bool = False
46
+ self, issue_list: IssueList, graph: Graph, make_compliant: bool = False, max_number_of_instance: int = -1
46
47
  ):
47
48
  self.issue_list = issue_list
48
49
  self.graph = graph
49
50
  self.max_number_of_instance = max_number_of_instance
50
51
  self.make_compliant = make_compliant
51
52
 
53
+ @classmethod
54
+ def from_graph_store(
55
+ cls, store: NeatGraphStoreBase, make_compliant: bool = False, max_number_of_instance: int = -1
56
+ ):
57
+ issue_list = IssueList(title="Inferred from graph store")
58
+
59
+ return cls(
60
+ issue_list, store.graph, make_compliant=make_compliant, max_number_of_instance=max_number_of_instance
61
+ )
62
+
52
63
  @classmethod
53
64
  def from_rdf_file(cls, filepath: Path, make_compliant: bool = False, max_number_of_instance: int = -1):
54
65
  issue_list = IssueList(title=f"'{filepath.name}'")
@@ -213,6 +213,11 @@ class Entity(BaseModel, extra="ignore"):
213
213
  return f"{self.suffix!s}"
214
214
  return f"{self.prefix}:{self.suffix!s}"
215
215
 
216
+ def as_dms_compliant_entity(self) -> "Self":
217
+ new_entity = self.model_copy(deep=True)
218
+ new_entity.suffix = replace_non_alphanumeric_with_underscore(new_entity.suffix)
219
+ return new_entity
220
+
216
221
 
217
222
  T_Entity = TypeVar("T_Entity", bound=Entity)
218
223
 
@@ -20,6 +20,7 @@ __all__ = [
20
20
  "ExcelToRules",
21
21
  "OntologyToRules",
22
22
  "DMSToRules",
23
+ "RulesInferenceFromRdfFile",
23
24
  ]
24
25
 
25
26
 
@@ -259,3 +260,97 @@ class DMSToRules(Step):
259
260
  output_text = "Rules import and validation passed successfully!"
260
261
 
261
262
  return FlowMessage(output_text=output_text), MultiRuleData.from_rules(rules)
263
+
264
+
265
+ class RulesInferenceFromRdfFile(Step):
266
+ """This step infers rules from the RDF file which contains knowledge graph."""
267
+
268
+ description = "This step infers rules from the RDF file which contains knowledge graph"
269
+ version = "private-beta"
270
+ category = CATEGORY
271
+ configurables: ClassVar[list[Configurable]] = [
272
+ Configurable(
273
+ name="File path",
274
+ value="staging/knowledge_graph.ttl",
275
+ label=("Relative path to the RDF file to be used for inference"),
276
+ ),
277
+ Configurable(
278
+ name="Report formatter",
279
+ value=next(iter(FORMATTER_BY_NAME.keys())),
280
+ label="The format of the report for the validation of the rules",
281
+ options=list(FORMATTER_BY_NAME),
282
+ ),
283
+ Configurable(
284
+ name="Role",
285
+ value="infer",
286
+ label="For what role Rules are intended?",
287
+ options=["infer", *RoleTypes.__members__.keys()],
288
+ ),
289
+ Configurable(
290
+ name="Make compliant",
291
+ value="True",
292
+ label=(
293
+ "Attempt to make the imported Rules compliant, by fixing "
294
+ "redefinition of properties and by making ids of entities compliant with"
295
+ " CDF-allowed set of characters ."
296
+ ),
297
+ options=["True", "False"],
298
+ ),
299
+ Configurable(
300
+ name="Maximum number of instances to process",
301
+ value="-1",
302
+ label=(
303
+ "Maximum number of instances to process"
304
+ " to infer rules from the RDF file. Default -1 means all instances."
305
+ ),
306
+ ),
307
+ ]
308
+
309
+ def run(self, flow_message: FlowMessage) -> (FlowMessage, MultiRuleData): # type: ignore[syntax, override]
310
+ if self.configs is None or self.data_store_path is None:
311
+ raise StepNotInitialized(type(self).__name__)
312
+
313
+ file_path = self.configs.get("File path", None)
314
+ full_path = flow_message.payload.get("full_path", None) if flow_message.payload else None
315
+ make_compliant = self.configs.get("Make compliant", "True") == "True"
316
+
317
+ try:
318
+ max_number_of_instance = int(self.configs.get("Maximum number of instances to process", -1))
319
+ except ValueError:
320
+ error_text = "Maximum number of instances to process should be an integer value"
321
+ return FlowMessage(error_text=error_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
322
+
323
+ if file_path:
324
+ rdf_file_path = self.data_store_path / Path(file_path)
325
+ elif full_path:
326
+ rdf_file_path = full_path
327
+ else:
328
+ error_text = "Expected either 'File name' in the step config or 'File uploader' step uploading Excel Rules."
329
+ return FlowMessage(error_text=error_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
330
+
331
+ # if role is None, it will be inferred from the rules file
332
+ role = self.configs.get("Role")
333
+ role_enum = None
334
+ if role != "infer" and role is not None:
335
+ role_enum = RoleTypes[role]
336
+
337
+ inference_importer = importers.InferenceImporter.from_rdf_file(
338
+ rdf_file_path, make_compliant=make_compliant, max_number_of_instance=max_number_of_instance
339
+ )
340
+ rules, issues = inference_importer.to_rules(errors="continue", role=role_enum)
341
+
342
+ if rules is None:
343
+ output_dir = self.config.staging_path
344
+ report_writer = FORMATTER_BY_NAME[self.configs["Report formatter"]]()
345
+ report_writer.write_to_file(issues, file_or_dir_path=output_dir)
346
+ report_file = report_writer.default_file_name
347
+ error_text = (
348
+ "<p></p>"
349
+ f'<a href="/data/staging/{report_file}?{time.time()}" '
350
+ f'target="_blank">Failed to validate rules, click here for report</a>'
351
+ )
352
+ return FlowMessage(error_text=error_text, step_execution_status=StepExecutionStatus.ABORT_AND_FAIL)
353
+
354
+ output_text = "Rules validation passed successfully!"
355
+
356
+ return FlowMessage(output_text=output_text), MultiRuleData.from_rules(rules)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-neat
3
- Version: 0.78.0
3
+ Version: 0.78.1
4
4
  Summary: Knowledge graph transformation
5
5
  Home-page: https://cognite-neat.readthedocs-hosted.com/
6
6
  License: Apache-2.0
@@ -1,5 +1,5 @@
1
1
  cognite/neat/__init__.py,sha256=v-rRiDOgZ3sQSMQKq0vgUQZvpeOkoHFXissAx6Ktg84,61
2
- cognite/neat/_version.py,sha256=c66Ro55TMfP42f5YzH82UTnUBBvi0RwfY4nXmvb0W50,23
2
+ cognite/neat/_version.py,sha256=HinYe1V3FgUaLri1gy6R6_VuKh3sB-UYTNM51cV6k4I,23
3
3
  cognite/neat/app/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  cognite/neat/app/api/asgi/metrics.py,sha256=nxFy7L5cChTI0a-zkCiJ59Aq8yLuIJp5c9Dg0wRXtV0,152
5
5
  cognite/neat/app/api/configuration.py,sha256=2U5M6M252swvQPQyooA1EBzFUZNtcTmuSaywfJDgckM,4232
@@ -178,7 +178,7 @@ cognite/neat/rules/importers/_dtdl2rules/_unit_lookup.py,sha256=wW4saKva61Q_i17g
178
178
  cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py,sha256=ysmWUxZ0npwrTB0uiH5jA0v37sfCwowGaYk17IyxPUU,12663
179
179
  cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py,sha256=QDyGt5YBaxzF4v_oCFSgKRSpwVdVruDU3-VW0DEiHbY,6718
180
180
  cognite/neat/rules/importers/_dtdl2rules/spec.py,sha256=tim_MfN1J0F3Oeqk3BMgIA82d_MZvhRuRMsLK3B4PYc,11897
181
- cognite/neat/rules/importers/_inference2rules.py,sha256=Jkq058al1NNGvVxrYZsv5y2-hFXt3CtGq9S1V5Vqbj8,10765
181
+ cognite/neat/rules/importers/_inference2rules.py,sha256=CFSwf8ZTg_luMooBaP3_0762fjDlJxCoxjLRm4J2_m4,11187
182
182
  cognite/neat/rules/importers/_owl2rules/__init__.py,sha256=tdGcrgtozdQyST-pTlxIa4cLBNTLvtk1nNYR4vOdFSw,63
183
183
  cognite/neat/rules/importers/_owl2rules/_owl2classes.py,sha256=LInFeBq-NbBIuMEAwgWch2a4DbBUt4_OMqPkwehW-sw,7591
184
184
  cognite/neat/rules/importers/_owl2rules/_owl2metadata.py,sha256=NdPN0dBB0NYkAcfC0yrYdIrGfdPbl5gfeGnSV3EtUPM,7786
@@ -210,7 +210,7 @@ cognite/neat/rules/models/dms/_schema.py,sha256=A4z8CINmLQgWzHoScxejRPMRo40ngKly
210
210
  cognite/neat/rules/models/dms/_serializer.py,sha256=iqp2zyyf8jEcU-R3PERuN8nu248xIqyxiWj4owAn92g,6406
211
211
  cognite/neat/rules/models/dms/_validation.py,sha256=nPSyfM1vGZ7d9Uv_2vF2HvMetygtehXW7eNtPD6eW8E,13937
212
212
  cognite/neat/rules/models/domain.py,sha256=tkKcHvDXnZ5IkOr1wHiuNBtE1h8OCFmf6GZSqzHzxjI,2814
213
- cognite/neat/rules/models/entities.py,sha256=SuVPDVZdf18Mx7h5BgrF8HVojWq_X3cFyCDoTA_sOIU,16686
213
+ cognite/neat/rules/models/entities.py,sha256=qQIH93t2Vmyz-aqh-HWarQbenpmauPeECS9rkS6ihFM,16898
214
214
  cognite/neat/rules/models/information/__init__.py,sha256=HR6g8xgyU53U7Ck8pPdbT70817Q4NC1r1pCRq5SA8iw,291
215
215
  cognite/neat/rules/models/information/_converter.py,sha256=JN63_G5bygdL5WCz-q0_ygiU0NHkzUxm5mZ3WD8yUes,11029
216
216
  cognite/neat/rules/models/information/_rules.py,sha256=tdCjvAtqnFzEo2zcx-BZHmvjSs28gVun2wz8UaT-AOA,13268
@@ -259,7 +259,7 @@ cognite/neat/workflows/steps/lib/current/graph_extractor.py,sha256=vW9UpJScx5dFV
259
259
  cognite/neat/workflows/steps/lib/current/graph_loader.py,sha256=HfGg1HRZhbV58TFu89FTjKeUxGsbCYLeFJIQFDN_pQM,2341
260
260
  cognite/neat/workflows/steps/lib/current/graph_store.py,sha256=r7VTxdaz8jJQU7FJbnRDMxvEYbSAZFNMABhPyfNwiFk,6295
261
261
  cognite/neat/workflows/steps/lib/current/rules_exporter.py,sha256=iFwzDWgUDBSPajaNAcXvu9pVw-jX66upvwyMXyTq7SE,23822
262
- cognite/neat/workflows/steps/lib/current/rules_importer.py,sha256=oGIBh9iFYP3w_K0kLpM-OKTw70R1Mw_opD62MGkCJlk,11451
262
+ cognite/neat/workflows/steps/lib/current/rules_importer.py,sha256=u79hnIulQ14TsScfwvcXp2UcvNhBX0E4ESxIJloerRY,15626
263
263
  cognite/neat/workflows/steps/lib/current/rules_validator.py,sha256=LwF9lXlnuPOxDSsOMMTHBi2BHc5rk08IF5zahS9yQuw,4844
264
264
  cognite/neat/workflows/steps/lib/io/__init__.py,sha256=k7IPbIq3ey19oRc5sA_15F99-O6dxzqbm1LihGRRo5A,32
265
265
  cognite/neat/workflows/steps/lib/io/io_steps.py,sha256=QAGypoi1vP32BRiIgBZ0B4qsbFMcwhzpRiVUUnWysLA,16874
@@ -276,8 +276,8 @@ cognite/neat/workflows/steps_registry.py,sha256=fkTX14ZA7_gkUYfWIlx7A1XbCidvqR23
276
276
  cognite/neat/workflows/tasks.py,sha256=dqlJwKAb0jlkl7abbY8RRz3m7MT4SK8-7cntMWkOYjw,788
277
277
  cognite/neat/workflows/triggers.py,sha256=_BLNplzoz0iic367u1mhHMHiUrCwP-SLK6_CZzfODX0,7071
278
278
  cognite/neat/workflows/utils.py,sha256=gKdy3RLG7ctRhbCRwaDIWpL9Mi98zm56-d4jfHDqP1E,453
279
- cognite_neat-0.78.0.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
280
- cognite_neat-0.78.0.dist-info/METADATA,sha256=I1IHVLVE_UkRsT2HM3vP3OtoE2AmEe_XaAi8wxFl1sY,9306
281
- cognite_neat-0.78.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
282
- cognite_neat-0.78.0.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
283
- cognite_neat-0.78.0.dist-info/RECORD,,
279
+ cognite_neat-0.78.1.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
280
+ cognite_neat-0.78.1.dist-info/METADATA,sha256=yDfESAmMuhuO2LxGTEozKPAOKN9z7RM1NmxeXRJCkEU,9306
281
+ cognite_neat-0.78.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
282
+ cognite_neat-0.78.1.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
283
+ cognite_neat-0.78.1.dist-info/RECORD,,