cognite-neat 0.85.0__py3-none-any.whl → 0.85.2__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.85.0"
1
+ __version__ = "0.85.2"
@@ -16,13 +16,20 @@ from cognite.neat.utils.utils import string_to_ideal_type
16
16
 
17
17
 
18
18
  class FilesExtractor(BaseExtractor):
19
+ """Extract data from Cognite Data Fusions files metadata into Neat.
20
+
21
+ Args:
22
+ files_metadata (Iterable[FileMetadata]): An iterable of files metadata.
23
+ namespace (Namespace, optional): The namespace to use. Defaults to DEFAULT_NAMESPACE.
24
+ """
25
+
19
26
  def __init__(
20
27
  self,
21
- events: Iterable[FileMetadata],
28
+ files_metadata: Iterable[FileMetadata],
22
29
  namespace: Namespace | None = None,
23
30
  ):
24
31
  self.namespace = namespace or DEFAULT_NAMESPACE
25
- self.events = events
32
+ self.files_metadata = files_metadata
26
33
 
27
34
  @classmethod
28
35
  def from_dataset(
@@ -39,7 +46,7 @@ class FilesExtractor(BaseExtractor):
39
46
 
40
47
  def extract(self) -> Iterable[Triple]:
41
48
  """Extract files metadata as triples."""
42
- for event in self.events:
49
+ for event in self.files_metadata:
43
50
  yield from self._file2triples(event, self.namespace)
44
51
 
45
52
  @classmethod
@@ -97,3 +97,27 @@ class Queries:
97
97
  else:
98
98
  warnings.warn("No rules found for the graph store, returning empty list.", stacklevel=2)
99
99
  return []
100
+
101
+ def list_triples(self, limit: int = 25) -> list[ResultRow]:
102
+ """List triples in the graph store
103
+
104
+ Args:
105
+ limit: Max number of triples to return, by default 25
106
+
107
+ Returns:
108
+ List of triples
109
+ """
110
+ query = f"SELECT ?subject ?predicate ?object WHERE {{ ?subject ?predicate ?object }} LIMIT {limit}"
111
+ return cast(list[ResultRow], list(self.graph.query(query)))
112
+
113
+ def list_types(self, limit: int = 25) -> list[ResultRow]:
114
+ """List types in the graph store
115
+
116
+ Args:
117
+ limit: Max number of types to return, by default 25
118
+
119
+ Returns:
120
+ List of types
121
+ """
122
+ query = f"SELECT DISTINCT ?type WHERE {{ ?subject a ?type }} LIMIT {limit}"
123
+ return cast(list[ResultRow], list(self.graph.query(query)))
@@ -7,7 +7,7 @@ from rdflib import Graph, Namespace, URIRef
7
7
  from rdflib import Literal as RdfLiteral
8
8
 
9
9
  import cognite.neat.rules.issues as issues
10
- from cognite.neat.constants import PREFIXES
10
+ from cognite.neat.constants import DEFAULT_NAMESPACE, PREFIXES
11
11
  from cognite.neat.graph.stores import NeatGraphStore
12
12
  from cognite.neat.rules.importers._base import BaseImporter, Rules, _handle_issues
13
13
  from cognite.neat.rules.issues import IssueList
@@ -246,8 +246,8 @@ class InferenceImporter(BaseImporter):
246
246
  created=datetime.now(),
247
247
  updated=datetime.now(),
248
248
  description="Inferred model from knowledge graph",
249
- prefix="inferred",
250
- namespace="http://purl.org/cognite/neat/inferred/",
249
+ prefix="neat",
250
+ namespace=DEFAULT_NAMESPACE,
251
251
  )
252
252
 
253
253
  @classmethod
@@ -18,7 +18,9 @@ _VALID_LOGIN_FLOWS = get_args(_LOGIN_FLOW)
18
18
  _CLIENT_NAME = f"CogniteNeat:{_version.__version__}"
19
19
 
20
20
 
21
- def get_cognite_client() -> CogniteClient:
21
+ def get_cognite_client(env_file_name: str = ".env") -> CogniteClient:
22
+ if not env_file_name.endswith(".env"):
23
+ raise ValueError("env_file_name must end with '.env'")
22
24
  with suppress(KeyError):
23
25
  variables = _EnvironmentVariables.create_from_environ()
24
26
  return variables.get_client()
@@ -26,16 +28,16 @@ def get_cognite_client() -> CogniteClient:
26
28
  repo_root = _repo_root()
27
29
  if repo_root:
28
30
  with suppress(KeyError, FileNotFoundError, TypeError):
