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

Files changed (160) hide show
  1. cognite/neat/_version.py +1 -1
  2. cognite/neat/app/api/routers/core.py +1 -2
  3. cognite/neat/app/api/routers/data_exploration.py +1 -1
  4. cognite/neat/app/api/routers/rules.py +71 -37
  5. cognite/neat/app/ui/neat-app/build/asset-manifest.json +3 -3
  6. cognite/neat/app/ui/neat-app/build/img/architect-icon.svg +116 -0
  7. cognite/neat/app/ui/neat-app/build/img/developer-icon.svg +112 -0
  8. cognite/neat/app/ui/neat-app/build/img/sme-icon.svg +34 -0
  9. cognite/neat/app/ui/neat-app/build/index.html +1 -1
  10. cognite/neat/app/ui/neat-app/build/static/js/{main.2efd96b2.js → main.25d27396.js} +3 -3
  11. cognite/neat/app/ui/neat-app/build/static/js/{main.2efd96b2.js.map → main.25d27396.js.map} +1 -1
  12. cognite/neat/constants.py +2 -2
  13. cognite/neat/graph/extractors/_mock_graph_generator.py +4 -4
  14. cognite/neat/graph/stores/_base.py +2 -23
  15. cognite/neat/legacy/graph/__init__.py +3 -0
  16. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44-dirty.xml +20182 -0
  17. cognite/neat/legacy/graph/examples/Knowledge-Graph-Nordic44.xml +20163 -0
  18. cognite/neat/legacy/graph/examples/__init__.py +7 -0
  19. cognite/neat/legacy/graph/examples/skos-capturing-sheet-wind-topics.xlsx +0 -0
  20. cognite/neat/legacy/graph/exceptions.py +91 -0
  21. cognite/neat/{graph/extractor → legacy/graph/extractors}/_base.py +1 -1
  22. cognite/neat/{graph/extractor → legacy/graph/extractors}/_dexpi.py +2 -2
  23. cognite/neat/{graph/extractor → legacy/graph/extractors}/_graph_capturing_sheet.py +6 -6
  24. cognite/neat/{graph/extractor → legacy/graph/extractors}/_mock_graph_generator.py +6 -5
  25. cognite/neat/{graph/loader → legacy/graph/loaders}/__init__.py +1 -1
  26. cognite/neat/{graph/loader → legacy/graph/loaders}/_asset_loader.py +3 -3
  27. cognite/neat/{graph/loader → legacy/graph/loaders}/_base.py +4 -4
  28. cognite/neat/{graph/loader → legacy/graph/loaders}/core/labels.py +2 -2
  29. cognite/neat/{graph/loader → legacy/graph/loaders}/core/models.py +1 -1
  30. cognite/neat/{graph/loader → legacy/graph/loaders}/core/rdf_to_assets.py +3 -3
  31. cognite/neat/{graph/loader → legacy/graph/loaders}/core/rdf_to_relationships.py +5 -5
  32. cognite/neat/{graph/loader → legacy/graph/loaders}/rdf_to_dms.py +5 -5
  33. cognite/neat/legacy/graph/models.py +6 -0
  34. cognite/neat/legacy/graph/stores/__init__.py +13 -0
  35. cognite/neat/legacy/graph/stores/_base.py +384 -0
  36. cognite/neat/legacy/graph/stores/_graphdb_store.py +51 -0
  37. cognite/neat/legacy/graph/stores/_memory_store.py +43 -0
  38. cognite/neat/legacy/graph/stores/_oxigraph_store.py +147 -0
  39. cognite/neat/legacy/graph/stores/_oxrdflib.py +247 -0
  40. cognite/neat/legacy/graph/stores/_rdf_to_graph.py +40 -0
  41. cognite/neat/{graph/transformation → legacy/graph/transformations}/entity_matcher.py +1 -1
  42. cognite/neat/{graph/transformation → legacy/graph/transformations}/query_generator/sparql.py +9 -7
  43. cognite/neat/{graph/transformation → legacy/graph/transformations}/transformer.py +12 -5
  44. cognite/neat/legacy/rules/__init__.py +0 -0
  45. cognite/neat/{rules → legacy/rules}/analysis.py +2 -2
  46. cognite/neat/legacy/rules/examples/__init__.py +18 -0
  47. cognite/neat/legacy/rules/examples/wind-energy.owl +1511 -0
  48. cognite/neat/legacy/rules/exceptions.py +2972 -0
  49. cognite/neat/{rules/exporter → legacy/rules/exporters}/_base.py +2 -2
  50. cognite/neat/{rules/exporter → legacy/rules/exporters}/_core/rules2labels.py +1 -1
  51. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2dms.py +6 -6
  52. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2excel.py +1 -1
  53. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2graphql.py +5 -5
  54. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2ontology.py +6 -6
  55. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2pydantic_models.py +8 -8
  56. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2rules.py +3 -2
  57. cognite/neat/{rules/exporter → legacy/rules/exporters}/_rules2triples.py +3 -2
  58. cognite/neat/{rules/exporter → legacy/rules/exporters}/_validation.py +2 -2
  59. cognite/neat/{rules/importer → legacy/rules/importers}/_base.py +2 -2
  60. cognite/neat/{rules/importer → legacy/rules/importers}/_dict2rules.py +1 -1
  61. cognite/neat/{rules/importer → legacy/rules/importers}/_dms2rules.py +2 -2
  62. cognite/neat/{rules/importer → legacy/rules/importers}/_graph2rules.py +5 -4
  63. cognite/neat/{rules/importer → legacy/rules/importers}/_owl2rules/_owl2metadata.py +11 -7
  64. cognite/neat/{rules/importer → legacy/rules/importers}/_owl2rules/_owl2rules.py +5 -5
  65. cognite/neat/{rules/importer → legacy/rules/importers}/_spreadsheet2rules.py +2 -2
  66. cognite/neat/{rules/importer → legacy/rules/importers}/_xsd2rules.py +1 -1
  67. cognite/neat/{rules/importer → legacy/rules/importers}/_yaml2rules.py +1 -1
  68. cognite/neat/{rules → legacy/rules}/models/raw_rules.py +4 -4
  69. cognite/neat/legacy/rules/models/rdfpath.py +238 -0
  70. cognite/neat/{rules → legacy/rules}/models/rules.py +4 -4
  71. cognite/neat/{rules → legacy/rules}/models/value_types.py +1 -1
  72. cognite/neat/rules/_shared.py +1 -1
  73. cognite/neat/rules/analysis/__init__.py +3 -0
  74. cognite/neat/rules/{_analysis → analysis}/_base.py +1 -1
  75. cognite/neat/rules/{_analysis → analysis}/_information_rules.py +3 -3
  76. cognite/neat/rules/examples/__init__.py +0 -9
  77. cognite/neat/rules/exporters/_base.py +1 -1
  78. cognite/neat/rules/exporters/_rules2dms.py +4 -4
  79. cognite/neat/rules/exporters/_rules2excel.py +2 -2
  80. cognite/neat/rules/exporters/_rules2ontology.py +4 -4
  81. cognite/neat/rules/exporters/_rules2yaml.py +1 -1
  82. cognite/neat/rules/exporters/_validation.py +2 -2
  83. cognite/neat/rules/importers/_base.py +1 -1
  84. cognite/neat/rules/importers/_dms2rules.py +10 -10
  85. cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py +2 -2
  86. cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py +3 -3
  87. cognite/neat/rules/importers/_dtdl2rules/spec.py +1 -1
  88. cognite/neat/rules/importers/_owl2rules/_owl2classes.py +1 -1
  89. cognite/neat/rules/importers/_owl2rules/_owl2metadata.py +6 -6
  90. cognite/neat/rules/importers/_owl2rules/_owl2properties.py +1 -1
  91. cognite/neat/rules/importers/_owl2rules/_owl2rules.py +2 -2
  92. cognite/neat/rules/importers/_spreadsheet2rules.py +2 -2
  93. cognite/neat/rules/importers/_yaml2rules.py +1 -1
  94. cognite/neat/rules/models/_entity.py +142 -0
  95. cognite/neat/rules/models/rdfpath.py +6 -8
  96. cognite/neat/rules/models/{_rules → rules}/__init__.py +5 -5
  97. cognite/neat/rules/models/{_rules/base.py → rules/_base.py} +1 -1
  98. cognite/neat/rules/models/{_rules/dms_architect_rules.py → rules/_dms_architect_rules.py} +5 -5
  99. cognite/neat/rules/models/{_rules/dms_schema.py → rules/_dms_schema.py} +1 -1
  100. cognite/neat/rules/models/{_rules/domain_rules.py → rules/_domain_rules.py} +2 -2
  101. cognite/neat/rules/models/{_rules/information_rules.py → rules/_information_rules.py} +18 -15
  102. cognite/neat/rules/models/{_rules → rules}/_types/_base.py +18 -134
  103. cognite/neat/workflows/steps/data_contracts.py +4 -4
  104. cognite/neat/workflows/steps/lib/graph_store.py +1 -1
  105. cognite/neat/workflows/steps/lib/rules_exporter.py +18 -5
  106. cognite/neat/workflows/steps/lib/rules_importer.py +2 -2
  107. cognite/neat/workflows/steps/lib/rules_validator.py +2 -2
  108. cognite/neat/workflows/steps/lib/v1/graph_contextualization.py +1 -1
  109. cognite/neat/workflows/steps/lib/v1/graph_extractor.py +5 -5
  110. cognite/neat/workflows/steps/lib/v1/graph_loader.py +7 -7
  111. cognite/neat/workflows/steps/lib/v1/graph_store.py +7 -1
  112. cognite/neat/workflows/steps/lib/v1/graph_transformer.py +2 -2
  113. cognite/neat/workflows/steps/lib/v1/rules_exporter.py +7 -7
  114. cognite/neat/workflows/steps/lib/v1/rules_importer.py +13 -13
  115. {cognite_neat-0.73.4.dist-info → cognite_neat-0.75.1.dist-info}/METADATA +1 -1
  116. cognite_neat-0.75.1.dist-info/RECORD +258 -0
  117. cognite_neat-0.73.4.dist-info/RECORD +0 -234
  118. /cognite/neat/app/ui/neat-app/build/static/js/{main.2efd96b2.js.LICENSE.txt → main.25d27396.js.LICENSE.txt} +0 -0
  119. /cognite/neat/{graph/loader/core → legacy}/__init__.py +0 -0
  120. /cognite/neat/{graph/extractor → legacy/graph/extractors}/__init__.py +0 -0
  121. /cognite/neat/{graph/loader → legacy/graph/loaders}/_exceptions.py +0 -0
  122. /cognite/neat/{graph/transformation → legacy/graph/loaders/core}/__init__.py +0 -0
  123. /cognite/neat/{graph/loader → legacy/graph/loaders}/validator.py +0 -0
  124. /cognite/neat/{rules/_analysis → legacy/graph/transformations}/__init__.py +0 -0
  125. /cognite/neat/{graph/transformation → legacy/graph/transformations}/query_generator/__init__.py +0 -0
  126. /cognite/neat/{rules → legacy/rules}/examples/Rules-Nordic44-to-TNT.xlsx +0 -0
  127. /cognite/neat/{rules → legacy/rules}/examples/Rules-Nordic44-to-graphql.xlsx +0 -0
  128. /cognite/neat/{rules → legacy/rules}/examples/power-grid-containers.yaml +0 -0
  129. /cognite/neat/{rules → legacy/rules}/examples/power-grid-example.xlsx +0 -0
  130. /cognite/neat/{rules → legacy/rules}/examples/power-grid-model.yaml +0 -0
  131. /cognite/neat/{rules → legacy/rules}/examples/rules-template.xlsx +0 -0
  132. /cognite/neat/{rules → legacy/rules}/examples/sheet2cdf-transformation-rules.xlsx +0 -0
  133. /cognite/neat/{rules → legacy/rules}/examples/skos-rules.xlsx +0 -0
  134. /cognite/neat/{rules → legacy/rules}/examples/source-to-solution-mapping-rules.xlsx +0 -0
  135. /cognite/neat/{rules/exporter → legacy/rules/exporters}/__init__.py +0 -0
  136. /cognite/neat/{rules/exporter → legacy/rules/exporters}/_core/__init__.py +0 -0
  137. /cognite/neat/{rules/importer → legacy/rules/importers}/__init__.py +0 -0
  138. /cognite/neat/{rules/importer → legacy/rules/importers}/_json2rules.py +0 -0
  139. /cognite/neat/{rules/importer → legacy/rules/importers}/_owl2rules/__init__.py +0 -0
  140. /cognite/neat/{rules/importer → legacy/rules/importers}/_owl2rules/_owl2classes.py +0 -0
  141. /cognite/neat/{rules/importer → legacy/rules/importers}/_owl2rules/_owl2properties.py +0 -0
  142. /cognite/neat/{rules → legacy/rules}/models/__init__.py +0 -0
  143. /cognite/neat/{rules → legacy/rules}/models/_base.py +0 -0
  144. /cognite/neat/{rules → legacy/rules}/models/tables.py +0 -0
  145. /cognite/neat/rules/models/{_rules → rules}/_types/__init__.py +0 -0
  146. /cognite/neat/rules/models/{_rules → rules}/_types/_field.py +0 -0
  147. /cognite/neat/rules/models/{_rules → rules}/_types/_value.py +0 -0
  148. /cognite/neat/workflows/examples/{Export DMS → Export_DMS}/workflow.yaml +0 -0
  149. /cognite/neat/workflows/examples/{Export Rules to Ontology → Export_Rules_to_Ontology}/workflow.yaml +0 -0
  150. /cognite/neat/workflows/examples/{Extract DEXPI Graph and Export Rules → Extract_DEXPI_Graph_and_Export_Rules}/workflow.yaml +0 -0
  151. /cognite/neat/workflows/examples/{Extract RDF Graph and Generate Assets → Extract_RDF_Graph_and_Generate_Assets}/workflow.yaml +0 -0
  152. /cognite/neat/workflows/examples/{Import DMS → Import_DMS}/workflow.yaml +0 -0
  153. /cognite/neat/workflows/examples/{Ontology to Data Model → Ontology_to_Data_Model}/workflow.yaml +0 -0
  154. /cognite/neat/workflows/examples/{Validate Rules → Validate_Rules}/workflow.yaml +0 -0
  155. /cognite/neat/workflows/examples/{Validate Solution Model → Validate_Solution_Model}/workflow.yaml +0 -0
  156. /cognite/neat/workflows/examples/{Visualize Data Model Using Mock Graph → Visualize_Data_Model_Using_Mock_Graph}/workflow.yaml +0 -0
  157. /cognite/neat/workflows/examples/{Visualize Semantic Data Model → Visualize_Semantic_Data_Model}/workflow.yaml +0 -0
  158. {cognite_neat-0.73.4.dist-info → cognite_neat-0.75.1.dist-info}/LICENSE +0 -0
  159. {cognite_neat-0.73.4.dist-info → cognite_neat-0.75.1.dist-info}/WHEEL +0 -0
  160. {cognite_neat-0.73.4.dist-info → cognite_neat-0.75.1.dist-info}/entry_points.txt +0 -0
