cognite-neat 0.127.24__py3-none-any.whl → 0.127.26__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.
@@ -1,10 +1,11 @@
1
+ import itertools
1
2
  from collections import UserList
2
3
  from dataclasses import dataclass, field
3
4
  from datetime import datetime
4
5
  from typing import Any
5
6
 
6
7
  from cognite.neat._data_model.deployer.data_classes import DeploymentResult
7
- from cognite.neat._issues import IssueList
8
+ from cognite.neat._issues import ConsistencyError, IssueList, ModelSyntaxError
8
9
  from cognite.neat._state_machine import State
9
10
 
10
11
 
@@ -35,6 +36,15 @@ class Change:
35
36
  """Check if change was successful"""
36
37
  return not self.errors
37
38
 
39
+ @property
40
+ def error_count(self) -> int:
41
+ """Get number of errors"""
42
+ return sum(
43
+ 1
44
+ for issue in itertools.chain(self.issues or [], self.errors or [])
45
+ if isinstance(issue, ModelSyntaxError | ConsistencyError)
46
+ )
47
+
38
48
  def as_mixpanel_event(self) -> dict[str, Any]:
39
49
  """Convert change to mixpanel event format"""
40
50
  return {
@@ -62,6 +62,7 @@ class NeatStore:
62
62
  def _can_agent_do_activity(self, agent: Agents) -> None:
63
63
  """Validate if activity can be performed in the current state and considering provenance"""
64
64
  if not self.state.can_transition(agent):
65
+ # specific error messages for common mistakes
65
66
  if isinstance(agent, DMSImporter) and isinstance(self.state, PhysicalState):
66
67
  raise RuntimeError(
67
68
  "⚠️ Cannot read data model, there is already a data model in the session!"
@@ -75,6 +76,17 @@ class NeatStore:
75
76
  )
76
77
  raise RuntimeError(f"Cannot run {type(agent).__name__} in state {self.state}")
77
78
 
79
+ if (
80
+ isinstance(agent, DMSExporter)
81
+ and self.provenance.last_change
82
+ and (error_count := self.provenance.last_change.error_count) > 0
83
+ ):
84
+ raise RuntimeError(
85
+ f"⚠️ Cannot write data model, the model has {error_count} errors!"
86
+ f"{NEWLINE}Resolve issues before exporting the data model."
87
+ f"{NEWLINE}You can inspect issues using neat.issues"
88
+ )
89
+
78
90
  # need implementation of checking if required predecessor activities have been done
79
91
  # this will be done by running self.provenance.can_agent_do_activity(agent)
80
92
 
cognite/neat/_version.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.127.24"
1
+ __version__ = "0.127.26"
2
2
  __engine__ = "^2.0.4"
@@ -27,33 +27,53 @@ CLASSES_QUERY = """SELECT ?concept ?name ?description ?implements
27
27
 
28
28
  CLASSES_QUERY_PARAMETERS = {"concept", "name", "description", "implements"}
29
29
 
30
- PROPERTIES_QUERY = """
31
-
32
- SELECT ?concept ?property_ ?name ?description ?value_type ?minCount ?maxCount ?default
30
+ PROPERTIES_QUERY = """ SELECT ?concept ?property_ ?name ?description ?value_type ?min_count ?max_count ?default
33
31
  WHERE {{
34
32
  ?property_ a ?property_Type.
35
33
  FILTER (?property_Type IN (owl:ObjectProperty, owl:DatatypeProperty ) )
36
34
 
35
+ # --- 1. Explicit Domain Discovery ---
37
36
 
37
+ # A. Handling owl:domain when it is expressed as owl restriction
38
+ OPTIONAL {{
39
+ ?property_ rdfs:domain ?domain_exp_node .
40
+ FILTER(isBlank(?domain_exp_node))
41
+ ?domain_exp_node owl:unionOf|owl:intersectionOf ?exp_concepts_list .
42
+ ?exp_concepts_list rdf:rest*/rdf:first ?explicit_concept.
43
+ }}
38
44
 
39
- # Handling owl:domain when it is expressed as
40
- # owl restriction
45
+ # B. Handling the domain when it is a single concept
41
46
  OPTIONAL {{
42
- ?property_ rdfs:domain ?domain .
43
- FILTER(isBlank(?domain))
44
- ?domain owl:unionOf|owl:intersectionOf ?concepts .
45
- ?concepts rdf:rest*/rdf:first ?concept.
47
+ ?property_ rdfs:domain ?domain_exp_node .
48
+ FILTER(!isBlank(?domain_exp_node))
49
+ BIND(?domain_exp_node AS ?explicit_concept)
46
50
  }}
47
51
 
48
- # Handling the domain when it is a single concept
52
+ # --- 2. Inherited Domain Discovery (Fallback) ---
53
+
54
+ # C. Handling inherited domain when parent domain is a restriction
49
55
  OPTIONAL {{
50
- ?property_ rdfs:domain ?domain .
51
- FILTER(!isBlank(?domain))
52
- BIND(?domain AS ?concept)
56
+ ?property_ rdfs:subPropertyOf ?parent_property .
57
+ ?parent_property rdfs:domain ?parent_domain_node .
58
+ FILTER(isBlank(?parent_domain_node))
59
+ ?parent_domain_node owl:unionOf|owl:intersectionOf ?parent_concepts_list .
60
+ ?parent_concepts_list rdf:rest*/rdf:first ?inherited_concept.
53
61
  }}
54
62
 
55
- # Handling owl:range when it is expressed as
56
- # owl restriction
63
+ # D. Handling inherited domain when parent domain is a single concept
64
+ OPTIONAL {{
65
+ ?property_ rdfs:subPropertyOf ?parent_property .
66
+ ?parent_property rdfs:domain ?parent_domain_node .
67
+ FILTER(!isBlank(?parent_domain_node))
68
+ BIND(?parent_domain_node AS ?inherited_concept)
69
+ }}
70
+
71
+ # Final Concept Assignment with Priority ---
72
+ # COALESCE prioritizes ?explicit_concept over ?inherited_concept
73
+ BIND(COALESCE(?explicit_concept, ?inherited_concept) AS ?concept)
74
+
75
+
76
+ # Handling owl:range when it is expressed as owl restriction
57
77
  OPTIONAL {{
58
78
  ?property_ rdfs:range ?range .
59
79
  FILTER(isBlank(?range))
@@ -70,8 +90,8 @@ PROPERTIES_QUERY = """
70
90
 
71
91
  OPTIONAL {{?property_ rdfs:label|skos:prefLabel ?name }}.
72
92
  OPTIONAL {{?property_ rdfs:comment|skos:definition ?description}}.
73
- OPTIONAL {{?property_ owl:maxCardinality ?maxCount}}.
74
- OPTIONAL {{?property_ owl:minCardinality ?minCount}}.
93
+ OPTIONAL {{?property_ owl:maxCardinality ?max_count}}.
94
+ OPTIONAL {{?property_ owl:minCardinality ?min_count}}.
75
95
 
76
96
  # FILTERS
77
97
  FILTER (!isBlank(?property_))
@@ -85,8 +105,8 @@ PROPERTIES_QUERY_PARAMETERS = {
85
105
  "name",
86
106
  "description",
87
107
  "value_type",
88
- "minCount",
89
- "maxCount",
108
+ "min_count",
109
+ "max_count",
90
110
  "default",
91
111
  }
92
112
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognite-neat
3
- Version: 0.127.24
3
+ Version: 0.127.26
4
4
  Summary: Knowledge graph transformation
5
5
  Project-URL: Documentation, https://cognite-neat.readthedocs-hosted.com/
6
6
  Project-URL: Homepage, https://cognite-neat.readthedocs-hosted.com/
@@ -1,7 +1,7 @@
1
1
  cognite/neat/__init__.py,sha256=Lo4DbjDOwnhCYUoAgPp5RG1fDdF7OlnomalTe7n1ydw,211
2
2
  cognite/neat/_exceptions.py,sha256=ox-5hXpee4UJlPE7HpuEHV2C96aLbLKo-BhPDoOAzhA,1650
3
3
  cognite/neat/_issues.py,sha256=wH1mnkrpBsHUkQMGUHFLUIQWQlfJ_qMfdF7q0d9wNhY,1871
4
- cognite/neat/_version.py,sha256=LNaUX8rigYyV0YJJO1DIZXt21i_AUALgOhe4snlff6o,47
4
+ cognite/neat/_version.py,sha256=zp1q6MhRkZE6P6k0LZ7xa5KjU1ZbL4JI5oVv8qlg_5Q,47
5
5
  cognite/neat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  cognite/neat/v1.py,sha256=owqW5Mml2DSZx1AvPvwNRTBngfhBNrQ6EH-7CKL7Jp0,61
7
7
  cognite/neat/_client/__init__.py,sha256=75Bh7eGhaN4sOt3ZcRzHl7pXaheu1z27kmTHeaI05vo,114
@@ -108,8 +108,8 @@ cognite/neat/_state_machine/__init__.py,sha256=wrtQUHETiLzYM0pFo7JC6pJCiXetHADQb
108
108
  cognite/neat/_state_machine/_base.py,sha256=-ZpeAhM6l6N6W70dET25tAzOxaaK5aa474eabwZVzjA,1112
109
109
  cognite/neat/_state_machine/_states.py,sha256=nmj4SmunpDYcBsNx8A284xnXGS43wuUuWpMMORha2DE,1170
110
110
  cognite/neat/_store/__init__.py,sha256=TvM9CcFbtOSrxydPAuJi6Bv_iiGard1Mxfx42ZFoTl0,55
111
- cognite/neat/_store/_provenance.py,sha256=WGRRLVmYrYEOjeouZj7GvoAlMzCN6vchzpSEKsKNYe0,2772
112
- cognite/neat/_store/_store.py,sha256=RiMJccn44gWxpM1SqPbnt3nzgMgYBeUaapfk4fY9Ikg,6250
111
+ cognite/neat/_store/_provenance.py,sha256=tWQGa2QNPyW7FfHQBRto9eHXCxeOTzlz7DvYjAwHfuY,3102
112
+ cognite/neat/_store/_store.py,sha256=Ql1nZvq2UtNoI-L1OmIUFQGXQ4i5-Zche28-YHnBkyg,6775
113
113
  cognite/neat/_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
114
114
  cognite/neat/_utils/_reader.py,sha256=9dXrODNNqWU0Gx1zXjRTOiiByFuDZlpQkQEzx3HAxYQ,5390
115
115
  cognite/neat/_utils/auxiliary.py,sha256=Cx-LP8dfN782R3iUcm--q26zdzQ0k_RFnVbJ0bwVZMI,1345
@@ -166,7 +166,7 @@ cognite/neat/v0/core/_data_model/importers/_spreadsheet2data_model.py,sha256=ksD
166
166
  cognite/neat/v0/core/_data_model/importers/_rdf/__init__.py,sha256=1yOjV2PKCxwH7uCTXVZhSdxtn5etmFX40cksvwtKcZ8,199
167
167
  cognite/neat/v0/core/_data_model/importers/_rdf/_base.py,sha256=Rv24TQQDZqAuFD8Qh0yRBiB7-JvoMVj3mGoPBm-xBFs,6052
168
168
  cognite/neat/v0/core/_data_model/importers/_rdf/_inference2rdata_model.py,sha256=w8LsdkzgoTXN3LZyjEL_5grWZGlf7PPj8qOu370_K6M,28976
169
- cognite/neat/v0/core/_data_model/importers/_rdf/_owl2data_model.py,sha256=JsL2gpVs4ntLyzncgRYic-4qSiDhXT-6xN3jTLo629U,4031
169
+ cognite/neat/v0/core/_data_model/importers/_rdf/_owl2data_model.py,sha256=6fS2IhmRjsQdENYb47bSvRcqTzp7zr0YUuRIsYY-EPc,5200
170
170
  cognite/neat/v0/core/_data_model/importers/_rdf/_shared.py,sha256=lcMnGIvqYZJ41JPjzanZHi9uG826EzYHpQXSMYVRK8A,9839
171
171
  cognite/neat/v0/core/_data_model/models/__init__.py,sha256=whWV0FrdUi01Du2mgan3_kZHQ9T2tGrGb2xRxoFDhNo,1258
172
172
  cognite/neat/v0/core/_data_model/models/_base_unverified.py,sha256=1Wfbp-tJaEF6hd1bFdp2FhTgPkInf-1ZokuEoVJRPxQ,6842
@@ -312,7 +312,7 @@ cognite/neat/v0/session/engine/__init__.py,sha256=D3MxUorEs6-NtgoICqtZ8PISQrjrr4
312
312
  cognite/neat/v0/session/engine/_import.py,sha256=1QxA2_EK613lXYAHKQbZyw2yjo5P9XuiX4Z6_6-WMNQ,169
313
313
  cognite/neat/v0/session/engine/_interface.py,sha256=3W-cYr493c_mW3P5O6MKN1xEQg3cA7NHR_ev3zdF9Vk,533
314
314
  cognite/neat/v0/session/engine/_load.py,sha256=u0x7vuQCRoNcPt25KJBJRn8sJabonYK4vtSZpiTdP4k,5201
315
- cognite_neat-0.127.24.dist-info/METADATA,sha256=MAWzw07h5PAWRf-4uH9i42Ljqj4n5f_DUI29VJ8ka_I,9150
316
- cognite_neat-0.127.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
317
- cognite_neat-0.127.24.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
318
- cognite_neat-0.127.24.dist-info/RECORD,,
315
+ cognite_neat-0.127.26.dist-info/METADATA,sha256=W1EY7XRW7rN7oqdEfS1UMJW1drv2KQyTFuDIH8V1Yh4,9150
316
+ cognite_neat-0.127.26.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
317
+ cognite_neat-0.127.26.dist-info/licenses/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
318
+ cognite_neat-0.127.26.dist-info/RECORD,,