cognite-neat 0.87.4__py3-none-any.whl → 0.88.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.

Potentially problematic release.


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

Files changed (132) hide show
  1. cognite/neat/_version.py +1 -1
  2. cognite/neat/app/api/data_classes/rest.py +0 -19
  3. cognite/neat/app/api/explorer.py +6 -4
  4. cognite/neat/app/api/routers/crud.py +11 -21
  5. cognite/neat/app/api/routers/workflows.py +24 -94
  6. cognite/neat/graph/extractors/_classic_cdf/_assets.py +8 -2
  7. cognite/neat/graph/extractors/_mock_graph_generator.py +2 -2
  8. cognite/neat/graph/loaders/_base.py +17 -12
  9. cognite/neat/graph/loaders/_rdf2asset.py +223 -58
  10. cognite/neat/graph/loaders/_rdf2dms.py +1 -1
  11. cognite/neat/graph/stores/_base.py +5 -0
  12. cognite/neat/rules/analysis/_asset.py +31 -1
  13. cognite/neat/rules/importers/_inference2rules.py +31 -35
  14. cognite/neat/rules/models/information/_rules.py +1 -1
  15. cognite/neat/workflows/steps/data_contracts.py +17 -43
  16. cognite/neat/workflows/steps/lib/current/graph_extractor.py +28 -24
  17. cognite/neat/workflows/steps/lib/current/graph_loader.py +4 -21
  18. cognite/neat/workflows/steps/lib/current/graph_store.py +18 -134
  19. cognite/neat/workflows/steps_registry.py +5 -7
  20. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/METADATA +1 -1
  21. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/RECORD +24 -132
  22. cognite/neat/app/api/routers/core.py +0 -91
  23. cognite/neat/app/api/routers/data_exploration.py +0 -336
  24. cognite/neat/app/api/routers/rules.py +0 -203
  25. cognite/neat/legacy/__init__.py +0 -0
  26. cognite/neat/legacy/graph/__init__.py +0 -3
  27. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -20182
  28. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +0 -20163
  29. cognite/neat/legacy/graph/examples/__init__.py +0 -10
  30. cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
  31. cognite/neat/legacy/graph/exceptions.py +0 -90
  32. cognite/neat/legacy/graph/extractors/__init__.py +0 -6
  33. cognite/neat/legacy/graph/extractors/_base.py +0 -14
  34. cognite/neat/legacy/graph/extractors/_dexpi.py +0 -44
  35. cognite/neat/legacy/graph/extractors/_graph_capturing_sheet.py +0 -403
  36. cognite/neat/legacy/graph/extractors/_mock_graph_generator.py +0 -361
  37. cognite/neat/legacy/graph/loaders/__init__.py +0 -23
  38. cognite/neat/legacy/graph/loaders/_asset_loader.py +0 -511
  39. cognite/neat/legacy/graph/loaders/_base.py +0 -67
  40. cognite/neat/legacy/graph/loaders/_exceptions.py +0 -85
  41. cognite/neat/legacy/graph/loaders/core/__init__.py +0 -0
  42. cognite/neat/legacy/graph/loaders/core/labels.py +0 -58
  43. cognite/neat/legacy/graph/loaders/core/models.py +0 -136
  44. cognite/neat/legacy/graph/loaders/core/rdf_to_assets.py +0 -1046
  45. cognite/neat/legacy/graph/loaders/core/rdf_to_relationships.py +0 -559
  46. cognite/neat/legacy/graph/loaders/rdf_to_dms.py +0 -309
  47. cognite/neat/legacy/graph/loaders/validator.py +0 -87
  48. cognite/neat/legacy/graph/models.py +0 -6
  49. cognite/neat/legacy/graph/stores/__init__.py +0 -13
  50. cognite/neat/legacy/graph/stores/_base.py +0 -400
  51. cognite/neat/legacy/graph/stores/_graphdb_store.py +0 -52
  52. cognite/neat/legacy/graph/stores/_memory_store.py +0 -43
  53. cognite/neat/legacy/graph/stores/_oxigraph_store.py +0 -151
  54. cognite/neat/legacy/graph/stores/_oxrdflib.py +0 -247
  55. cognite/neat/legacy/graph/stores/_rdf_to_graph.py +0 -42
  56. cognite/neat/legacy/graph/transformations/__init__.py +0 -0
  57. cognite/neat/legacy/graph/transformations/entity_matcher.py +0 -101
  58. cognite/neat/legacy/graph/transformations/query_generator/__init__.py +0 -3
  59. cognite/neat/legacy/graph/transformations/query_generator/sparql.py +0 -575
  60. cognite/neat/legacy/graph/transformations/transformer.py +0 -322
  61. cognite/neat/legacy/rules/__init__.py +0 -0
  62. cognite/neat/legacy/rules/analysis.py +0 -231
  63. cognite/neat/legacy/rules/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
  64. cognite/neat/legacy/rules/examples/Rules-Nordic44.xlsx +0 -0
  65. cognite/neat/legacy/rules/examples/__init__.py +0 -18
  66. cognite/neat/legacy/rules/examples/power-grid-containers.yaml +0 -124
  67. cognite/neat/legacy/rules/examples/power-grid-example.xlsx +0 -0
  68. cognite/neat/legacy/rules/examples/power-grid-model.yaml +0 -224
  69. cognite/neat/legacy/rules/examples/rules-template.xlsx +0 -0
  70. cognite/neat/legacy/rules/examples/sheet2cdf-transformation-rules.xlsx +0 -0
  71. cognite/neat/legacy/rules/examples/skos-rules.xlsx +0 -0
  72. cognite/neat/legacy/rules/examples/source-to-solution-mapping-rules.xlsx +0 -0
  73. cognite/neat/legacy/rules/examples/wind-energy.owl +0 -1511
  74. cognite/neat/legacy/rules/exceptions.py +0 -2972
  75. cognite/neat/legacy/rules/exporters/__init__.py +0 -20
  76. cognite/neat/legacy/rules/exporters/_base.py +0 -45
  77. cognite/neat/legacy/rules/exporters/_core/__init__.py +0 -5
  78. cognite/neat/legacy/rules/exporters/_core/rules2labels.py +0 -24
  79. cognite/neat/legacy/rules/exporters/_rules2dms.py +0 -885
  80. cognite/neat/legacy/rules/exporters/_rules2excel.py +0 -213
  81. cognite/neat/legacy/rules/exporters/_rules2graphql.py +0 -183
  82. cognite/neat/legacy/rules/exporters/_rules2ontology.py +0 -524
  83. cognite/neat/legacy/rules/exporters/_rules2pydantic_models.py +0 -748
  84. cognite/neat/legacy/rules/exporters/_rules2rules.py +0 -105
  85. cognite/neat/legacy/rules/exporters/_rules2triples.py +0 -38
  86. cognite/neat/legacy/rules/exporters/_validation.py +0 -146
  87. cognite/neat/legacy/rules/importers/__init__.py +0 -22
  88. cognite/neat/legacy/rules/importers/_base.py +0 -66
  89. cognite/neat/legacy/rules/importers/_dict2rules.py +0 -158
  90. cognite/neat/legacy/rules/importers/_dms2rules.py +0 -194
  91. cognite/neat/legacy/rules/importers/_graph2rules.py +0 -308
  92. cognite/neat/legacy/rules/importers/_json2rules.py +0 -39
  93. cognite/neat/legacy/rules/importers/_owl2rules/__init__.py +0 -3
  94. cognite/neat/legacy/rules/importers/_owl2rules/_owl2classes.py +0 -239
  95. cognite/neat/legacy/rules/importers/_owl2rules/_owl2metadata.py +0 -260
  96. cognite/neat/legacy/rules/importers/_owl2rules/_owl2properties.py +0 -217
  97. cognite/neat/legacy/rules/importers/_owl2rules/_owl2rules.py +0 -290
  98. cognite/neat/legacy/rules/importers/_spreadsheet2rules.py +0 -45
  99. cognite/neat/legacy/rules/importers/_xsd2rules.py +0 -20
  100. cognite/neat/legacy/rules/importers/_yaml2rules.py +0 -39
  101. cognite/neat/legacy/rules/models/__init__.py +0 -5
  102. cognite/neat/legacy/rules/models/_base.py +0 -151
  103. cognite/neat/legacy/rules/models/raw_rules.py +0 -316
  104. cognite/neat/legacy/rules/models/rdfpath.py +0 -237
  105. cognite/neat/legacy/rules/models/rules.py +0 -1289
  106. cognite/neat/legacy/rules/models/tables.py +0 -9
  107. cognite/neat/legacy/rules/models/value_types.py +0 -118
  108. cognite/neat/legacy/workflows/examples/Export_DMS/workflow.yaml +0 -89
  109. cognite/neat/legacy/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
  110. cognite/neat/legacy/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
  111. cognite/neat/legacy/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  112. cognite/neat/legacy/workflows/examples/Import_DMS/workflow.yaml +0 -65
  113. cognite/neat/legacy/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
  114. cognite/neat/legacy/workflows/examples/Validate_Rules/workflow.yaml +0 -67
  115. cognite/neat/legacy/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -64
  116. cognite/neat/legacy/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -95
  117. cognite/neat/legacy/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -111
  118. cognite/neat/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
  119. cognite/neat/workflows/migration/__init__.py +0 -0
  120. cognite/neat/workflows/migration/steps.py +0 -91
  121. cognite/neat/workflows/migration/wf_manifests.py +0 -33
  122. cognite/neat/workflows/steps/lib/legacy/__init__.py +0 -7
  123. cognite/neat/workflows/steps/lib/legacy/graph_contextualization.py +0 -82
  124. cognite/neat/workflows/steps/lib/legacy/graph_extractor.py +0 -746
  125. cognite/neat/workflows/steps/lib/legacy/graph_loader.py +0 -606
  126. cognite/neat/workflows/steps/lib/legacy/graph_store.py +0 -307
  127. cognite/neat/workflows/steps/lib/legacy/graph_transformer.py +0 -58
  128. cognite/neat/workflows/steps/lib/legacy/rules_exporter.py +0 -511
  129. cognite/neat/workflows/steps/lib/legacy/rules_importer.py +0 -612
  130. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/LICENSE +0 -0
  131. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/WHEEL +0 -0
  132. {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/entry_points.txt +0 -0
@@ -1,307 +0,0 @@
1
- import logging
2
- from pathlib import Path
3
- from typing import ClassVar, cast
4
-
5
- from cognite.neat.constants import DEFAULT_NAMESPACE, get_default_prefixes
6
- from cognite.neat.legacy.graph import stores
7
- from cognite.neat.workflows._exceptions import StepNotInitialized
8
- from cognite.neat.workflows.model import FlowMessage
9
- from cognite.neat.workflows.steps.data_contracts import (
10
- RulesData,
11
- SolutionGraph,
12
- SourceGraph,
13
- )
14
- from cognite.neat.workflows.steps.step_model import Configurable, Step
15
-
16
- __all__ = ["ResetGraphStores", "ConfigureGraphStore"]
17
-
18
- CATEGORY = __name__.split(".")[-1].replace("_", " ").title() + " [LEGACY]"
19
-
20
-
21
- class ConfigureDefaultGraphStores(Step):
22
- """
23
- This step initializes the source and solution graph stores
24
- """
25
-
26
- description = "This step initializes the source and solution graph stores."
27
- category = CATEGORY
28
- version = "legacy"
29
- configurables: ClassVar[list[Configurable]] = [
30
- Configurable(
31
- name="source_rdf_store.type",
32
- value=stores.OxiGraphStore.rdf_store_type,
33
- label="Data store type for source graph. Supported: oxigraph, memory,file, graphdb, sparql. ",
34
- options=["oxigraph", "memory", "file", "graphdb", "sparql"],
35
- ),
36
- Configurable(
37
- name="solution_rdf_store.type",
38
- value=stores.OxiGraphStore.rdf_store_type,
39
- label="Data store type for solutioin graph. Supported: oxigraph, memory,file, graphdb, sparql",
40
- options=["oxigraph", "memory", "file", "graphdb", "sparql"],
41
- ),
42
- Configurable(
43
- name="source_rdf_store.disk_store_dir",
44
- value="source-graph-store",
45
- label="Local directory for source graph store",
46
- ),
47
- Configurable(
48
- name="source_rdf_store.query_url",
49
- value="",
50
- label="Sparql query endpoint.Only for sparql and graphdb store type",
51
- ),
52
- Configurable(
53
- name="source_rdf_store.update_url",
54
- value="",
55
- label="Sparql update endpoint.Only for sparql and graphdb store type",
56
- ),
57
- Configurable(
58
- name="solution_rdf_store.query_url",
59
- value="",
60
- label="Sparql query endpoint.Only for sparql and graphdb store type",
61
- ),
62
- Configurable(
63
- name="solution_rdf_store.update_url",
64
- value="",
65
- label="Sparql update endpoint.Only for sparql and graphdb store type",
66
- ),
67
- Configurable(
68
- name="solution_rdf_store.disk_store_dir",
69
- value="solution-graph-store",
70
- label="Local directory for solution graph store",
71
- ),
72
- Configurable(
73
- name="stores_to_configure",
74
- value="all",
75
- label="Defines which stores to configure",
76
- options=["all", "source", "solution"],
77
- ),
78
- Configurable(
79
- name="solution_rdf_store.api_root_url",
80
- value="",
81
- label="Root url for graphdb or sparql endpoint",
82
- ),
83
- ]
84
-
85
- def run(self, rules_data: RulesData | None = None) -> (FlowMessage, SourceGraph, SolutionGraph): # type: ignore[override, syntax]
86
- prefixes = rules_data.rules.prefixes if rules_data else get_default_prefixes()
87
-
88
- if self.configs is None or self.data_store_path is None:
89
- raise StepNotInitialized(type(self).__name__)
90
- logging.info("Initializing source graph")
91
- stores_to_configure = self.configs["stores_to_configure"]
92
- source_store_dir = self.configs["source_rdf_store.disk_store_dir"]
93
- source_store_dir = Path(self.data_store_path) / Path(source_store_dir) if source_store_dir else None
94
- source_store_type = self.configs["source_rdf_store.type"]
95
- if stores_to_configure in ["all", "source"]:
96
- if source_store_type == stores.OxiGraphStore.rdf_store_type and "SourceGraph" in self.flow_context:
97
- cast(SourceGraph, self.flow_context["SourceGraph"]).graph.upsert_prefixes(prefixes)
98
- return FlowMessage(output_text="Stores already configured")
99
- try:
100
- store_cls = stores.STORE_BY_TYPE[source_store_type]
101
- except KeyError:
102
- return FlowMessage(output_text="Invalid store type")
103
- source_graph = store_cls(prefixes=prefixes, base_prefix="neat", namespace=DEFAULT_NAMESPACE)
104
-
105
- source_graph.init_graph(
106
- self.configs["source_rdf_store.query_url"],
107
- self.configs["source_rdf_store.update_url"],
108
- "neat-tnt",
109
- internal_storage_dir=source_store_dir,
110
- )
111
- if stores_to_configure == "source":
112
- return FlowMessage(output_text="Source graph store configured successfully"), SourceGraph(
113
- graph=source_graph
114
- )
115
- else:
116
- source_graph = None
117
-
118
- if stores_to_configure in ["all", "solution"]:
119
- solution_store_dir = self.configs["solution_rdf_store.disk_store_dir"]
120
- solution_store_dir = self.data_store_path / Path(solution_store_dir) if solution_store_dir else None
121
- solution_store_type = self.configs["solution_rdf_store.type"]
122
-
123
- if solution_store_type == stores.OxiGraphStore.rdf_store_type and "SolutionGraph" in self.flow_context:
124
- cast(SolutionGraph, self.flow_context["SolutionGraph"]).graph.upsert_prefixes(prefixes)
125
- return FlowMessage(output_text="Stores already configured")
126
-
127
- try:
128
- solution_graph = stores.STORE_BY_TYPE[solution_store_type](
129
- prefixes=prefixes, base_prefix="neat", namespace=DEFAULT_NAMESPACE
130
- )
131
- except KeyError:
132
- return FlowMessage(output_text="Invalid store type")
133
-
134
- solution_graph.init_graph(
135
- self.configs["solution_rdf_store.query_url"],
136
- self.configs["solution_rdf_store.update_url"],
137
- "tnt-solution",
138
- internal_storage_dir=solution_store_dir,
139
- )
140
-
141
- if isinstance(solution_graph, stores.GraphDBStore):
142
- solution_graph.graph_db_rest_url = self.configs["solution_rdf_store.api_root_url"]
143
-
144
- if stores_to_configure == "solution":
145
- return FlowMessage(output_text="Solution graph store configured successfully"), SolutionGraph(
146
- graph=solution_graph
147
- )
148
- else:
149
- solution_graph = None
150
-
151
- return (
152
- FlowMessage(output_text="All graph stores configured successfully"),
153
- SourceGraph(graph=source_graph) if source_graph else None,
154
- SolutionGraph(graph=solution_graph) if solution_graph else None,
155
- )
156
-
157
-
158
- class ResetGraphStores(Step):
159
- """
160
- This step resets graph stores to their initial state (clears all data)
161
- """
162
-
163
- description = "This step resets graph stores to their initial state (clears all data)."
164
- category = CATEGORY
165
- version = "legacy"
166
- configurables: ClassVar[list[Configurable]] = [
167
- Configurable(
168
- name="graph_name",
169
- value="source",
170
- label="Name of the data store. Supported: solution, source ",
171
- options=["source", "solution"],
172
- )
173
- ]
174
-
175
- def run(self) -> FlowMessage: # type: ignore[override, syntax]
176
- if self.configs is None or self.data_store_path is None:
177
- raise StepNotInitialized(type(self).__name__)
178
- graph_name_mapping = {"source": "SourceGraph", "solution": "SolutionGraph"}
179
-
180
- graph_name = graph_name_mapping[self.configs["graph_name"]]
181
- graph_store = cast(SourceGraph | SolutionGraph | None, self.flow_context.get(graph_name, None))
182
- if graph_store is not None:
183
- reset_store(graph_store.graph.internal_storage_dir, graph_store.graph)
184
- if graph_name in self.flow_context:
185
- del self.flow_context[graph_name]
186
- return FlowMessage(output_text="Reset operation completed")
187
- else:
188
- return FlowMessage(output_text="Stores already reset")
189
-
190
-
191
- class ConfigureGraphStore(Step):
192
- """
193
- This step initializes source OR solution graph store
194
- """
195
-
196
- description = "This step initializes the source and solution graph stores."
197
- version = "legacy"
198
- category = CATEGORY
199
- configurables: ClassVar[list[Configurable]] = [
200
- Configurable(
201
- name="graph_name",
202
- value="source",
203
- label="Name of the data store. Supported: solution, source ",
204
- options=["source", "solution"],
205
- ),
206
- Configurable(
207
- name="store_type",
208
- value=stores.OxiGraphStore.rdf_store_type,
209
- label="Data store type for source graph. Supported: oxigraph, memory,file, graphdb, sparql. ",
210
- options=["oxigraph", "memory", "file", "graphdb", "sparql"],
211
- ),
212
- Configurable(
213
- name="disk_store_dir",
214
- value="source-graph-store",
215
- label="Local directory that is used as local graph store.Only for oxigraph, file store types",
216
- ),
217
- Configurable(
218
- name="sparql_query_url",
219
- value="",
220
- label="Query url for sparql endpoint.Only for sparql store type",
221
- ),
222
- Configurable(
223
- name="sparql_update_url",
224
- value="",
225
- label="Update url for sparql endpoint.Only for sparql store type",
226
- ),
227
- Configurable(
228
- name="db_server_api_root_url",
229
- value="",
230
- label="Root url for graphdb or sparql endpoint.Only for graphdb",
231
- ),
232
- Configurable(
233
- name="init_procedure",
234
- value="reset",
235
- label="Operations to be performed on the graph store as part of init and configuration process. \
236
- Supported options : reset, clear, none",
237
- options=["reset", "none"],
238
- ),
239
- ]
240
-
241
- def run( # type: ignore[override]
242
- self, rules_data: RulesData | None = None
243
- ) -> (FlowMessage, SourceGraph | SolutionGraph): # type: ignore[syntax]
244
- if self.configs is None or self.data_store_path is None:
245
- raise StepNotInitialized(type(self).__name__)
246
- logging.info("Initializing graph")
247
- store_dir = self.data_store_path / Path(value) if (value := self.configs["disk_store_dir"]) else None
248
- store_type = self.configs["store_type"]
249
- graph_name_mapping = {"source": "SourceGraph", "solution": "SolutionGraph"}
250
-
251
- graph_name = graph_name_mapping[self.configs["graph_name"]]
252
- graph_store = cast(SourceGraph | SolutionGraph | None, self.flow_context.get(graph_name, None))
253
- if self.configs["init_procedure"] == "reset":
254
- logging.info("Resetting graph")
255
- reset_store(store_dir, graph_store.graph if graph_store else None)
256
- if graph_name in self.flow_context:
257
- del self.flow_context[graph_name]
258
- graph_store = None
259
- logging.info("Graph reset complete")
260
-
261
- prefixes = rules_data.rules.prefixes if rules_data else get_default_prefixes()
262
-
263
- if store_type == stores.OxiGraphStore.rdf_store_type and graph_store is not None:
264
- # OXIGRAPH doesn't like to be initialized twice without a good reason
265
- graph_store.graph.upsert_prefixes(prefixes)
266
- return FlowMessage(output_text="Stores already configured")
267
- try:
268
- store_cls = stores.STORE_BY_TYPE[store_type]
269
- except KeyError:
270
- return FlowMessage(output_text="Invalid store type")
271
-
272
- new_graph_store = store_cls(prefixes=prefixes, base_prefix="neat", namespace=DEFAULT_NAMESPACE)
273
- new_graph_store.init_graph(
274
- self.configs["sparql_query_url"],
275
- self.configs["sparql_update_url"],
276
- "neat-tnt",
277
- internal_storage_dir=store_dir,
278
- )
279
- logging.info(50 * "*")
280
- logging.info(50 * "*")
281
- logging.info(50 * "*")
282
- logging.info(type(new_graph_store))
283
- logging.info(50 * "*")
284
- logging.info(50 * "*")
285
-
286
- return (
287
- FlowMessage(output_text="Graph store configured successfully"),
288
- (
289
- SourceGraph(graph=new_graph_store)
290
- if graph_name == "SourceGraph"
291
- else SolutionGraph(graph=new_graph_store)
292
- ),
293
- )
294
-
295
-
296
- def reset_store(data_store_dir: Path | None, graph_store: stores.NeatGraphStoreBase | None = None):
297
- if isinstance(graph_store, stores.OxiGraphStore):
298
- if graph_store:
299
- graph_store.close()
300
- graph_store.drop_graph_store_storage(data_store_dir)
301
- elif data_store_dir:
302
- graph_store.drop_graph_store_storage(data_store_dir)
303
- elif isinstance(graph_store, stores.GraphDBStore):
304
- if graph_store:
305
- graph_store.drop()
306
- graph_store.reinitialize_graph()
307
- return None
@@ -1,58 +0,0 @@
1
- from typing import ClassVar
2
-
3
- from cognite.client import CogniteClient
4
-
5
- from cognite.neat.legacy.graph.transformations.transformer import RuleProcessingReport, domain2app_knowledge_graph
6
- from cognite.neat.legacy.rules.exporters._rules2triples import get_instances_as_triples
7
- from cognite.neat.workflows.model import FlowMessage
8
- from cognite.neat.workflows.steps.data_contracts import RulesData, SolutionGraph, SourceGraph
9
- from cognite.neat.workflows.steps.step_model import Configurable, Step
10
-
11
- __all__ = ["TransformSourceToSolutionGraph"]
12
-
13
- CATEGORY = __name__.split(".")[-1].replace("_", " ").title() + " [LEGACY]"
14
-
15
-
16
- class TransformSourceToSolutionGraph(Step):
17
- """
18
- The step transforms source graph to solution graph
19
- """
20
-
21
- description = "The step transforms source graph to solution graph"
22
- category = CATEGORY
23
- version = "legacy"
24
- configurables: ClassVar[list[Configurable]] = [
25
- Configurable(
26
- name="cdf_lookup_database",
27
- value="",
28
- label="Name of the CDF raw database to use for data lookup (rawlookup rules).\
29
- Applicable only for transformations with rawlookup rules.",
30
- )
31
- ]
32
-
33
- def run( # type: ignore[override, syntax]
34
- self,
35
- transformation_rules: RulesData,
36
- cdf_client: CogniteClient,
37
- source_graph: SourceGraph,
38
- solution_graph: SolutionGraph,
39
- ) -> FlowMessage:
40
- report = RuleProcessingReport()
41
- # run transformation and generate new graph
42
- cdf_lookup_database = self.configs.get("cdf_lookup_database", "")
43
- solution_graph.graph.set_graph(
44
- domain2app_knowledge_graph(
45
- source_graph.graph.get_graph(),
46
- transformation_rules.rules,
47
- app_instance_graph=solution_graph.graph.get_graph(),
48
- extra_triples=get_instances_as_triples(transformation_rules.rules),
49
- client=cdf_client,
50
- cdf_lookup_database=cdf_lookup_database, # change this accordingly!
51
- processing_report=report,
52
- )
53
- )
54
- return FlowMessage(
55
- output_text=f"Total processed rules: { report.total_rules } , success: { report.total_success } , \
56
- no results: { report.total_success_no_results } , failed: { report.total_failed }",
57
- payload=report,
58
- )