@@ -3,8 +3,8 @@ from abc import ABC, abstractmethod
3
3
  from pathlib import Path
4
4
  from typing import Generic, TypeVar
5
5
 
6
- from cognite.neat.rules.models.raw_rules import RawRules
7
- from cognite.neat.rules.models.rules import Rules
6
+ from cognite.neat.legacy.rules.models.raw_rules import RawRules
7
+ from cognite.neat.legacy.rules.models.rules import Rules
8
8
 
9
9
  if sys.version_info >= (3, 11):
10
10
  from typing import Self
@@ -1,4 +1,4 @@
1
- from cognite.neat.rules.models.rules import Rules
1
+ from cognite.neat.legacy.rules.models.rules import Rules
2
2
 
3
3
 
4
4
  def get_labels(transformation_rules: Rules) -> set[str]:
@@ -10,7 +10,7 @@ from typing import ClassVar, Literal, cast, no_type_check
10
10
 
11
11
  import yaml
12
12
 
13
- from cognite.neat.rules.models.value_types import ValueTypeMapping
13
+ from cognite.neat.legacy.rules.models.value_types import ValueTypeMapping
14
14
 
15
15
  if sys.version_info >= (3, 11):
16
16
  from typing import Self
@@ -41,11 +41,11 @@ from cognite.client.data_classes.data_modeling.views import (
41
41
  from cognite.client.exceptions import CogniteAPIError
42
42
  from pydantic import BaseModel, ConfigDict, field_validator
43
43
 
44
- from cognite.neat.rules import exceptions
45
- from cognite.neat.rules.exporter._base import BaseExporter
46
- from cognite.neat.rules.exporter._validation import are_entity_names_dms_compliant
47
- from cognite.neat.rules.models._base import ContainerEntity, EntityTypes, ParentClass
48
- from cognite.neat.rules.models.rules import Class, Property, Rules
44
+ from cognite.neat.legacy.rules import exceptions
45
+ from cognite.neat.legacy.rules.exporters._base import BaseExporter
46
+ from cognite.neat.legacy.rules.exporters._validation import are_entity_names_dms_compliant
47
+ from cognite.neat.legacy.rules.models._base import ContainerEntity, EntityTypes, ParentClass
48
+ from cognite.neat.legacy.rules.models.rules import Class, Property, Rules
49
49
  from cognite.neat.utils.utils import generate_exception_report
50
50
 
51
51
  if sys.version_info < (3, 11):
@@ -6,7 +6,7 @@ from openpyxl.cell import Cell
6
6
  from openpyxl.styles import Alignment, Border, Font, NamedStyle, PatternFill, Side
7
7
  from openpyxl.worksheet.worksheet import Worksheet
8
8
 
9
- from cognite.neat.rules.models._base import EntityTypes
9
+ from cognite.neat.legacy.rules.models._base import EntityTypes
10
10
 
11
11
  from ._base import BaseExporter
12
12
 
@@ -9,11 +9,11 @@ if sys.version_info >= (3, 11):
9
9
  else:
10
10
  from typing_extensions import Self
11
11
 
12
- from cognite.neat.rules import exceptions
13
- from cognite.neat.rules.analysis import to_class_property_pairs
14
- from cognite.neat.rules.exporter._validation import are_entity_names_dms_compliant, are_properties_redefined
15
- from cognite.neat.rules.models.rules import Rules
16
- from cognite.neat.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
12
+ from cognite.neat.legacy.rules import exceptions
13
+ from cognite.neat.legacy.rules.analysis import to_class_property_pairs
14
+ from cognite.neat.legacy.rules.exporters._validation import are_entity_names_dms_compliant, are_properties_redefined
15
+ from cognite.neat.legacy.rules.models.rules import Rules
16
+ from cognite.neat.legacy.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
17
17
  from cognite.neat.utils.utils import generate_exception_report
18
18
 
19
19
  from ._base import BaseExporter
@@ -8,12 +8,12 @@ from pydantic import BaseModel, ConfigDict, ValidationInfo, field_validator
8
8
  from rdflib import DCTERMS, OWL, RDF, RDFS, XSD, BNode, Graph, Literal, Namespace, URIRef
9
9
  from rdflib.collection import Collection as GraphCollection
10
10
 
11
- from cognite.neat.rules import exceptions
12
- from cognite.neat.rules.analysis import to_class_property_pairs, to_property_dict
13
- from cognite.neat.rules.exporter._base import BaseExporter
14
- from cognite.neat.rules.exporter._validation import are_properties_redefined
15
- from cognite.neat.rules.models.rules import Class, Metadata, Property, Rules
16
- from cognite.neat.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
11
+ from cognite.neat.legacy.rules import exceptions
12
+ from cognite.neat.legacy.rules.analysis import to_class_property_pairs, to_property_dict
13
+ from cognite.neat.legacy.rules.exporters._base import BaseExporter
14
+ from cognite.neat.legacy.rules.exporters._validation import are_properties_redefined
15
+ from cognite.neat.legacy.rules.models.rules import Class, Metadata, Property, Rules
16
+ from cognite.neat.legacy.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
17
17
  from cognite.neat.utils.utils import generate_exception_report, remove_namespace
18
18
 
19
19
  if sys.version_info >= (3, 11):
@@ -13,14 +13,14 @@ from pydantic._internal._model_construction import ModelMetaclass
13
13
  from rdflib import Graph, URIRef
14
14
  from typing_extensions import TypeAliasType
15
15
 
16
- from cognite.neat.graph.loader.core.rdf_to_assets import NeatMetadataKeys
17
- from cognite.neat.graph.transformation.query_generator.sparql import build_construct_query, triples2dictionary
18
- from cognite.neat.rules import exceptions
19
- from cognite.neat.rules.analysis import define_class_asset_mapping, to_class_property_pairs
20
- from cognite.neat.rules.exporter._rules2dms import DMSSchemaComponents
21
- from cognite.neat.rules.exporter._validation import are_entity_names_dms_compliant
22
- from cognite.neat.rules.models.rules import Property, Rules
23
- from cognite.neat.rules.models.value_types import ValueTypeMapping
16
+ from cognite.neat.legacy.graph.loaders.core.rdf_to_assets import NeatMetadataKeys
17
+ from cognite.neat.legacy.graph.transformations.query_generator.sparql import build_construct_query, triples2dictionary
18
+ from cognite.neat.legacy.rules import exceptions
19
+ from cognite.neat.legacy.rules.analysis import define_class_asset_mapping, to_class_property_pairs
20
+ from cognite.neat.legacy.rules.exporters._rules2dms import DMSSchemaComponents
21
+ from cognite.neat.legacy.rules.exporters._validation import are_entity_names_dms_compliant
22
+ from cognite.neat.legacy.rules.models.rules import Property, Rules
23
+ from cognite.neat.legacy.rules.models.value_types import ValueTypeMapping
24
24
  from cognite.neat.utils.utils import generate_exception_report
25
25
 
26
26
  if sys.version_info >= (3, 11):
@@ -4,13 +4,14 @@ to TransformationRules for purpose of for example:
4
4
  - subsetting the data model to only include desired classes and their properties
5
5
  - converting classes/properties ids/names to DMS compliant format
6
6
  """
7
+
7
8
  import logging
8
9
  import re
9
10
  import warnings
10
11
  from typing import Any
11
12
 
12
- from cognite.neat.rules.analysis import get_defined_classes
13
- from cognite.neat.rules.models.rules import Rules
13
+ from cognite.neat.legacy.rules.analysis import get_defined_classes
14
+ from cognite.neat.legacy.rules.models.rules import Rules
14
15
 
15
16
 
16
17
  def subset_rules(rules: Rules, desired_classes: set, skip_validation: bool = False) -> Rules:
@@ -2,8 +2,9 @@ from pathlib import Path
2
2
 
3
3
  from rdflib.term import Node
4
4
 
5
- from cognite.neat.rules.exporter._base import BaseExporter
6
- from cognite.neat.rules.models.rules import Rules
5
+ from cognite.neat.legacy.rules.models.rules import Rules
6
+
7
+ from ._base import BaseExporter
7
8
 
8
9
 
9
10
  class TripleExporter(BaseExporter[list[tuple[Node, Node, Node]]]):
@@ -3,8 +3,8 @@ import warnings
3
3
  from typing import Literal, overload
4
4
 
5
5
  from cognite.neat.exceptions import wrangle_warnings
6
- from cognite.neat.rules import exceptions
7
- from cognite.neat.rules.models.rules import (
6
+ from cognite.neat.legacy.rules import exceptions
7
+ from cognite.neat.legacy.rules.models.rules import (
8
8
  Rules,
9
9
  dms_property_id_compliance_regex,
10
10
  value_id_compliance_regex,
@@ -5,8 +5,8 @@ from datetime import datetime
5
5
  import pandas as pd
6
6
  from pydantic_core import ErrorDetails
7
7
 
8
- from cognite.neat.rules.models.raw_rules import RawRules
9
- from cognite.neat.rules.models.rules import Rules
8
+ from cognite.neat.legacy.rules.models.raw_rules import RawRules
9
+ from cognite.neat.legacy.rules.models.rules import Rules
10
10
 
11
11
 
12
12
  class BaseImporter(ABC):
@@ -3,7 +3,7 @@ from typing import Any, Literal
3
3
 
4
4
  import pandas as pd
5
5
 
6
- from cognite.neat.rules.models.tables import Tables
6
+ from cognite.neat.legacy.rules.models.tables import Tables
7
7
 
8
8
  from ._base import BaseImporter
9
9
 
@@ -15,8 +15,8 @@ from cognite.client.data_classes.data_modeling import (
15
15
  )
16
16
  from cognite.client.data_classes.data_modeling.ids import DataModelIdentifier, ViewId
17
17
 
18
- from cognite.neat.rules.models.tables import Tables
19
- from cognite.neat.rules.models.value_types import DMS_VALUE_TYPE_MAPPINGS, XSD_VALUE_TYPE_MAPPINGS
18
+ from cognite.neat.legacy.rules.models.tables import Tables
19
+ from cognite.neat.legacy.rules.models.value_types import DMS_VALUE_TYPE_MAPPINGS, XSD_VALUE_TYPE_MAPPINGS
20
20
 
21
21
  from ._base import BaseImporter
22
22
 
@@ -11,12 +11,13 @@ import pandas as pd
11
11
  from rdflib import Graph, Literal, Namespace, URIRef
12
12
 
13
13
  from cognite.neat.constants import PREFIXES
14
- from cognite.neat.rules import exceptions
15
- from cognite.neat.rules.exporter._rules2rules import to_dms_name
16
- from cognite.neat.rules.importer._base import BaseImporter
17
- from cognite.neat.rules.models.tables import Tables
14
+ from cognite.neat.legacy.rules import exceptions
15
+ from cognite.neat.legacy.rules.exporters._rules2rules import to_dms_name
16
+ from cognite.neat.legacy.rules.models.tables import Tables
18
17
  from cognite.neat.utils.utils import get_namespace, remove_namespace, uri_to_short_form
19
18
 
19
+ from ._base import BaseImporter
20
+
20
21
 
21
22
  class GraphImporter(BaseImporter):
22
23
  """
@@ -4,7 +4,7 @@ import re
4
4
  import pandas as pd
5
5
  from rdflib import Graph, Namespace
6
6
 
7
- from cognite.neat.rules.models.rules import (
7
+ from cognite.neat.legacy.rules.models.rules import (
8
8
  cdf_space_compliance_regex,
9
9
  data_model_id_compliance_regex,
10
10
  prefix_compliance_regex,
@@ -66,12 +66,16 @@ def parse_owl_metadata(graph: Graph, make_compliant: bool = False) -> pd.DataFra
66
66
  "updated": results[7].pop(),
67
67
  "title": results[8].pop(),
68
68
  "description": results[9].pop(),
69
- "creator": ", ".join(remove_none_elements_from_set(results[10]))
70
- if remove_none_elements_from_set(results[10])
71
- else None,
72
- "contributor": ", ".join(remove_none_elements_from_set(results[11]))
73
- if remove_none_elements_from_set(results[11])
74
- else None,
69
+ "creator": (
70
+ ", ".join(remove_none_elements_from_set(results[10]))
71
+ if remove_none_elements_from_set(results[10])
72
+ else None
73
+ ),
74
+ "contributor": (
75
+ ", ".join(remove_none_elements_from_set(results[11]))
76
+ if remove_none_elements_from_set(results[11])
77
+ else None
78
+ ),
75
79
  "rights": results[12].pop(),
76
80
  "license": results[13].pop(),
77
81
  }
@@ -9,11 +9,11 @@ import pandas as pd
9
9
  from pydantic_core import ErrorDetails
10
10
  from rdflib import DC, DCTERMS, OWL, RDF, RDFS, SKOS, Graph
11
11
 
12
- from cognite.neat.rules.importer._base import BaseImporter
13
- from cognite.neat.rules.models.raw_rules import RawRules
14
- from cognite.neat.rules.models.rules import Rules
15
- from cognite.neat.rules.models.tables import Tables
16
- from cognite.neat.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
12
+ from cognite.neat.legacy.rules.importers._base import BaseImporter
13
+ from cognite.neat.legacy.rules.models.raw_rules import RawRules
14
+ from cognite.neat.legacy.rules.models.rules import Rules
15
+ from cognite.neat.legacy.rules.models.tables import Tables
16
+ from cognite.neat.legacy.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS
17
17
 
18
18
  from ._owl2classes import parse_owl_classes
19
19
  from ._owl2metadata import parse_owl_metadata
@@ -3,15 +3,15 @@ In more details, it traverses the graph and abstracts class and properties, basi
3
3
  generating a list of rules based on which nodes that form the graph are made.
4
4
  """
5
5
 
6
-
7
6
  from pathlib import Path
8
7
 
9
8
  import pandas as pd
10
9
  from openpyxl import Workbook, load_workbook
11
10
 
12
- from cognite.neat.rules.importer._base import BaseImporter
13
11
  from cognite.neat.utils.auxiliary import local_import
14
12
 
13
+ from ._base import BaseImporter
14
+
15
15
 
16
16
  class ExcelImporter(BaseImporter):
17
17
  def __init__(self, filepath: Path):
@@ -2,7 +2,7 @@ from pathlib import Path
2
2
 
3
3
  import pandas as pd
4
4
 
5
- from cognite.neat.rules.importer._base import BaseImporter
5
+ from ._base import BaseImporter
6
6
 
7
7
 
8
8
  class XSDImporter(BaseImporter):
@@ -3,7 +3,7 @@ from typing import Literal
3
3
 
4
4
  import yaml
5
5
 
6
- from cognite.neat.rules.importer._dict2rules import ArbitraryDictImporter
6
+ from ._dict2rules import ArbitraryDictImporter
7
7
 
8
8
 
9
9
  class ArbitraryYAMLImporter(ArbitraryDictImporter):
@@ -12,12 +12,12 @@ from rdflib import Namespace
12
12
  from cognite.neat.constants import PREFIXES
13
13
  from cognite.neat.exceptions import wrangle_warnings
14
14
 
15
+ # rules model and model components:
16
+ from cognite.neat.legacy.rules.models.rules import Class, Metadata, Property, RuleModel, Rules
17
+ from cognite.neat.legacy.rules.models.tables import Tables
18
+
15
19
  # importers:
16
20
  from cognite.neat.rules import exceptions
17
-
18
- # rules model and model components:
19
- from cognite.neat.rules.models.rules import Class, Metadata, Property, RuleModel, Rules
20
- from cognite.neat.rules.models.tables import Tables
21
21
  from cognite.neat.utils.utils import generate_exception_report
22
22
 
23
23
  __all__ = ["RawRules"]
@@ -0,0 +1,238 @@
1
+ """
2
+ """
3
+
4
+ import re
5
+ import sys
6
+ from collections import Counter
7
+ from typing import Literal
8
+
9
+ from pydantic import BaseModel, field_validator
10
+
11
+ from cognite.neat.legacy.rules import exceptions
12
+
13
+ from ._base import (
14
+ CLASS_ID_REGEX,
15
+ CLASS_ID_REGEX_COMPILED,
16
+ ENTITY_ID_REGEX,
17
+ PROPERTY_ID_REGEX,
18
+ SUFFIX_REGEX,
19
+ Entity,
20
+ EntityTypes,
21
+ )
22
+
23
+ if sys.version_info >= (3, 11):
24
+ from enum import StrEnum
25
+ from typing import Self
26
+ else:
27
+ from backports.strenum import StrEnum
28
+ from typing_extensions import Self
29
+
30
+
31
+ class TransformationRuleType(StrEnum):
32
+ rdfpath = "rdfpath"
33
+ rawlookup = "rawlookup"
34
+ sparql = "sparql"
35
+
36
+
37
+ class Lookup(StrEnum):
38
+ table = "table"
39
+ key = "key"
40
+ value = "value" # type: ignore
41
+
42
+
43
+ # traversal direction
44
+ DIRECTION_REGEX = r"(?P<direction>(->|<-))"
45
+
46
+ # steps
47
+ STEP_REGEX = rf"((->|<-){CLASS_ID_REGEX}({PROPERTY_ID_REGEX})?)"
48
+ STEP_REGEX_COMPILED = re.compile(STEP_REGEX)
49
+ STEP_CLASS_REGEX_COMPILED = re.compile(rf"(^{DIRECTION_REGEX}{CLASS_ID_REGEX})$")
50
+ STEP_CLASS_AND_PROPERTY_REGEX_COMPILED = re.compile(rf"(^{DIRECTION_REGEX}{CLASS_ID_REGEX}{PROPERTY_ID_REGEX}$)")
51
+
52
+
53
+ _traversal = "traversal"
54
+ ORIGIN_REGEX = rf"(?P<origin>{ENTITY_ID_REGEX})"
55
+
56
+ HOP_REGEX_COMPILED = re.compile(rf"^{ORIGIN_REGEX}(?P<{_traversal}>{STEP_REGEX}+)$")
57
+
58
+ # grabbing specific property for a class, property can be either object, annotation or data property
59
+ SINGLE_PROPERTY_REGEX_COMPILED = re.compile(rf"^{CLASS_ID_REGEX}{PROPERTY_ID_REGEX}$")
60
+
61
+ # grabbing all properties for a class
62
+ ALL_PROPERTIES_REGEX_COMPILED = re.compile(rf"^{CLASS_ID_REGEX}\(\*\)$")
63
+
64
+ ALL_TRAVERSAL_REGEX_COMPILED = (
65
+ rf"({CLASS_ID_REGEX}\(\*\)|{CLASS_ID_REGEX}{PROPERTY_ID_REGEX}|{ORIGIN_REGEX}(?P<{_traversal}>{STEP_REGEX}+))"
66
+ )
67
+
68
+ TABLE_REGEX_COMPILED = re.compile(
69
+ rf"^(?P<{Lookup.table}>{SUFFIX_REGEX})\((?P<{Lookup.key}>{SUFFIX_REGEX}),\s*(?P<{Lookup.value}>{SUFFIX_REGEX})\)$"
70
+ )
71
+
72
+
73
+ StepDirection = Literal["source", "target", "origin"]
74
+ _direction_by_symbol: dict[str, StepDirection] = {"->": "target", "<-": "source"}
75
+
76
+
77
+ class Step(BaseModel):
78
+ class_: Entity
79
+ property: Entity | None = None # only terminal step has property
80
+ direction: StepDirection
81
+
82
+ @classmethod
83
+ def from_string(cls, raw: str, **kwargs) -> Self:
84
+ if result := STEP_CLASS_AND_PROPERTY_REGEX_COMPILED.match(raw):
85
+ return cls(
86
+ class_=Entity.from_string(result.group(EntityTypes.class_), type_="class"),
87
+ property=Entity.from_string(result.group(EntityTypes.property_), type_="property"),
88
+ direction=_direction_by_symbol[result.group("direction")],
89
+ **kwargs,
90
+ )
91
+ elif result := STEP_CLASS_REGEX_COMPILED.match(raw):
92
+ return cls(
93
+ class_=Entity.from_string(result.group(EntityTypes.class_)),
94
+ direction=_direction_by_symbol[result.group("direction")],
95
+ ) # type: ignore
96
+ msg = f"Invalid step {raw}, expected in one of the following forms:"
97
+ msg += " ->prefix:suffix, <-prefix:suffix, ->prefix:suffix(prefix:suffix) or <-prefix:suffix(prefix:suffix)"
98
+ raise ValueError(msg)
99
+
100
+
101
+ class Traversal(BaseModel):
102
+ class_: Entity
103
+
104
+
105
+ class SingleProperty(Traversal):
106
+ property: Entity
107
+
108
+ @classmethod
109
+ def from_string(cls, class_: str, property_: str) -> Self:
110
+ return cls(
111
+ class_=Entity.from_string(class_, type_="class"), property=Entity.from_string(property_, type_="property")
112
+ )
113
+
114
+
115
+ class AllReferences(Traversal):
116
+ @classmethod
117
+ def from_string(cls, class_: str) -> Self:
118
+ return cls(class_=Entity.from_string(class_, type_="class"))
119
+
120
+
121
+ class AllProperties(Traversal):
122
+ @classmethod
123
+ def from_string(cls, class_: str) -> Self:
124
+ return cls(class_=Entity.from_string(class_, type_="class"))
125
+
126
+
127
+ class Origin(BaseModel):
128
+ class_: Entity
129
+
130
+ @field_validator("class_", mode="before")
131
+ def process_if_string(cls, value):
132
+ return Entity.from_string(value) if isinstance(value, str) else value
133
+
134
+
135
+ class Hop(Traversal):
136
+ """Multi or single hop traversal through graph"""
137
+
138
+ traversal: list[Step]
139
+
140
+ @classmethod
141
+ def from_string(cls, class_: str, traversal: str | list[Step]) -> Self:
142
+ return cls(
143
+ class_=Entity.from_string(class_),
144
+ traversal=(
145
+ [Step.from_string(result[0]) for result in STEP_REGEX_COMPILED.findall(traversal)]
146
+ if isinstance(traversal, str)
147
+ else traversal
148
+ ),
149
+ )
150
+
151
+
152
+ class TableLookup(BaseModel):
153
+ name: str
154
+ key: str
155
+ value: str
156
+
157
+
158
+ class Rule(BaseModel):
159
+ pass
160
+
161
+
162
+ class Query(BaseModel):
163
+ query: str
164
+
165
+
166
+ class RDFPath(Rule):
167
+ traversal: Traversal | Query
168
+
169
+
170
+ class RawLookup(RDFPath):
171
+ table: TableLookup
172
+
173
+
174
+ class SPARQLQuery(RDFPath):
175
+ traversal: Query
176
+
177
+
178
+ def parse_traversal(raw: str) -> AllReferences | AllProperties | SingleProperty | Hop:
179
+ if result := CLASS_ID_REGEX_COMPILED.match(raw):
180
+ return AllReferences.from_string(class_=result.group(EntityTypes.class_))
181
+ elif result := ALL_PROPERTIES_REGEX_COMPILED.match(raw):
182
+ return AllProperties.from_string(class_=result.group(EntityTypes.class_))
183
+ elif result := SINGLE_PROPERTY_REGEX_COMPILED.match(raw):
184
+ return SingleProperty.from_string(
185
+ class_=result.group(EntityTypes.class_), property_=result.group(EntityTypes.property_)
186
+ )
187
+ elif result := HOP_REGEX_COMPILED.match(raw):
188
+ return Hop.from_string(class_=result.group("origin"), traversal=result.group(_traversal))
189
+ else:
190
+ raise exceptions.NotValidRDFPath(raw).to_pydantic_custom_error()
191
+
192
+
193
+ def parse_table_lookup(raw: str) -> TableLookup:
194
+ if result := TABLE_REGEX_COMPILED.match(raw):
195
+ return TableLookup(
196
+ name=result.group(Lookup.table), key=result.group(Lookup.key), value=result.group(Lookup.value)
197
+ )
198
+ raise exceptions.NotValidTableLookUp(raw).to_pydantic_custom_error()
199
+
200
+
201
+ def parse_rule(rule_raw: str, rule_type: TransformationRuleType | None) -> RDFPath:
202
+ match rule_type:
203
+ case TransformationRuleType.rdfpath:
204
+ rule_raw = rule_raw.replace(" ", "")
205
+ return RDFPath(traversal=parse_traversal(rule_raw))
206
+ case TransformationRuleType.rawlookup:
207
+ rule_raw = rule_raw.replace(" ", "")
208
+ if Counter(rule_raw).get("|") != 1:
209
+ raise exceptions.NotValidRAWLookUp(rule_raw).to_pydantic_custom_error()
210
+ traversal, table_lookup = rule_raw.split("|")
211
+ return RawLookup(traversal=parse_traversal(traversal), table=parse_table_lookup(table_lookup))
212
+ case TransformationRuleType.sparql:
213
+ return SPARQLQuery(traversal=Query(query=rule_raw))
214
+ case None:
215
+ raise ValueError("Rule type must be specified")
216
+
217
+
218
+ def is_valid_rule(rule_type: TransformationRuleType, rule_raw: str) -> bool:
219
+ is_valid_rule = {TransformationRuleType.rdfpath: is_rdfpath, TransformationRuleType.rawlookup: is_rawlookup}[
220
+ rule_type
221
+ ]
222
+ return is_valid_rule(rule_raw)
223
+
224
+
225
+ def is_rdfpath(raw: str) -> bool:
226
+ try:
227
+ parse_traversal(raw)
228
+ except ValueError:
229
+ return False
230
+ return True
231
+
232
+
233
+ def is_rawlookup(raw: str) -> bool:
234
+ try:
235
+ parse_rule(raw, TransformationRuleType.rawlookup)
236
+ except ValueError:
237
+ return False
238
+ return True
@@ -30,15 +30,15 @@ from pydantic.fields import FieldInfo
30
30
  from rdflib import XSD, Literal, Namespace, URIRef
31
31
 
32
32
  from cognite.neat.constants import PREFIXES
33
- from cognite.neat.rules import exceptions
34
- from cognite.neat.rules.models._base import (
33
+ from cognite.neat.legacy.rules import exceptions
34
+ from cognite.neat.legacy.rules.models._base import (
35
35
  ENTITY_ID_REGEX_COMPILED,
36
36
  VERSIONED_ENTITY_REGEX_COMPILED,
37
37
  ContainerEntity,
38
38
  EntityTypes,
39
39
  ParentClass,
40
40
  )
41
- from cognite.neat.rules.models.rdfpath import (
41
+ from cognite.neat.legacy.rules.models.rdfpath import (
42
42
  AllReferences,
43
43
  Entity,
44
44
  Hop,
@@ -49,7 +49,7 @@ from cognite.neat.rules.models.rdfpath import (
49
49
  Traversal,
50
50
  parse_rule,
51
51
  )
52
- from cognite.neat.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS, ValueType
52
+ from cognite.neat.legacy.rules.models.value_types import XSD_VALUE_TYPE_MAPPINGS, ValueType
53
53
 
54
54
  if sys.version_info >= (3, 11):
55
55
  from typing import Self
@@ -19,7 +19,7 @@ from cognite.client.data_classes.data_modeling import (
19
19
  )
20
20
  from pydantic import BaseModel
21
21
 
22
- from cognite.neat.rules.models._base import Entity, EntityTypes
22
+ from cognite.neat.legacy.rules.models._base import Entity, EntityTypes
23
23
 
24
24
 
25
25
  class ValueTypeMapping(BaseModel):
@@ -1,5 +1,5 @@
1
1
  from typing import TypeAlias
2
2
 
3
- from cognite.neat.rules.models._rules import DMSRules, DomainRules, InformationRules
3
+ from cognite.neat.rules.models.rules import DMSRules, DomainRules, InformationRules
4
4
 
5
5
  Rules: TypeAlias = DomainRules | InformationRules | DMSRules
@@ -0,0 +1,3 @@
1
+ from ._information_rules import InformationArchitectRulesAnalysis
2
+
3
+ __all__ = ["InformationArchitectRulesAnalysis"]
@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
3
3
  from typing import Generic, TypeVar
4
4
 
5
5
  from cognite.neat.rules._shared import Rules
6
- from cognite.neat.rules.models._rules._types import ClassEntity
6
+ from cognite.neat.rules.models.rules._types import ClassEntity
7
7
 
8
8
  if sys.version_info >= (3, 11):
9
9
  from enum import StrEnum
@@ -7,10 +7,10 @@ from typing import Any, cast
7
7
  import pandas as pd
8
8
  from pydantic import ValidationError
9
9
 
10
- from cognite.neat.rules.models._rules._types._base import ClassEntity, EntityTypes, ParentClassEntity, ReferenceEntity
11
- from cognite.neat.rules.models._rules.base import SchemaCompleteness
12
- from cognite.neat.rules.models._rules.information_rules import InformationClass, InformationProperty, InformationRules
13
10
  from cognite.neat.rules.models.rdfpath import TransformationRuleType
11
+ from cognite.neat.rules.models.rules._base import SchemaCompleteness
12
+ from cognite.neat.rules.models.rules._information_rules import InformationClass, InformationProperty, InformationRules
13
+ from cognite.neat.rules.models.rules._types._base import ClassEntity, EntityTypes, ParentClassEntity, ReferenceEntity
14
14
  from cognite.neat.utils.utils import get_inheritance_path
15
15
 
16
16
  from ._base import BaseAnalysis, DataModelingScenario
@@ -6,13 +6,4 @@ from pathlib import Path
6
6
  # Currently there are simple paths to the examples which are then easily loaded in the notebooks
7
7
 
8
8
  _EXAMPLES = Path(__file__).parent
9
-
10
- power_grid_model = _EXAMPLES / "power-grid-example.xlsx"
11
- power_grid_containers = _EXAMPLES / "power-grid-containers.yaml"
12
- power_grid_data_model = _EXAMPLES / "power-grid-model.yaml"
13
- simple_example = _EXAMPLES / "sheet2cdf-transformation-rules.xlsx"
14
- source_to_solution_mapping = _EXAMPLES / "source-to-solution-mapping-rules.xlsx"
15
- nordic44 = _EXAMPLES / "Rules-Nordic44-to-TNT.xlsx"
16
- nordic44_graphql = _EXAMPLES / "Rules-Nordic44-to-graphql.xlsx"
17
- skos = _EXAMPLES / "skos-rules.xlsx"
18
9
  wind_energy_ontology = _EXAMPLES / "wind-energy.owl"