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.
- cognite/neat/_version.py +1 -1
- cognite/neat/app/api/data_classes/rest.py +0 -19
- cognite/neat/app/api/explorer.py +6 -4
- cognite/neat/app/api/routers/crud.py +11 -21
- cognite/neat/app/api/routers/workflows.py +24 -94
- cognite/neat/graph/extractors/_classic_cdf/_assets.py +8 -2
- cognite/neat/graph/extractors/_mock_graph_generator.py +2 -2
- cognite/neat/graph/loaders/_base.py +17 -12
- cognite/neat/graph/loaders/_rdf2asset.py +223 -58
- cognite/neat/graph/loaders/_rdf2dms.py +1 -1
- cognite/neat/graph/stores/_base.py +5 -0
- cognite/neat/rules/analysis/_asset.py +31 -1
- cognite/neat/rules/importers/_inference2rules.py +31 -35
- cognite/neat/rules/models/information/_rules.py +1 -1
- cognite/neat/workflows/steps/data_contracts.py +17 -43
- cognite/neat/workflows/steps/lib/current/graph_extractor.py +28 -24
- cognite/neat/workflows/steps/lib/current/graph_loader.py +4 -21
- cognite/neat/workflows/steps/lib/current/graph_store.py +18 -134
- cognite/neat/workflows/steps_registry.py +5 -7
- {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/METADATA +1 -1
- {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/RECORD +24 -132
- cognite/neat/app/api/routers/core.py +0 -91
- cognite/neat/app/api/routers/data_exploration.py +0 -336
- cognite/neat/app/api/routers/rules.py +0 -203
- cognite/neat/legacy/__init__.py +0 -0
- cognite/neat/legacy/graph/__init__.py +0 -3
- cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +0 -20182
- cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +0 -20163
- cognite/neat/legacy/graph/examples/__init__.py +0 -10
- cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
- cognite/neat/legacy/graph/exceptions.py +0 -90
- cognite/neat/legacy/graph/extractors/__init__.py +0 -6
- cognite/neat/legacy/graph/extractors/_base.py +0 -14
- cognite/neat/legacy/graph/extractors/_dexpi.py +0 -44
- cognite/neat/legacy/graph/extractors/_graph_capturing_sheet.py +0 -403
- cognite/neat/legacy/graph/extractors/_mock_graph_generator.py +0 -361
- cognite/neat/legacy/graph/loaders/__init__.py +0 -23
- cognite/neat/legacy/graph/loaders/_asset_loader.py +0 -511
- cognite/neat/legacy/graph/loaders/_base.py +0 -67
- cognite/neat/legacy/graph/loaders/_exceptions.py +0 -85
- cognite/neat/legacy/graph/loaders/core/__init__.py +0 -0
- cognite/neat/legacy/graph/loaders/core/labels.py +0 -58
- cognite/neat/legacy/graph/loaders/core/models.py +0 -136
- cognite/neat/legacy/graph/loaders/core/rdf_to_assets.py +0 -1046
- cognite/neat/legacy/graph/loaders/core/rdf_to_relationships.py +0 -559
- cognite/neat/legacy/graph/loaders/rdf_to_dms.py +0 -309
- cognite/neat/legacy/graph/loaders/validator.py +0 -87
- cognite/neat/legacy/graph/models.py +0 -6
- cognite/neat/legacy/graph/stores/__init__.py +0 -13
- cognite/neat/legacy/graph/stores/_base.py +0 -400
- cognite/neat/legacy/graph/stores/_graphdb_store.py +0 -52
- cognite/neat/legacy/graph/stores/_memory_store.py +0 -43
- cognite/neat/legacy/graph/stores/_oxigraph_store.py +0 -151
- cognite/neat/legacy/graph/stores/_oxrdflib.py +0 -247
- cognite/neat/legacy/graph/stores/_rdf_to_graph.py +0 -42
- cognite/neat/legacy/graph/transformations/__init__.py +0 -0
- cognite/neat/legacy/graph/transformations/entity_matcher.py +0 -101
- cognite/neat/legacy/graph/transformations/query_generator/__init__.py +0 -3
- cognite/neat/legacy/graph/transformations/query_generator/sparql.py +0 -575
- cognite/neat/legacy/graph/transformations/transformer.py +0 -322
- cognite/neat/legacy/rules/__init__.py +0 -0
- cognite/neat/legacy/rules/analysis.py +0 -231
- cognite/neat/legacy/rules/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
- cognite/neat/legacy/rules/examples/Rules-Nordic44.xlsx +0 -0
- cognite/neat/legacy/rules/examples/__init__.py +0 -18
- cognite/neat/legacy/rules/examples/power-grid-containers.yaml +0 -124
- cognite/neat/legacy/rules/examples/power-grid-example.xlsx +0 -0
- cognite/neat/legacy/rules/examples/power-grid-model.yaml +0 -224
- cognite/neat/legacy/rules/examples/rules-template.xlsx +0 -0
- cognite/neat/legacy/rules/examples/sheet2cdf-transformation-rules.xlsx +0 -0
- cognite/neat/legacy/rules/examples/skos-rules.xlsx +0 -0
- cognite/neat/legacy/rules/examples/source-to-solution-mapping-rules.xlsx +0 -0
- cognite/neat/legacy/rules/examples/wind-energy.owl +0 -1511
- cognite/neat/legacy/rules/exceptions.py +0 -2972
- cognite/neat/legacy/rules/exporters/__init__.py +0 -20
- cognite/neat/legacy/rules/exporters/_base.py +0 -45
- cognite/neat/legacy/rules/exporters/_core/__init__.py +0 -5
- cognite/neat/legacy/rules/exporters/_core/rules2labels.py +0 -24
- cognite/neat/legacy/rules/exporters/_rules2dms.py +0 -885
- cognite/neat/legacy/rules/exporters/_rules2excel.py +0 -213
- cognite/neat/legacy/rules/exporters/_rules2graphql.py +0 -183
- cognite/neat/legacy/rules/exporters/_rules2ontology.py +0 -524
- cognite/neat/legacy/rules/exporters/_rules2pydantic_models.py +0 -748
- cognite/neat/legacy/rules/exporters/_rules2rules.py +0 -105
- cognite/neat/legacy/rules/exporters/_rules2triples.py +0 -38
- cognite/neat/legacy/rules/exporters/_validation.py +0 -146
- cognite/neat/legacy/rules/importers/__init__.py +0 -22
- cognite/neat/legacy/rules/importers/_base.py +0 -66
- cognite/neat/legacy/rules/importers/_dict2rules.py +0 -158
- cognite/neat/legacy/rules/importers/_dms2rules.py +0 -194
- cognite/neat/legacy/rules/importers/_graph2rules.py +0 -308
- cognite/neat/legacy/rules/importers/_json2rules.py +0 -39
- cognite/neat/legacy/rules/importers/_owl2rules/__init__.py +0 -3
- cognite/neat/legacy/rules/importers/_owl2rules/_owl2classes.py +0 -239
- cognite/neat/legacy/rules/importers/_owl2rules/_owl2metadata.py +0 -260
- cognite/neat/legacy/rules/importers/_owl2rules/_owl2properties.py +0 -217
- cognite/neat/legacy/rules/importers/_owl2rules/_owl2rules.py +0 -290
- cognite/neat/legacy/rules/importers/_spreadsheet2rules.py +0 -45
- cognite/neat/legacy/rules/importers/_xsd2rules.py +0 -20
- cognite/neat/legacy/rules/importers/_yaml2rules.py +0 -39
- cognite/neat/legacy/rules/models/__init__.py +0 -5
- cognite/neat/legacy/rules/models/_base.py +0 -151
- cognite/neat/legacy/rules/models/raw_rules.py +0 -316
- cognite/neat/legacy/rules/models/rdfpath.py +0 -237
- cognite/neat/legacy/rules/models/rules.py +0 -1289
- cognite/neat/legacy/rules/models/tables.py +0 -9
- cognite/neat/legacy/rules/models/value_types.py +0 -118
- cognite/neat/legacy/workflows/examples/Export_DMS/workflow.yaml +0 -89
- cognite/neat/legacy/workflows/examples/Export_Rules_to_Ontology/workflow.yaml +0 -152
- cognite/neat/legacy/workflows/examples/Extract_DEXPI_Graph_and_Export_Rules/workflow.yaml +0 -139
- cognite/neat/legacy/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
- cognite/neat/legacy/workflows/examples/Import_DMS/workflow.yaml +0 -65
- cognite/neat/legacy/workflows/examples/Ontology_to_Data_Model/workflow.yaml +0 -116
- cognite/neat/legacy/workflows/examples/Validate_Rules/workflow.yaml +0 -67
- cognite/neat/legacy/workflows/examples/Validate_Solution_Model/workflow.yaml +0 -64
- cognite/neat/legacy/workflows/examples/Visualize_Data_Model_Using_Mock_Graph/workflow.yaml +0 -95
- cognite/neat/legacy/workflows/examples/Visualize_Semantic_Data_Model/workflow.yaml +0 -111
- cognite/neat/workflows/examples/Extract_RDF_Graph_and_Generate_Assets/workflow.yaml +0 -270
- cognite/neat/workflows/migration/__init__.py +0 -0
- cognite/neat/workflows/migration/steps.py +0 -91
- cognite/neat/workflows/migration/wf_manifests.py +0 -33
- cognite/neat/workflows/steps/lib/legacy/__init__.py +0 -7
- cognite/neat/workflows/steps/lib/legacy/graph_contextualization.py +0 -82
- cognite/neat/workflows/steps/lib/legacy/graph_extractor.py +0 -746
- cognite/neat/workflows/steps/lib/legacy/graph_loader.py +0 -606
- cognite/neat/workflows/steps/lib/legacy/graph_store.py +0 -307
- cognite/neat/workflows/steps/lib/legacy/graph_transformer.py +0 -58
- cognite/neat/workflows/steps/lib/legacy/rules_exporter.py +0 -511
- cognite/neat/workflows/steps/lib/legacy/rules_importer.py +0 -612
- {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/LICENSE +0 -0
- {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/WHEEL +0 -0
- {cognite_neat-0.87.4.dist-info → cognite_neat-0.88.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import traceback
|
|
3
|
-
from typing import cast
|
|
4
|
-
|
|
5
|
-
from cognite.client import CogniteClient
|
|
6
|
-
from cognite.client.data_classes import LabelDefinition, LabelDefinitionList
|
|
7
|
-
|
|
8
|
-
from cognite.neat.legacy.rules.exporters._core import get_labels
|
|
9
|
-
from cognite.neat.legacy.rules.models.rules import Rules
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def upload_labels(
|
|
13
|
-
client: CogniteClient,
|
|
14
|
-
rules: Rules,
|
|
15
|
-
data_set_id: int,
|
|
16
|
-
extra_labels: list | None = None,
|
|
17
|
-
stop_on_exception: bool = False,
|
|
18
|
-
):
|
|
19
|
-
"""Generates labels from transformation rules and upload them to CDF
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
client : Instance of CogniteClient
|
|
23
|
-
transformation_rules : Instance of TransformationRules which contains the labels to upload
|
|
24
|
-
data_set_id : Id of the dataset to upload the labels to
|
|
25
|
-
extra_labels : Any additional labels not defined in TransformationRules ,
|
|
26
|
-
by default ["historic", "non-historic"]
|
|
27
|
-
stop_on_exception : If this function fails to stop the process, by default False
|
|
28
|
-
"""
|
|
29
|
-
if extra_labels is None:
|
|
30
|
-
extra_labels = []
|
|
31
|
-
|
|
32
|
-
try:
|
|
33
|
-
logging.debug("Fetching existing labels from CDF")
|
|
34
|
-
# This is to list all labels, not just the ones in the dataset since labels
|
|
35
|
-
# must have unique external_ids, fixing issue that Daniel encountered
|
|
36
|
-
if retrieved_labels := client.labels.list(limit=-1):
|
|
37
|
-
existing_labels = set(retrieved_labels.to_pandas().external_id)
|
|
38
|
-
else:
|
|
39
|
-
existing_labels = set()
|
|
40
|
-
logging.debug(f"Found {len(existing_labels)} existing labels in CDF")
|
|
41
|
-
except Exception as e:
|
|
42
|
-
logging.debug("Error fetching existing labels from CDF, no ")
|
|
43
|
-
traceback.print_exc()
|
|
44
|
-
if stop_on_exception:
|
|
45
|
-
raise e
|
|
46
|
-
existing_labels = set()
|
|
47
|
-
|
|
48
|
-
non_existing_labels = set(list(get_labels(rules)) + extra_labels).difference(existing_labels)
|
|
49
|
-
|
|
50
|
-
if non_existing_labels:
|
|
51
|
-
logging.debug(f"Creating total of {len(existing_labels)} new labels in CDF")
|
|
52
|
-
labels = [
|
|
53
|
-
LabelDefinition(external_id=label, name=label, data_set_id=data_set_id) for label in non_existing_labels
|
|
54
|
-
]
|
|
55
|
-
res = cast(LabelDefinitionList, client.labels.create(labels))
|
|
56
|
-
logging.debug(f"Created total of {len(res)} new labels in CDF")
|
|
57
|
-
else:
|
|
58
|
-
logging.debug("No new labels created in CDF")
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import logging
|
|
4
|
-
from typing import ClassVar
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel, ConfigDict, root_validator, validator
|
|
7
|
-
from rdflib import Namespace
|
|
8
|
-
|
|
9
|
-
from cognite.neat.legacy.rules.models.rules import METADATA_VALUE_MAX_LENGTH
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class AssetClassMapping(BaseModel):
|
|
13
|
-
external_id: str
|
|
14
|
-
name: str
|
|
15
|
-
parent_external_id: str | None = None
|
|
16
|
-
description: str | None = None
|
|
17
|
-
metadata: dict | None = {}
|
|
18
|
-
|
|
19
|
-
@root_validator(pre=True)
|
|
20
|
-
def create_metadata(cls, values: dict):
|
|
21
|
-
fields = values.keys()
|
|
22
|
-
|
|
23
|
-
# adding metadata key in case if it is missing
|
|
24
|
-
values["metadata"] = {} if "metadata" not in values else values["metadata"]
|
|
25
|
-
|
|
26
|
-
for field in fields:
|
|
27
|
-
if field not in ["external_id", "name", "parent_external_id", "data_set_id", "metadata", "description"]:
|
|
28
|
-
values["metadata"][field] = ""
|
|
29
|
-
return values
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class AssetTemplate(BaseModel):
|
|
33
|
-
"""This class is used to validate, repair and wrangle rdf asset dictionary according to the
|
|
34
|
-
expected format of cognite sdk Asset dataclass."""
|
|
35
|
-
|
|
36
|
-
external_id_prefix: str | None = None # convenience field to add prefix to external_ids
|
|
37
|
-
external_id: str
|
|
38
|
-
name: str | None = None
|
|
39
|
-
parent_external_id: str | None = None
|
|
40
|
-
metadata: dict | None = {}
|
|
41
|
-
description: str | None = None
|
|
42
|
-
data_set_id: int | None = None
|
|
43
|
-
|
|
44
|
-
@root_validator(pre=True)
|
|
45
|
-
def preprocess_fields(cls, values: dict):
|
|
46
|
-
fields = values.keys()
|
|
47
|
-
|
|
48
|
-
# Adding metadata key in case if it is missing
|
|
49
|
-
values["metadata"] = {} if "metadata" not in values else values["metadata"]
|
|
50
|
-
|
|
51
|
-
for field in fields:
|
|
52
|
-
# Enrich: adding any field that is not in the list of expected fields to metadata
|
|
53
|
-
if field not in [
|
|
54
|
-
"external_id",
|
|
55
|
-
"name",
|
|
56
|
-
"parent_external_id",
|
|
57
|
-
"data_set_id",
|
|
58
|
-
"metadata",
|
|
59
|
-
"description",
|
|
60
|
-
"external_id_prefix",
|
|
61
|
-
]:
|
|
62
|
-
values["metadata"][field] = values[field]
|
|
63
|
-
|
|
64
|
-
# Repair: in case if name/description is list instead of single value list elements are joined
|
|
65
|
-
elif field in ["name", "description"] and isinstance(values[field], list):
|
|
66
|
-
msg = f"{values['type']} instance {values['identifier']} property {field} "
|
|
67
|
-
msg += f"has multiple values {values[field]}, "
|
|
68
|
-
msg += f"these values will be joined in a single string: {', '.join(values[field])}"
|
|
69
|
-
logging.info(msg)
|
|
70
|
-
values[field] = ", ".join(sorted(values[field]))[: METADATA_VALUE_MAX_LENGTH - 1]
|
|
71
|
-
|
|
72
|
-
# Repair: in case if external_id or parent_external_id are lists, we take the first value
|
|
73
|
-
elif field in ["external_id", "parent_external_id"] and isinstance(values[field], list):
|
|
74
|
-
msg = f"{values['type']} instance {values['identifier']} property {field} "
|
|
75
|
-
msg += f"has multiple values {values[field]}, "
|
|
76
|
-
msg += f"only the first one will be used: {values[field][0]}"
|
|
77
|
-
logging.info(msg)
|
|
78
|
-
values[field] = values[field][0]
|
|
79
|
-
|
|
80
|
-
# Setting asset to be by default active
|
|
81
|
-
values["metadata"]["active"] = "true"
|
|
82
|
-
|
|
83
|
-
# Handling case when the external_id is not provided by defaulting to the original identifier
|
|
84
|
-
# The original identifier probably has its namespace removed
|
|
85
|
-
if "external_id" not in fields and "identifier" in fields:
|
|
86
|
-
values["external_id"] = values["identifier"]
|
|
87
|
-
|
|
88
|
-
return values
|
|
89
|
-
|
|
90
|
-
@validator("metadata")
|
|
91
|
-
def to_list_if_comma(cls, value):
|
|
92
|
-
for key, v in value.items():
|
|
93
|
-
if isinstance(v, list):
|
|
94
|
-
value[key] = ", ".join(sorted(v))[: METADATA_VALUE_MAX_LENGTH - 1]
|
|
95
|
-
return value
|
|
96
|
-
|
|
97
|
-
@validator("metadata")
|
|
98
|
-
def to_str(cls, value):
|
|
99
|
-
for key, v in value.items():
|
|
100
|
-
value[key] = str(v)
|
|
101
|
-
return value
|
|
102
|
-
|
|
103
|
-
@validator("external_id", always=True)
|
|
104
|
-
def add_prefix_to_external_id(cls, value, values):
|
|
105
|
-
if values["external_id_prefix"]:
|
|
106
|
-
return values["external_id_prefix"] + value
|
|
107
|
-
else:
|
|
108
|
-
return value
|
|
109
|
-
|
|
110
|
-
@validator("parent_external_id")
|
|
111
|
-
def add_prefix_to_parent_external_id(cls, value, values):
|
|
112
|
-
if values["external_id_prefix"]:
|
|
113
|
-
return values["external_id_prefix"] + value
|
|
114
|
-
else:
|
|
115
|
-
return value
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
class RelationshipDefinition(BaseModel):
|
|
119
|
-
source_class: str
|
|
120
|
-
target_class: str
|
|
121
|
-
property_: str
|
|
122
|
-
labels: list[str] | None = None
|
|
123
|
-
target_type: str = "Asset"
|
|
124
|
-
source_type: str = "Asset"
|
|
125
|
-
relationship_external_id_rule: str | None = None
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
class RelationshipDefinitions(BaseModel):
|
|
129
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
130
|
-
populate_by_name=True, str_strip_whitespace=True, arbitrary_types_allowed=True, strict=False
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
data_set_id: int
|
|
134
|
-
prefix: str
|
|
135
|
-
namespace: Namespace
|
|
136
|
-
relationships: dict[str, RelationshipDefinition]
|