29
- variables = _from_dotenv(repo_root / ".env")
31
+ variables = _from_dotenv(repo_root / env_file_name)
30
32
  client = variables.get_client()
31
33
  print("Found .env file in repository root. Loaded variables from .env file.")
32
34
  return client
33
35
  variables = _prompt_user()
34
- if repo_root and _env_in_gitignore(repo_root):
36
+ if repo_root and _env_in_gitignore(repo_root, env_file_name):
35
37
  local_import("rich", "jupyter")
36
38
  from rich.prompt import Prompt
37
39
 
38
- env_file = repo_root / ".env"
40
+ env_file = repo_root / env_file_name
39
41
  answer = Prompt.ask(
40
42
  "Do you store the variables in an .env file in the repository root for easy reuse?", choices=["y", "n"]
41
43
  )
@@ -88,7 +90,7 @@ class _EnvironmentVariables:
88
90
  @property
89
91
  def idp_scopes(self) -> list[str]:
90
92
  if self.IDP_SCOPES:
91
- return self.IDP_SCOPES.split()
93
+ return self.IDP_SCOPES.split(",")
92
94
  return [f"https://{self.CDF_CLUSTER}.cognitedata.com/.default"]
93
95
 
94
96
  @property
@@ -187,7 +189,7 @@ class _EnvironmentVariables:
187
189
  value = getattr(self, name)
188
190
  if value is not None:
189
191
  if isinstance(value, list):
190
- value = " ".join(value)
192
+ value = ",".join(value)
191
193
  lines.append(f"{field.name}={value}")
192
194
  return "\n".join(lines)
193
195
 
@@ -199,7 +201,7 @@ def _from_dotenv(evn_file: Path) -> _EnvironmentVariables:
199
201
  valid_variables = {f.name for f in fields(_EnvironmentVariables)}
200
202
  variables: dict[str, str] = {}
201
203
  for line in content.splitlines():
202
- if line.startswith("#") or not line:
204
+ if line.startswith("#") or "=" not in line:
203
205
  continue
204
206
  key, value = line.split("=", 1)
205
207
  if key in valid_variables:
@@ -241,8 +243,13 @@ def _prompt_user() -> _EnvironmentVariables:
241
243
  token_url = Prompt.ask("Enter IDP_TOKEN_URL")
242
244
  variables.IDP_TOKEN_URL = token_url
243
245
  optional = ["IDP_AUDIENCE", "IDP_SCOPES"]
244
- else:
245
- optional = ["IDP_TENANT_ID", "IDP_SCOPES"]
246
+ else: # login_flow == "interactive"
247
+ tenant_id = Prompt.ask("Enter IDP_TENANT_ID (leave empty to enter IDP_AUTHORITY_URL instead)")
248
+ if tenant_id:
249
+ variables.IDP_TENANT_ID = tenant_id
250
+ else:
251
+ variables.IDP_AUTHORITY_URL = Prompt.ask("Enter IDP_TOKEN_URL")
252
+ optional = ["IDP_SCOPES"]
246
253
 
247
254
  defaults = "".join(f"\n - {name}: {getattr(variables, name.lower())}" for name in optional)
