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

knowledge/__init__.py CHANGED
@@ -17,7 +17,7 @@ __license__ = "Wacom"
17
17
  __maintainer__ = ["Markus Weber"]
18
18
  __email__ = "markus.weber@wacom.com"
19
19
  __status__ = "beta"
20
- __version__ = "3.2.0"
20
+ __version__ = "3.2.2"
21
21
 
22
22
  import loguru
23
23
 
@@ -180,6 +180,61 @@ class AsyncWacomKnowledgeService(AsyncServiceAPIClient):
180
180
  thing: ThingObject = ThingObject.from_dict(e)
181
181
  return thing
182
182
 
183
+ async def entities(self, uris: List[str], locale: Optional[LocaleCode] = None, auth_key: Optional[str] = None) \
184
+ -> List[ThingObject]:
185
+ """
186
+ Retrieve entities information from personal knowledge, using the URI as identifier.
187
+
188
+ **Remark:** Object properties (relations) must be requested separately.
189
+
190
+ Parameters
191
+ ----------
192
+ uris: List[str]
193
+ List of URIs of the entities
194
+ locale: LocaleCode
195
+ ISO-3166 Country Codes and ISO-639 Language Codes in the format <language_code>_<country>, e.g., en_US.
196
+ auth_key: Optional[str]
197
+ Use a different auth key than the one from the client
198
+
199
+ Returns
200
+ -------
201
+ things: List[ThingObject]
202
+ Entities with is type URI, description, an image/icon, and tags (labels).
203
+
204
+ Raises
205
+ ------
206
+ WacomServiceException
207
+ If the graph service returns an error code or the entity is not found in the knowledge graph
208
+ """
209
+ if auth_key is None:
210
+ auth_key, _ = await self.handle_token()
211
+ url: str = f"{self.service_base_url}{AsyncWacomKnowledgeService.ENTITY_ENDPOINT}/"
212
+ headers: Dict[str, str] = {
213
+ USER_AGENT_HEADER_FLAG: self.user_agent,
214
+ AUTHORIZATION_HEADER_FLAG: f"Bearer {auth_key}",
215
+ }
216
+ things: List[ThingObject] = []
217
+ params: Dict[str, Any] = {
218
+ URIS_TAG: uris
219
+ }
220
+ if locale:
221
+ params[LOCALE_TAG] = locale
222
+ async with AsyncServiceAPIClient.__async_session__() as session:
223
+ async with session.get(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
224
+ if response.ok:
225
+ entities: List[Dict[str, Any]] = await response.json()
226
+ for e in entities:
227
+ thing: ThingObject = ThingObject.from_dict(e)
228
+ things.append(thing)
229
+ else:
230
+ raise await handle_error(
231
+ f"Retrieving of entities content failed. List of URIs: {uris}.", response,
232
+ headers=headers
233
+ )
234
+ await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
235
+ # Create ThingObject
236
+ return things
237
+
183
238
  async def set_entity_image_local(self, entity_uri: str, path: Path, auth_key: Optional[str] = None) -> str:
184
239
  """Setting the image of the entity.
185
240
  The image is stored locally.
@@ -213,7 +213,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
213
213
  """
214
214
  if auth_key is None:
215
215
  auth_key, _ = await self.handle_token()
216
- url: str = f"{self.service_base_url}documents/count/filter"
216
+ url: str = f"{self.service_base_url}documents/count/filter/"
217
217
  headers: Dict[str, str] = {
218
218
  USER_AGENT_HEADER_FLAG: self.user_agent,
219
219
  CONTENT_TYPE_HEADER_FLAG: APPLICATION_JSON_HEADER,
@@ -307,7 +307,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
307
307
  """
308
308
  if auth_key is None:
309
309
  auth_key, _ = await self.handle_token()
310
- url: str = f"{self.service_base_url}labels/count/filter"
310
+ url: str = f"{self.service_base_url}labels/count/filter/"
311
311
  headers: Dict[str, str] = {
312
312
  USER_AGENT_HEADER_FLAG: self.user_agent,
313
313
  CONTENT_TYPE_HEADER_FLAG: APPLICATION_JSON_HEADER,
@@ -300,7 +300,8 @@ 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) -> Tuple[str, str, datetime]:
303
+ def request_user_token(self, tenant_api_key: str, external_id: str, timeout: int = DEFAULT_TIMEOUT) \
304
+ -> Tuple[str, str, datetime]:
304
305
  """
305
306
  Login as user by using the tenant key and its external user id.
306
307
 
@@ -310,6 +311,8 @@ class WacomServiceAPIClient(RESTAPIClient):
310
311
  Tenant API key
311
312
  external_id: str
312
313
  External id.
314
+ timeout: int (Default:= DEFAULT_TIMEOUT)
315
+ Timeout for the request in seconds.
313
316
 
314
317
  Returns
315
318
  -------
@@ -333,7 +336,8 @@ class WacomServiceAPIClient(RESTAPIClient):
333
336
  }
334
337
  payload: dict = {EXTERNAL_USER_ID: external_id}
335
338
  response: Response = requests.post(
336
- url, headers=headers, json=payload, timeout=DEFAULT_TIMEOUT, verify=self.verify_calls
339
+ url, headers=headers, json=payload, timeout=timeout, verify=self.verify_calls,
340
+ allow_redirects=True
337
341
  )
338
342
  if response.ok:
339
343
  try:
@@ -18,7 +18,6 @@ from knowledge.base.entity import (
18
18
  DATA_PROPERTIES_TAG,
19
19
  TYPE_TAG,
20
20
  LABELS_TAG,
21
- IS_MAIN_TAG,
22
21
  RELATIONS_TAG,
23
22
  LOCALE_TAG,
24
23
  EntityStatus,
@@ -226,18 +225,74 @@ class WacomKnowledgeService(WacomServiceAPIClient):
226
225
  response: Response = session.get(url, headers=headers, timeout=timeout, verify=self.verify_calls)
227
226
  if response.ok:
228
227
  e: Dict[str, Any] = response.json()
229
- pref_label: List[Label] = []
230
- aliases: List[Label] = []
231
- # Extract labels and alias
232
- for label in e[LABELS_TAG]:
233
- if label[IS_MAIN_TAG]: # Labels
234
- pref_label.append(Label.create_from_dict(label))
235
- else: # Alias
236
- aliases.append(Label.create_from_dict(label))
237
228
  thing: ThingObject = ThingObject.from_dict(e)
238
229
  return thing
239
230
  raise handle_error(f"Retrieving of entity content failed. URI:={uri}.", response)
240
231
 
232
+ def entities(self,
233
+ uris: List[str],
234
+ locale: Optional[LocaleCode] = None,
235
+ auth_key: Optional[str] = None,
236
+ timeout: int = DEFAULT_TIMEOUT,
237
+ max_retries: int = DEFAULT_MAX_RETRIES,
238
+ backoff_factor: float = DEFAULT_BACKOFF_FACTOR,
239
+ ) -> List[ThingObject]:
240
+ """
241
+ Retrieve entity information from personal knowledge, using the URI as identifier.
242
+
243
+ **Remark:** Object properties (relations) must be requested separately.
244
+
245
+ Parameters
246
+ ----------
247
+ uris: List[str]
248
+ List of URIs of entities
249
+ locale: Optional[LocaleCode]
250
+ ISO-3166 Country Codes and ISO-639 Language Codes in the format <language_code>_<country>, e.g., en_US.
251
+ auth_key: Optional[str]
252
+ If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
253
+ timeout: int
254
+ Timeout for the request (default: 60 seconds)
255
+ max_retries: int
256
+ Maximum number of retries (default: 3)
257
+ backoff_factor: float
258
+ A backoff factor to apply between attempts after the second try (most errors are resolved immediately by a
259
+ second try without a delay) (default: 0.1)
260
+
261
+ Returns
262
+ -------
263
+ things: List[ThingObject]
264
+ Entities with is type URI, description, an image/icon, and tags (labels).
265
+
266
+ Raises
267
+ ------
268
+ WacomServiceException
269
+ If the graph service returns an error code or the entity is not found in the knowledge graph
270
+ """
271
+ if auth_key is None:
272
+ auth_key, _ = self.handle_token()
273
+ url: str = f"{self.service_base_url}{WacomKnowledgeService.ENTITY_ENDPOINT}/"
274
+ headers: Dict[str, str] = {
275
+ USER_AGENT_HEADER_FLAG: self.user_agent,
276
+ AUTHORIZATION_HEADER_FLAG: f"Bearer {auth_key}",
277
+ }
278
+ params: Dict[str, Any] = {URIS_TAG: uris}
279
+ if locale is not None:
280
+ params[LOCALE_TAG] = locale
281
+ mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
282
+ with requests.Session() as session:
283
+ retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
284
+ 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)
287
+ if response.ok:
288
+ things: List[ThingObject] = []
289
+ entities: List[Dict[str, Any]] = response.json()
290
+ for e in entities:
291
+ thing: ThingObject = ThingObject.from_dict(e)
292
+ things.append(thing)
293
+ return things
294
+ raise handle_error(f"Retrieving of entity content failed. URIs:={uris}.", response)
295
+
241
296
  def delete_entities(
242
297
  self,
243
298
  uris: List[str],
@@ -2017,7 +2072,7 @@ class WacomKnowledgeService(WacomServiceAPIClient):
2017
2072
 
2018
2073
  def rebuild_nel_index(
2019
2074
  self,
2020
- nel_index: Literal["western", "japanese"],
2075
+ nel_index: Literal["Western", "Japanese"],
2021
2076
  prune: bool = False,
2022
2077
  auth_key: Optional[str] = None,
2023
2078
  timeout: int = DEFAULT_TIMEOUT,
@@ -9,6 +9,7 @@ from requests import Response
9
9
  from requests.adapters import HTTPAdapter
10
10
  from urllib3 import Retry
11
11
 
12
+ from knowledge.base.entity import FORCE_TAG
12
13
  from knowledge.base.ontology import (
13
14
  OntologyClassReference,
14
15
  OntologyPropertyReference,
@@ -1140,6 +1141,7 @@ class OntologyService(WacomServiceAPIClient):
1140
1141
  def commit(
1141
1142
  self,
1142
1143
  context: str,
1144
+ force: bool = False,
1143
1145
  auth_key: Optional[str] = None,
1144
1146
  timeout: int = DEFAULT_TIMEOUT,
1145
1147
  max_retries: int = DEFAULT_MAX_RETRIES,
@@ -1152,6 +1154,8 @@ class OntologyService(WacomServiceAPIClient):
1152
1154
  ----------
1153
1155
  context: str
1154
1156
  Name of the context.
1157
+ force: bool (default:= False)
1158
+ Force commit of the ontology.
1155
1159
  auth_key: Optional[str] [default:= None]
1156
1160
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
1157
1161
  timeout: int
@@ -1170,11 +1174,13 @@ class OntologyService(WacomServiceAPIClient):
1170
1174
  }
1171
1175
  context_url: str = urllib.parse.quote_plus(context)
1172
1176
  url: str = f"{self.service_base_url}context/{context_url}/commit"
1177
+ params: Dict[str, bool] = {FORCE_TAG: force}
1173
1178
  mount_point: str = "https://" if self.service_url.startswith("https") else "http://"
1174
1179
  with requests.Session() as session:
1175
1180
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
1176
1181
  session.mount(mount_point, HTTPAdapter(max_retries=retries))
1177
- response: Response = session.put(url, headers=headers, verify=self.verify_calls, timeout=timeout)
1182
+ response: Response = session.put(url, params=params, headers=headers, verify=self.verify_calls,
1183
+ timeout=timeout)
1178
1184
  if not response.ok:
1179
1185
  raise handle_error("Commit of ontology failed.", response, headers=headers)
1180
1186
 
@@ -241,7 +241,7 @@ class SemanticSearchClient(WacomServiceAPIClient):
241
241
  """
242
242
  if auth_key is None:
243
243
  auth_key, _ = self.handle_token()
244
- url: str = f"{self.service_base_url}documents/count/filter"
244
+ url: str = f"{self.service_base_url}documents/count/filter/"
245
245
  headers: Dict[str, str] = {
246
246
  USER_AGENT_HEADER_FLAG: self.user_agent,
247
247
  CONTENT_TYPE_HEADER_FLAG: APPLICATION_JSON_HEADER,
@@ -263,6 +263,7 @@ class SemanticSearchClient(WacomServiceAPIClient):
263
263
  locale: LocaleCode,
264
264
  concept_type: Optional[str] = None,
265
265
  auth_key: Optional[str] = None,
266
+ timeout: float = DEFAULT_TIMEOUT,
266
267
  max_retries: int = 3,
267
268
  backoff_factor: float = 0.1,
268
269
  ) -> int:
@@ -275,6 +276,8 @@ class SemanticSearchClient(WacomServiceAPIClient):
275
276
  ISO-3166 Country Codes and ISO-639 Language Codes in the format '<language_code>_<country>', e.g., en_US.
276
277
  concept_type: Optional[str] (Default:= None)
277
278
  Concept type.
279
+ timeout: int (Default:= DEFAULT_TIMEOUT)
280
+ Timeout for the request in seconds.
278
281
  max_retries: int
279
282
  Maximum number of retries
280
283
  backoff_factor: float
@@ -306,7 +309,7 @@ class SemanticSearchClient(WacomServiceAPIClient):
306
309
  with requests.Session() as session:
307
310
  retries: Retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=STATUS_FORCE_LIST)
308
311
  session.mount(mount_point, HTTPAdapter(max_retries=retries))
309
- response = session.get(url, params=params, headers=headers)
312
+ response = session.get(url, params=params, headers=headers, timeout=timeout)
310
313
  if response.ok:
311
314
  return response.json().get("count", 0)
312
315
  raise handle_error("Counting labels failed.", response, headers=headers, parameters={"locale": locale})
@@ -347,7 +350,7 @@ class SemanticSearchClient(WacomServiceAPIClient):
347
350
  """
348
351
  if auth_key is None:
349
352
  auth_key, _ = self.handle_token()
350
- url: str = f"{self.service_base_url}labels/count/filter"
353
+ url: str = f"{self.service_base_url}labels/count/filter/"
351
354
  headers: Dict[str, str] = {
352
355
  USER_AGENT_HEADER_FLAG: self.user_agent,
353
356
  CONTENT_TYPE_HEADER_FLAG: APPLICATION_JSON_HEADER,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: personal_knowledge_library
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Library to access Wacom's Personal Knowledge graph.
5
5
  License: Apache-2.0
6
6
  Keywords: semantic-knowledge,knowledge-graph
@@ -1,4 +1,4 @@
1
- knowledge/__init__.py,sha256=xx1SZgmFpjbHD3ZgpA9Bdbh5YaadA-vu2Y6MPsu6rvY,2680
1
+ knowledge/__init__.py,sha256=Xl8GZrILXBXgRRuaZ8VHRIBptdEs6Koa4IeL4c-lxj0,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
@@ -21,16 +21,16 @@ knowledge/public/wikidata.py,sha256=LwMP2kq2mH5Oi9JhPvG8lN9pZMDlQvxgaZgQKQO3kaM,
21
21
  knowledge/services/__init__.py,sha256=Pg4Pd9cCRiQ4-v3E0WCqldOhJFcMmkZrQHA7BY1Z1K8,3604
22
22
  knowledge/services/asyncio/__init__.py,sha256=dq9yGTxg_hoQb8E1kEtY4AeB8zrdJfw3-XlPoYn2j5U,225
23
23
  knowledge/services/asyncio/base.py,sha256=im6J1CWOp1N1tt6WdJ1uU0R-VFpvdYc6lZu8TyPrU5A,16222
24
- knowledge/services/asyncio/graph.py,sha256=BRU8kLgKt7KNuyzlgT2PEVwa7ig-S-sR0AWMTYkp5NE,62401
24
+ knowledge/services/asyncio/graph.py,sha256=MXcAf1XnQ2b36eUMAL8m731f_GMgOtBNmDtAKqurzjE,64719
25
25
  knowledge/services/asyncio/group.py,sha256=UKbk8vnPqqAkuc5gAd6g3IVOKmUJNqG2lreZM0O-hRg,18356
26
- knowledge/services/asyncio/search.py,sha256=_ESVbNGLYbo7EmyMLtsh0pRiRHIyGeBicrcD2JKbFwY,16215
26
+ knowledge/services/asyncio/search.py,sha256=fm1j6fJDQx831B82bqmZ3czYrYH3qtPCYlisSF26M5g,16217
27
27
  knowledge/services/asyncio/users.py,sha256=NJ7xagjr4gF6yKJXdwa0bz0eaYlQDee5RCEpfQJEHWk,10274
28
- knowledge/services/base.py,sha256=gXBIkbk7wXGrm_hZGfLvft7-E8fcSMjl-HIsLxfRZ6c,17849
29
- knowledge/services/graph.py,sha256=XhbB2-3CUkQ9-NdVoW9pcQfnItaX6H07WVTsK3ynZ5I,86888
28
+ knowledge/services/base.py,sha256=PdHfObShUBpbAS71LBhe5jOA13Y1JXbUkhRi9op8wis,18018
29
+ knowledge/services/graph.py,sha256=d5TLQOH7DiVcjQKaR8ZGHOGePcOhlRQnEDmIqlqkojI,89392
30
30
  knowledge/services/group.py,sha256=b8dBBrHXqgwpJ7BtUqqweoR_WQH5MZ0aLh0fBBTyHUI,30698
31
31
  knowledge/services/helper.py,sha256=NYhRkYXtiFgovsXaQr6rBVN2mjBwOT7cSSuLTyjvzKA,4990
32
- knowledge/services/ontology.py,sha256=u89S3GV0C2FWAviQxd5fvoCQWzo8EhYix7fQc1bEEc0,51534
33
- knowledge/services/search.py,sha256=-qB9J1pyqoq3RlH7iDlgozBImKFzTx1p1kC0XKWAPEs,19147
32
+ knowledge/services/ontology.py,sha256=1QewHZoNTNrQe9cAgLMvWRPQ2YYn4IltscEOV9Dy2qM,51800
33
+ knowledge/services/search.py,sha256=9I4ZdCFnVSCCmYHeQralrw47VwKnMqA08UpAq_BMxQs,19305
34
34
  knowledge/services/session.py,sha256=y8uTETRMDOBbC30UAlrrtWTN7Zgs2klqHsoMjLO2tq0,14145
35
35
  knowledge/services/tenant.py,sha256=rQsUe8qNFTt_WZG4XBTg8QSLoyavuCWLWk3QhU1fBG8,11728
36
36
  knowledge/services/users.py,sha256=nOwyZhqERTNFPTN21c_q7-6XaEMb3SnHfnXr4Kf22qk,16594
@@ -40,7 +40,7 @@ knowledge/utils/graph.py,sha256=kuPZEGhexVN9McoT8JK2ViIrfXTh-nFPv_8XPfG0wlA,1231
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.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
- personal_knowledge_library-3.2.0.dist-info/METADATA,sha256=4RhzFCxjAyhFmnRavgdpwY5x-9PWs9p08tEqd9j1f6U,57087
45
- personal_knowledge_library-3.2.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
- personal_knowledge_library-3.2.0.dist-info/RECORD,,
43
+ personal_knowledge_library-3.2.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
+ personal_knowledge_library-3.2.2.dist-info/METADATA,sha256=KBcGxJbB9Wqbt9snudWw3modgrNlirPNrF96kVOlbnA,57087
45
+ personal_knowledge_library-3.2.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
+ personal_knowledge_library-3.2.2.dist-info/RECORD,,