personal_knowledge_library 3.3.2__py3-none-any.whl → 3.4.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 personal_knowledge_library might be problematic. Click here for more details.

@@ -164,8 +164,8 @@ def handle_error(
164
164
  ----------
165
165
  message: str
166
166
  Error message
167
- response: aiohttp.ClientResponse
168
- Response
167
+ response: Response
168
+ Response from the service
169
169
  parameters: Optional[Dict[str, Any]] (Default:= None)
170
170
  Parameters
171
171
  payload: Optional[Dict[str, Any]] (Default:= None)
@@ -300,8 +300,9 @@ class WacomServiceAPIClient(RESTAPIClient):
300
300
  raise WacomServiceException(f"Unknown session id:= {self.__current_session_id}. Please login first.")
301
301
  return session
302
302
 
303
- def request_user_token(self, tenant_api_key: str, external_id: str, timeout: int = DEFAULT_TIMEOUT) \
304
- -> Tuple[str, str, datetime]:
303
+ def request_user_token(
304
+ self, tenant_api_key: str, external_id: str, timeout: int = DEFAULT_TIMEOUT
305
+ ) -> Tuple[str, str, datetime]:
305
306
  """
306
307
  Login as user by using the tenant key and its external user id.
307
308
 
@@ -336,8 +337,7 @@ class WacomServiceAPIClient(RESTAPIClient):
336
337
  }
337
338
  payload: dict = {EXTERNAL_USER_ID: external_id}
338
339
  response: Response = requests.post(
339
- url, headers=headers, json=payload, timeout=timeout, verify=self.verify_calls,
340
- allow_redirects=True
340
+ url, headers=headers, json=payload, timeout=timeout, verify=self.verify_calls, allow_redirects=True
341
341
  )
342
342
  if response.ok:
343
343
  try:
@@ -229,7 +229,8 @@ class WacomKnowledgeService(WacomServiceAPIClient):
229
229
  return thing
230
230
  raise handle_error(f"Retrieving of entity content failed. URI:={uri}.", response)
231
231
 
232
- def entities(self,
232
+ def entities(
233
+ self,
233
234
  uris: List[str],
234
235
  locale: Optional[LocaleCode] = None,
235
236
  auth_key: Optional[str] = None,
@@ -282,8 +283,9 @@ class WacomKnowledgeService(WacomServiceAPIClient):
282
283
  with requests.Session() as session:
283
284
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
284
285
  session.mount(mount_point, HTTPAdapter(max_retries=retries))
285
- response: Response = session.get(url, params=params, headers=headers, timeout=timeout,
286
- verify=self.verify_calls)
286
+ response: Response = session.get(
287
+ url, params=params, headers=headers, timeout=timeout, verify=self.verify_calls
288
+ )
287
289
  if response.ok:
288
290
  things: List[ThingObject] = []
289
291
  entities: List[Dict[str, Any]] = response.json()
@@ -1743,7 +1745,7 @@ class WacomKnowledgeService(WacomServiceAPIClient):
1743
1745
  _, file_extension = os.path.splitext(file_name.lower())
1744
1746
  if file_extension not in MIME_TYPE:
1745
1747
  raise handle_error(
1746
- "Creation of entity image failed. Mime-type cannot be identified or is not " "supported.",
1748
+ "Creation of entity image failed. " "Mime-type cannot be identified or is not supported.",
1747
1749
  response,
1748
1750
  )
1749
1751
  mime_type = MIME_TYPE[file_extension]
@@ -1914,6 +1916,8 @@ class WacomKnowledgeService(WacomServiceAPIClient):
1914
1916
  ------
1915
1917
  WacomServiceException
1916
1918
  If the graph service returns an error code.
1919
+ FileNotFoundError
1920
+ If the file does not exist.
1917
1921
  """
1918
1922
  if not file_path.exists():
1919
1923
  raise FileNotFoundError(f"The file {file_path} does not exist.")
@@ -1929,7 +1933,9 @@ class WacomKnowledgeService(WacomServiceAPIClient):
1929
1933
  url: str = f"{self.service_base_url}{self.IMPORT_ENTITIES_ENDPOINT}"
1930
1934
  mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
1931
1935
  with requests.Session() as session:
1932
- retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
1936
+ retries: Retry = Retry(
1937
+ total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST
1938
+ )
1933
1939
  session.mount(mount_point, HTTPAdapter(max_retries=retries))
1934
1940
  response: Response = session.post(
1935
1941
  url, headers=headers, files=files, timeout=timeout, verify=self.verify_calls
@@ -92,13 +92,6 @@ def entity_payload(entity: ThingObject) -> Dict[str, Any]:
92
92
 
93
93
  if len(desc.content) > 0 and not desc.content == " ":
94
94
  descriptions.append({DESCRIPTION_TAG: desc.content, LOCALE_TAG: desc.language_code})
95
- if len(descriptions) == 0:
96
- # Adding an empty description
97
- for label in entity.label:
98
- if len(label.content) > 0 and not label.content == " ":
99
- descriptions.append(
100
- {DESCRIPTION_TAG: f"Description of {label.content}", LOCALE_TAG: label.language_code}
101
- )
102
95
 
103
96
  # Labels are tagged as main label
104
97
  for label in entity.label:
@@ -1179,8 +1179,9 @@ class OntologyService(WacomServiceAPIClient):
1179
1179
  with requests.Session() as session:
1180
1180
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
1181
1181
  session.mount(mount_point, HTTPAdapter(max_retries=retries))
1182
- response: Response = session.put(url, params=params, headers=headers, verify=self.verify_calls,
1183
- timeout=timeout)
1182
+ response: Response = session.put(
1183
+ url, params=params, headers=headers, verify=self.verify_calls, timeout=timeout
1184
+ )
1184
1185
  if not response.ok:
1185
1186
  raise handle_error("Commit of ontology failed.", response, headers=headers)
1186
1187
 
@@ -68,9 +68,6 @@ class TenantManagementServiceAPI(WacomServiceAPIClient):
68
68
  name: str,
69
69
  create_and_apply_onto: bool = True,
70
70
  rights: Optional[List[str]] = None,
71
- vector_search_data_properties: Optional[List[str]] = None,
72
- vector_search_object_properties: Optional[List[str]] = None,
73
- content_data_property_name: str = "",
74
71
  timeout: int = DEFAULT_TIMEOUT,
75
72
  max_retries: int = DEFAULT_MAX_RETRIES,
76
73
  backoff_factor: float = DEFAULT_BACKOFF_FACTOR,
@@ -86,12 +83,6 @@ class TenantManagementServiceAPI(WacomServiceAPIClient):
86
83
  Creates and applies the ontology.
87
84
  rights: List[str]
88
85
  List of rights for the tenant. They are encoded in the user token, e.g., "ink-to-text"
89
- vector_search_data_properties: List[str]
90
- List of data properties that are automatically added to meta-data of the vector search index documents.
91
- vector_search_object_properties: List[str]
92
- List of object properties that are automatically added to meta-data of the vector search index documents.
93
- content_data_property_name: str
94
- The data property that is used to indexing its content to the document index.
95
86
  timeout: int
96
87
  Timeout for the request (default: 60 seconds)
97
88
  max_retries: int
@@ -121,13 +112,7 @@ class TenantManagementServiceAPI(WacomServiceAPIClient):
121
112
  AUTHORIZATION_HEADER_FLAG: f"Bearer {self.__tenant_management_token}",
122
113
  CONTENT_TYPE_HEADER_FLAG: "application/json",
123
114
  }
124
- payload: dict = {
125
- "name": name,
126
- "rights": rights if rights else [],
127
- "vectorSearchDataProperties": vector_search_data_properties if vector_search_object_properties else [],
128
- "vectorSearchObjectProperties": vector_search_object_properties if vector_search_object_properties else [],
129
- "contentDataPropertyName": content_data_property_name,
130
- }
115
+ payload: dict = {"name": name, "rights": rights if rights else []}
131
116
  params: dict = {"createAndApplyOnto": create_and_apply_onto}
132
117
  mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
133
118
  with requests.Session() as session:
@@ -227,9 +212,8 @@ class TenantManagementServiceAPI(WacomServiceAPIClient):
227
212
  "vectorSearchDataProperties": vector_search_data_properties,
228
213
  "vectorSearchObjectProperties": vector_search_object_properties,
229
214
  "contentDataPropertyName": content_data_property_name,
215
+ "rights": rights,
230
216
  }