248
255
  use_defaults = Prompt.ask(
@@ -284,15 +291,15 @@ def _repo_root() -> Path | None:
284
291
  return None
285
292
 
286
293
 
287
- def _env_in_gitignore(repo_root: Path) -> bool:
294
+ def _env_in_gitignore(repo_root: Path, env_file_name: str) -> bool:
288
295
  ignore_file = repo_root / ".gitignore"
289
296
  if not ignore_file.exists():
290
297
  return False
291
298
  else:
292
299
  ignored = {line.strip() for line in ignore_file.read_text().splitlines()}
293
- return ".env" in ignored or "*.env" in ignored
300
+ return env_file_name in ignored or "*.env" in ignored
294
301
 
295
302
 
296
303
  if __name__ == "__main__":
297
- c = _prompt_user().get_client()
304
+ c = get_cognite_client()
298
305
  print(c.iam.token.inspect())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cognite-neat
3
- Version: 0.85.0
3
+ Version: 0.85.2
4
4
  Summary: Knowledge graph transformation
5
5
  Home-page: https://cognite-neat.readthedocs-hosted.com/
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  cognite/neat/__init__.py,sha256=AiexNcHdAHFbrrbo9c65gtil1dqx_SGraDH1PSsXjKE,126
2
2
  cognite/neat/_shared.py,sha256=RSaHm2eJceTlvb-hMMe4nHgoHdPYDfN3XcxDXo24k3A,1530
3
- cognite/neat/_version.py,sha256=oS_t2ihHSRa_TQs1XBgfsFFpaFOEDZAndDmjccnIF4g,23
3
+ cognite/neat/_version.py,sha256=KJl3iR2SY5vGxzthLO9dh1TLLxtswsW9LCjfengv-Fw,23
4
4
  cognite/neat/app/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  cognite/neat/app/api/asgi/metrics.py,sha256=nxFy7L5cChTI0a-zkCiJ59Aq8yLuIJp5c9Dg0wRXtV0,152
6
6
  cognite/neat/app/api/configuration.py,sha256=2U5M6M252swvQPQyooA1EBzFUZNtcTmuSaywfJDgckM,4232
@@ -59,7 +59,7 @@ cognite/neat/graph/extractors/_base.py,sha256=8IWygpkQTwo0UOmbbwWVI7540_klTVdUVX
59
59
  cognite/neat/graph/extractors/_classic_cdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
60
  cognite/neat/graph/extractors/_classic_cdf/_assets.py,sha256=Hu-RoTBhn4LFm38G51L5tc0MVy4-zr1POHWyrIB-vUc,4130
61
61
  cognite/neat/graph/extractors/_classic_cdf/_events.py,sha256=SGZWKCxppECIQkwQs5M2e_SoF-eGilCW2KiyXk2PmzM,4230
62
- cognite/neat/graph/extractors/_classic_cdf/_files.py,sha256=-6nCkXUCAnDsv4eDFDEiQ-U4SGhmW1VLxZJFUcszqjU,4831
62
+ cognite/neat/graph/extractors/_classic_cdf/_files.py,sha256=o35K0_ouq7hjR_lAVRjWbuRsuAzlS78S_97am5TFU5A,5129
63
63
  cognite/neat/graph/extractors/_classic_cdf/_labels.py,sha256=4JxQHPDciMjbk7F6GxMa-HfhOgAv8LT3VO3mRfEgQ0E,2832
64
64
  cognite/neat/graph/extractors/_classic_cdf/_relationships.py,sha256=jgIN__nztlhLwoIJw59s2-Blc9gxIm7YDha5qEoXBSg,5654
65
65
  cognite/neat/graph/extractors/_classic_cdf/_sequences.py,sha256=5FuhwpgDiGG51C0bQacQ4LD6KkutUaU1cX2NSy_krhU,3652
@@ -75,7 +75,7 @@ cognite/neat/graph/loaders/_rdf2asset.py,sha256=aFby7BwIrW253LEJ4XqGeUuf4jG9VUe8
75
75
  cognite/neat/graph/loaders/_rdf2dms.py,sha256=xyr0SfIusfjYjlAXZcIGS1-IQ6LoVWeOB3_q6D304oo,13603
76
76
  cognite/neat/graph/models.py,sha256=AtLgZh2qyRP6NRetjQCy9qLMuTQB0CH52Zsev-qa2sk,149
77
77
  cognite/neat/graph/queries/__init__.py,sha256=BgDd-037kvtWwAoGAy8eORVNMiZ5-E9sIV0txIpeaN4,50
78
- cognite/neat/graph/queries/_base.py,sha256=20A7GDBdmc35VmHVz5n0YCGPcnBAmUX-bM2ImHPManc,3844
78
+ cognite/neat/graph/queries/_base.py,sha256=pSc6nHpcDEStGtIeeboAI-QD2PbckWaaNMK3As04jOI,4658
79
79
  cognite/neat/graph/queries/_construct.py,sha256=FxzSQqzCpo7lKVYerlLAY03oqCeFM5L6MozfBUblzr4,7341
80
80
  cognite/neat/graph/queries/_shared.py,sha256=EwW2RbPttt7-z7QTgfKWlthA2Nq5d3bYyyewFkCA7R4,5043
81
81
  cognite/neat/graph/stores/__init__.py,sha256=G-VG_YwfRt1kuPao07PDJyZ3w_0-eguzLUM13n-Z_RA,64
@@ -203,7 +203,7 @@ cognite/neat/rules/importers/_dtdl2rules/_unit_lookup.py,sha256=wW4saKva61Q_i17g
203
203
  cognite/neat/rules/importers/_dtdl2rules/dtdl_converter.py,sha256=ysmWUxZ0npwrTB0uiH5jA0v37sfCwowGaYk17IyxPUU,12663
204
204
  cognite/neat/rules/importers/_dtdl2rules/dtdl_importer.py,sha256=Psj3C2jembY_Wu7WWJIFIwrMawvjISjeqfBnoRy_csw,6740
205
205
  cognite/neat/rules/importers/_dtdl2rules/spec.py,sha256=tim_MfN1J0F3Oeqk3BMgIA82d_MZvhRuRMsLK3B4PYc,11897
206
- cognite/neat/rules/importers/_inference2rules.py,sha256=OilV3aF3LTjFHK2Yzs8KktTGG41iPB4hh3u1aAwhNbI,11675
206
+ cognite/neat/rules/importers/_inference2rules.py,sha256=bBpzrioIZl3xdzz5Pal_GJyVPx08ascYW7uckixUy0Q,11667
207
207
  cognite/neat/rules/importers/_owl2rules/__init__.py,sha256=tdGcrgtozdQyST-pTlxIa4cLBNTLvtk1nNYR4vOdFSw,63
208
208
  cognite/neat/rules/importers/_owl2rules/_owl2classes.py,sha256=QpTxvrTGczIa48X8lgXGnMN1AWPhHK0DR6uNq175xak,7357
209
209
  cognite/neat/rules/importers/_owl2rules/_owl2metadata.py,sha256=nwnUaBNAAYMoBre2UmsnkJXUuaqGEpR3U3txDrH2w6g,7527
@@ -251,7 +251,7 @@ cognite/neat/rules/models/information/_serializer.py,sha256=yti9I_xJruxrib66YIBI
251
251
  cognite/neat/rules/models/information/_validation.py,sha256=Is2GzL2lZU3A5zPu3NjvlXfmIU2_Y10C5Nxi5Denz4g,7528
252
252
  cognite/neat/rules/models/wrapped_entities.py,sha256=ThhjnNNrpgz0HeORIQ8Q894trxP73P7T_TuZj6qH2CU,7157
253
253
  cognite/neat/utils/__init__.py,sha256=l5Nyqhqo25bcQXCOb_lk01cr-UXsG8cczz_y_I0u6bg,68
254
- cognite/neat/utils/auth.py,sha256=0UeZH4nx-0LizNsBrYJiquK6ZldNYk_2frLBZzcB5JM,11270
254
+ cognite/neat/utils/auth.py,sha256=rBzx92IN4xGj3UK95UExKlK2dCwQi3svTZ_YBMWaTVo,11739
255
255
  cognite/neat/utils/auxiliary.py,sha256=IOVbr6lPQulMJUyrrhfSsF6lIHch0Aw6KszMkBomprc,1248
256
256
  cognite/neat/utils/cdf.py,sha256=piRx-6GRz4cCfBZD5rU0OM6ixQ3cj5TMzI0yCYUveR8,2422
257
257
  cognite/neat/utils/cdf_classes.py,sha256=NEmz5UprBlqfqZnqJkRk5xjSpzazwHbhcWsMH_GNxP8,5831
@@ -310,8 +310,8 @@ cognite/neat/workflows/steps_registry.py,sha256=fkTX14ZA7_gkUYfWIlx7A1XbCidvqR23
310
310
  cognite/neat/workflows/tasks.py,sha256=dqlJwKAb0jlkl7abbY8RRz3m7MT4SK8-7cntMWkOYjw,788
311
311
  cognite/neat/workflows/triggers.py,sha256=_BLNplzoz0iic367u1mhHMHiUrCwP-SLK6_CZzfODX0,7071
312
312
  cognite/neat/workflows/utils.py,sha256=gKdy3RLG7ctRhbCRwaDIWpL9Mi98zm56-d4jfHDqP1E,453
313
- cognite_neat-0.85.0.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
314
- cognite_neat-0.85.0.dist-info/METADATA,sha256=v0E853i0iw38J4bJSXaqj-K7ZLL9aBaTO4roAkCu-VE,9493
315
- cognite_neat-0.85.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
316
- cognite_neat-0.85.0.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
317
- cognite_neat-0.85.0.dist-info/RECORD,,
313
+ cognite_neat-0.85.2.dist-info/LICENSE,sha256=W8VmvFia4WHa3Gqxq1Ygrq85McUNqIGDVgtdvzT-XqA,11351
314
+ cognite_neat-0.85.2.dist-info/METADATA,sha256=ZX3Pa8xd3fAqOiem-NJ2rzWjeP8FlMaihmnGVHYok9I,9493
315
+ cognite_neat-0.85.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
316
+ cognite_neat-0.85.2.dist-info/entry_points.txt,sha256=61FPqiWb25vbqB0KI7znG8nsg_ibLHBvTjYnkPvNFso,50
317
+ cognite_neat-0.85.2.dist-info/RECORD,,