231
- if len(rights) > 0:
232
- payload["rights"] = rights
233
217
  mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
234
218
  with requests.Session() as session:
235
219
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
@@ -176,7 +176,7 @@ class UserManagementServiceAPI(WacomServiceAPIClient):
176
176
  timeout: int = DEFAULT_TIMEOUT,
177
177
  ) -> Tuple[User, str, str, datetime]:
178
178
  """
179
- Creates user for a tenant.
179
+ Creates a user for a tenant.
180
180
 
181
181
  Parameters
182
182
  ----------
@@ -430,7 +430,7 @@ class UserManagementServiceAPI(WacomServiceAPIClient):
430
430
  """
431
431
  url: str = f"{self.service_base_url}{UserManagementServiceAPI.USER_ENDPOINT}"
432
432
  headers: Dict[str, str] = {USER_AGENT_TAG: self.user_agent, TENANT_API_KEY_FLAG: tenant_key}
433
- params: Dict[str, str] = {OFFSET_TAG: offset, LIMIT_TAG: limit}
433
+ params: Dict[str, int] = {OFFSET_TAG: offset, LIMIT_TAG: limit}
434
434
  mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
435
435
  with requests.Session() as session:
436
436
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
knowledge/utils/graph.py CHANGED
@@ -1,12 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright © 2024-present Wacom. All rights reserved.
3
+ import asyncio
3
4
  from typing import Optional, Iterator, Tuple, AsyncIterator
4
5
 
6
+ import loguru
7
+
5
8
  from knowledge.base.language import LocaleCode
6
9
  from knowledge.base.ontology import OntologyClassReference, ThingObject
7
10
  from knowledge.services.asyncio.graph import AsyncWacomKnowledgeService
8
11
  from knowledge.services.graph import WacomKnowledgeService, Visibility
9
12
 
13
+ logger = loguru.logger
14
+
10
15
 
11
16
  def count_things(
12
17
  wacom_client: WacomKnowledgeService,
@@ -401,17 +406,21 @@ async def async_things_session_iter(
401
406
  raise ValueError("No session configured for client")
402
407
 
403
408
  while True:
404
- things, _, next_page_id = await async_client.listing(
405
- concept_type,
406
- visibility=visibility,
407
- is_owner=only_own,
408
- locale=locale,
409
- limit=fetch_size,
410
- page_id=next_page_id,
411
- )
412
- if len(things) == 0:
413
- return
414
- for obj in things:
415
- await async_client.handle_token(force_refresh_timeout=force_refresh_timeout)
416
- if obj.owner or not only_own:
417
- yield obj
409
+ try:
410
+ things, _, next_page_id = await async_client.listing(
411
+ concept_type,
412
+ visibility=visibility,
413
+ is_owner=only_own,
414
+ locale=locale,
415
+ limit=fetch_size,
416
+ page_id=next_page_id,
417
+ )
418
+ if len(things) == 0:
419
+ return
420
+ for obj in things:
421
+ await async_client.handle_token(force_refresh_timeout=force_refresh_timeout)
422
+ if obj.owner or not only_own:
423
+ yield obj
424
+ except TimeoutError as e:
425
+ logger.error(f"Timeout error while fetching things: {e}")
426
+ await asyncio.sleep(2) # Wait before retrying
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: personal_knowledge_library
3
- Version: 3.3.2
3
+ Version: 3.4.0
4
4
  Summary: Library to access Wacom's Personal Knowledge graph.
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -1,46 +1,46 @@
1
- knowledge/__init__.py,sha256=flQ1lRI4EvDr7UK_m3TSu6wMprmvVNFrhVlnzMFv3WY,2680
1
+ knowledge/__init__.py,sha256=peGvMBf-uwyMLzHXRnXvPnj0TiGQm22pJdJnLqfhKTk,2680
2
2
  knowledge/base/__init__.py,sha256=rgAcl0azO6eoVk1gK9z0UFNlTHj3AN88k6LG-GdATFk,1079
3
3
  knowledge/base/access.py,sha256=BSh-6QbeHOCu55XTxA-p3DwEyRzgtN8TSxtcn6UvmZo,4411
4
4
  knowledge/base/entity.py,sha256=b-Ana_H_WI2-AT_n-V_HzUL6W9Ri16DcZFS3q4ziI94,8445
5
5
  knowledge/base/language.py,sha256=L4VAKRuFRQxE0BfzxkQUeChyhvLKoZM7ooqxm0dACO4,1478
6
- knowledge/base/ontology.py,sha256=kPZAPBYuT-2LY33lldP66hXArqKO8WwZj8SMJhgTEjU,95434
7
- knowledge/base/response.py,sha256=dqdskdcjKnM142nX_8sDVs8v7xTQjiVY1MqJCI-Dfkc,10918
8
- knowledge/base/search.py,sha256=J1PSVpTU2JKF9xSZLZZvAbJfFy1HiMPJRzPjHhR7IQM,14722
6
+ knowledge/base/ontology.py,sha256=Ix_LP7np2tDYIQVhVX9cNCf-N_S6RhAuGY3Pm21doL8,95443
7
+ knowledge/base/response.py,sha256=Y1xk5QCRCd2jGosI9FXYFOf4umP1T85AE65dcCeQW7Q,11006
8
+ knowledge/base/search.py,sha256=IBSi4sEUExtPg5s3-4RSQwr2mCU50cdDG4PCR78CR2Y,15241
9
9
  knowledge/base/tenant.py,sha256=f2Z_LjUcjIt5J2_Rse9aQyTzJ0sSyVvCzlm8PP3PqY8,6084
10
10
  knowledge/nel/__init__.py,sha256=eTT88LV_KQ-Ku-a4RnTv_TUCNogl357ui4KT1pEKMuQ,330
11
- knowledge/nel/base.py,sha256=EloMv3utdYVaor7dFp0R79IxXd7oXq4kv7AwTHzbQhw,15775
11
+ knowledge/nel/base.py,sha256=Nmt2SrxI8yOVWSCloeE08LQmhIQMlheQMXj4gwnD0w8,15774
12
12
  knowledge/nel/engine.py,sha256=2fCGkrS3PVPVEfO6AmYyWDPUOpwIeLxDRmNQT3-eMvo,5456
13
13
  knowledge/ontomapping/__init__.py,sha256=u_t6i5a6pYYnf43Q_S6sG7NRLeGuKmahIHW6TFGHqOk,18848
14
14
  knowledge/ontomapping/manager.py,sha256=pXBwRGSTcS731df5vewNv6oMgP18HzvnjZqiUgyFIhI,13361
15
15
  knowledge/public/__init__.py,sha256=FrW5sqJGVcIfg5IVpt_g7qlWiIYNGA370jkE5mJDhoo,812
16
16
  knowledge/public/cache.py,sha256=uKEuW9WN9xPmY-fwWPLSxmdEP6xg-XG3g8fKAmGZgBQ,14510
17
17
  knowledge/public/client.py,sha256=7Z-nYhYIni_jKDWJw18CvuUxuOCns74l8XjeEEJXl_Y,15437
18
- knowledge/public/helper.py,sha256=PDsInMHMHgP8rMvcFk5E47afdE3rC7V3BzPS-DdOsww,13238
18
+ knowledge/public/helper.py,sha256=OJIjo_c1eE-PVlOlgCFHDJLkoXsOXgRWpX6HtfL-LqY,13620
19
19
  knowledge/public/relations.py,sha256=DrL-rYuwLzaE2H2TOM2gG1TGqHbkcPL4EsRD54LQqLs,4182
20
- knowledge/public/wikidata.py,sha256=LwMP2kq2mH5Oi9JhPvG8lN9pZMDlQvxgaZgQKQO3kaM,36683
20
+ knowledge/public/wikidata.py,sha256=9wj99ZhFF_FZzeD75hU3CWy5XzNuMSUu_Tw3Xsfjx7U,36683
21
21
  knowledge/services/__init__.py,sha256=Pg4Pd9cCRiQ4-v3E0WCqldOhJFcMmkZrQHA7BY1Z1K8,3604
22
22
  knowledge/services/asyncio/__init__.py,sha256=dq9yGTxg_hoQb8E1kEtY4AeB8zrdJfw3-XlPoYn2j5U,225
23
- knowledge/services/asyncio/base.py,sha256=im6J1CWOp1N1tt6WdJ1uU0R-VFpvdYc6lZu8TyPrU5A,16222
24
- knowledge/services/asyncio/graph.py,sha256=XLVqDli8-Nr92MuLUKvHDisSqqca3fxg6e3_O0HC_2o,74144
25
- knowledge/services/asyncio/group.py,sha256=UKbk8vnPqqAkuc5gAd6g3IVOKmUJNqG2lreZM0O-hRg,18356
26
- knowledge/services/asyncio/search.py,sha256=DMxcevIM_pd6HF2_JTdva7t_zVUdSg5PbjJ8rPkBHi4,16774
27
- knowledge/services/asyncio/users.py,sha256=NJ7xagjr4gF6yKJXdwa0bz0eaYlQDee5RCEpfQJEHWk,10274
28
- knowledge/services/base.py,sha256=PdHfObShUBpbAS71LBhe5jOA13Y1JXbUkhRi9op8wis,18018
29
- knowledge/services/graph.py,sha256=hMGFomueC7lOr7-PjVZWeQn2S-D8FsU-0Ah7lCiAJH4,92095
23
+ knowledge/services/asyncio/base.py,sha256=CaB9Q9enzT6HS4kLjTKHTXVevVB6CXZt-oVq1m_uTfQ,16235
24
+ knowledge/services/asyncio/graph.py,sha256=Yvt0kJZiMFgzKI2PEX9FdkD6InUDNPu6c1vm7iqHaUk,75359
25
+ knowledge/services/asyncio/group.py,sha256=uhfrO5gPnAhf3AK9DQGb1Fla8FlTUYMRY5kens7Vm_0,20133
26
+ knowledge/services/asyncio/search.py,sha256=bn7vHaCO_2GvkGH953Gfssv83qSkWtQ5qk-p5sQplKk,18029
27
+ knowledge/services/asyncio/users.py,sha256=3xzCsZZpEEnBzLziQXUARUorHaimeeTIH15ps_Xr6sQ,10995
28
+ knowledge/services/base.py,sha256=xs7Iz1DUnrmIKzEKvzfME7anris8dpCSR7KQLcbR0m8,18009
29
+ knowledge/services/graph.py,sha256=paHB4j1JYqsmuX9NWHyWPqhTyi5wlr9d4BP9XxwFjSU,92193
30
30
  knowledge/services/group.py,sha256=b8dBBrHXqgwpJ7BtUqqweoR_WQH5MZ0aLh0fBBTyHUI,30698
31
- knowledge/services/helper.py,sha256=NYhRkYXtiFgovsXaQr6rBVN2mjBwOT7cSSuLTyjvzKA,4990
32
- knowledge/services/ontology.py,sha256=1QewHZoNTNrQe9cAgLMvWRPQ2YYn4IltscEOV9Dy2qM,51800
31
+ knowledge/services/helper.py,sha256=x9dfUSdM39B_ZbHECNnYT5PREl6MK5WSiMA-uZtQh04,4656
32
+ knowledge/services/ontology.py,sha256=8fEOs9k7ajRWyPsmg2UH17RSqmJ1Gr0mVYIirFh84ys,51785
33
33
  knowledge/services/search.py,sha256=L97EXWoG7XoYSLP5ABnN5BtOSd7yr9KLR6bZT4vzicc,19862
34
34
  knowledge/services/session.py,sha256=y8uTETRMDOBbC30UAlrrtWTN7Zgs2klqHsoMjLO2tq0,14145
35
- knowledge/services/tenant.py,sha256=rQsUe8qNFTt_WZG4XBTg8QSLoyavuCWLWk3QhU1fBG8,11728
36
- knowledge/services/users.py,sha256=nOwyZhqERTNFPTN21c_q7-6XaEMb3SnHfnXr4Kf22qk,16594
35
+ knowledge/services/tenant.py,sha256=YOLyJSreylE3lMyrkXWWSAzD8jWA7NDmUvXqaSpaJwg,10707
36
+ knowledge/services/users.py,sha256=-ORhjidxQ3LlqPbERNXnU73oATLT6WVFkaEfCPePATo,16596
37
37
  knowledge/utils/__init__.py,sha256=7unsBV5ge6eIyicKCIc_C4OroD-zkKRMVE0jXcH6EOw,313
38
38
  knowledge/utils/diff.py,sha256=HrU03qGvkirPqC0vRRZRLA49eI08o-JI3dcHS5-uv4g,26647
39
- knowledge/utils/graph.py,sha256=kuPZEGhexVN9McoT8JK2ViIrfXTh-nFPv_8XPfG0wlA,12318
39
+ knowledge/utils/graph.py,sha256=IXLVsiIqDB6doaxIy1I38235fCuFFZ-pNXAYQ3vXpzg,12604
40
40
  knowledge/utils/import_format.py,sha256=fjuWpd91eAs7MbqSpLrFgdRvFaHK0nzV1L83ByjTmV0,5277
41
41
  knowledge/utils/wikidata.py,sha256=vRH-4AMR-3xywyvmDqbjI4KSw4tF4TEYqUGCJmUMqK8,5512
42
42
  knowledge/utils/wikipedia.py,sha256=rBuFqYVM58JCj5ISLxuhYVVl2gOIlPLWx7_CghyQgvE,5052
43
- personal_knowledge_library-3.3.2.dist-info/METADATA,sha256=Cw39qFfSsOaRAyoTJgzlj_MG0aXcLwe1eIKVyr0uKFc,57120
44
- personal_knowledge_library-3.3.2.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
45
- personal_knowledge_library-3.3.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
46
- personal_knowledge_library-3.3.2.dist-info/RECORD,,
43
+ personal_knowledge_library-3.4.0.dist-info/METADATA,sha256=ZfMkBQ7eIcOYrUO-iMXGABNqBzHJtVdLRhrzBLGywIw,57120
44
+ personal_knowledge_library-3.4.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
45
+ personal_knowledge_library-3.4.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
46
+ personal_knowledge_library-3.4.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.2.0
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any