personal_knowledge_library 3.1.0__py3-none-any.whl → 3.1.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 personal_knowledge_library might be problematic. Click here for more details.
- knowledge/__init__.py +1 -1
- knowledge/public/cache.py +1 -1
- knowledge/public/client.py +33 -15
- knowledge/public/wikidata.py +1 -1
- {personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/METADATA +1 -1
- {personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/RECORD +8 -8
- {personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/LICENSE +0 -0
- {personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/WHEEL +0 -0
knowledge/__init__.py
CHANGED
knowledge/public/cache.py
CHANGED
|
@@ -53,7 +53,7 @@ class WikidataCache:
|
|
|
53
53
|
|
|
54
54
|
_instance = None # Singleton instance
|
|
55
55
|
|
|
56
|
-
def __init__(self, max_size: int =
|
|
56
|
+
def __init__(self, max_size: int = 100000):
|
|
57
57
|
self.max_size = max_size
|
|
58
58
|
self.cache: OrderedDict = OrderedDict() # Maintain insertion order for LRU eviction
|
|
59
59
|
self.property_cache: OrderedDict = OrderedDict() # Cache for properties
|
knowledge/public/client.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import multiprocessing
|
|
4
4
|
from collections import deque
|
|
5
5
|
from multiprocessing import Pool
|
|
6
|
-
from typing import Union, Any, Dict, List, Tuple, Set
|
|
6
|
+
from typing import Union, Any, Dict, List, Tuple, Set, Optional, Callable
|
|
7
7
|
|
|
8
8
|
import requests
|
|
9
9
|
from requests import Response
|
|
@@ -321,18 +321,10 @@ class WikiDataAPIClient:
|
|
|
321
321
|
"""
|
|
322
322
|
try:
|
|
323
323
|
results: List[WikidataThing] = []
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if wikidata_cache.qid_in_cache(qid):
|
|
327
|
-
results.append(wikidata_cache.get_wikidata_object(qid))
|
|
328
|
-
else:
|
|
329
|
-
request_qids.append(qid)
|
|
330
|
-
if len(request_qids) > 0:
|
|
331
|
-
for e in __waiting_multi_request__(request_qids):
|
|
324
|
+
if len(qids) > 0:
|
|
325
|
+
for e in __waiting_multi_request__(qids):
|
|
332
326
|
w_thing = WikidataThing.from_wikidata(e)
|
|
333
327
|
results.append(w_thing)
|
|
334
|
-
# Add the thing to the cache
|
|
335
|
-
wikidata_cache.cache_wikidata_object(w_thing)
|
|
336
328
|
return results
|
|
337
329
|
except Exception as e:
|
|
338
330
|
logger.exception(e)
|
|
@@ -356,13 +348,16 @@ class WikiDataAPIClient:
|
|
|
356
348
|
return WikiDataAPIClient.__wikidata_task__(qid)
|
|
357
349
|
|
|
358
350
|
@staticmethod
|
|
359
|
-
def retrieve_entities(qids: Union[List[str], Set[str]]
|
|
351
|
+
def retrieve_entities(qids: Union[List[str], Set[str]], progress: Optional[Callable[[int, int], None]] = None) \
|
|
352
|
+
-> List[WikidataThing]:
|
|
360
353
|
"""
|
|
361
354
|
Retrieve multiple Wikidata things.
|
|
362
355
|
Parameters
|
|
363
356
|
----------
|
|
364
357
|
qids: List[str]
|
|
365
358
|
QIDs of the entities.
|
|
359
|
+
progress: Optional[Callable[[int, int], None]]
|
|
360
|
+
Optional callback function to report progress.
|
|
366
361
|
|
|
367
362
|
Returns
|
|
368
363
|
-------
|
|
@@ -370,17 +365,40 @@ class WikiDataAPIClient:
|
|
|
370
365
|
List of wikidata things.
|
|
371
366
|
"""
|
|
372
367
|
pulled: List[WikidataThing] = []
|
|
368
|
+
task_size: int = len(qids)
|
|
373
369
|
if len(qids) == 0:
|
|
374
370
|
return []
|
|
375
|
-
|
|
371
|
+
missing_qids: List[str] = []
|
|
372
|
+
for qid in qids:
|
|
373
|
+
if not wikidata_cache.qid_in_cache(qid):
|
|
374
|
+
if qid and qid.startswith("Q") and len(qid) > 1:
|
|
375
|
+
missing_qids.append(qid)
|
|
376
|
+
else:
|
|
377
|
+
pulled.append(wikidata_cache.get_wikidata_object(qid))
|
|
378
|
+
ctr: int = len(pulled)
|
|
379
|
+
if progress:
|
|
380
|
+
progress(len(pulled), task_size)
|
|
381
|
+
jobs: List[List[str]] = list(chunks(list(missing_qids), API_LIMIT))
|
|
376
382
|
num_processes: int = min(len(jobs), multiprocessing.cpu_count())
|
|
377
383
|
if num_processes > 1:
|
|
378
384
|
with Pool(processes=num_processes) as pool:
|
|
379
385
|
# Wikidata thing is not support in multiprocessing
|
|
380
386
|
for lst in pool.imap_unordered(__waiting_multi_request__, jobs):
|
|
381
|
-
|
|
387
|
+
for w_dict in lst:
|
|
388
|
+
w_thing = WikidataThing.from_wikidata(w_dict)
|
|
389
|
+
wikidata_cache.cache_wikidata_object(w_thing)
|
|
390
|
+
pulled.append(w_thing)
|
|
391
|
+
ctr += 1
|
|
392
|
+
if progress:
|
|
393
|
+
progress(ctr, task_size)
|
|
382
394
|
else:
|
|
383
|
-
|
|
395
|
+
results = WikiDataAPIClient.__wikidata_multiple_task__(jobs[0])
|
|
396
|
+
for w_thing in results:
|
|
397
|
+
wikidata_cache.cache_wikidata_object(w_thing)
|
|
398
|
+
ctr += 1
|
|
399
|
+
if progress:
|
|
400
|
+
progress(ctr, task_size)
|
|
401
|
+
pulled.extend(results)
|
|
384
402
|
return pulled
|
|
385
403
|
|
|
386
404
|
@staticmethod
|
knowledge/public/wikidata.py
CHANGED
|
@@ -877,7 +877,7 @@ class WikidataThing:
|
|
|
877
877
|
val = {"tabular": data_value["value"]}
|
|
878
878
|
elif data_type == "entity-schema":
|
|
879
879
|
val = {"id": data_value["value"]["id"]}
|
|
880
|
-
elif data_type
|
|
880
|
+
elif data_type in ["wikibase-form", "musical-notation"]:
|
|
881
881
|
continue
|
|
882
882
|
else:
|
|
883
883
|
raise WikiDataAPIException(f"Data type: {data_type} not supported.")
|
{personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/RECORD
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
knowledge/__init__.py,sha256=
|
|
1
|
+
knowledge/__init__.py,sha256=UL4La2Ep9cXbMd4imaLqt6UCqBhjLjusWHDZXU8Pc8s,2680
|
|
2
2
|
knowledge/base/__init__.py,sha256=q0NJRQLhfZ8khE-uZCK0SVA38dzbaMomcgL5Olnjtio,895
|
|
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
|
|
@@ -12,11 +12,11 @@ knowledge/nel/engine.py,sha256=qvQkfsdeYPWJ_5m8mmGFw1tvd699vOQ3IKoBIwALRWk,5347
|
|
|
12
12
|
knowledge/ontomapping/__init__.py,sha256=9E-rZpxQPfukjDz_0ymrRieYDpv_e3tvpqDfkWzPJy0,18846
|
|
13
13
|
knowledge/ontomapping/manager.py,sha256=pXBwRGSTcS731df5vewNv6oMgP18HzvnjZqiUgyFIhI,13361
|
|
14
14
|
knowledge/public/__init__.py,sha256=FrW5sqJGVcIfg5IVpt_g7qlWiIYNGA370jkE5mJDhoo,812
|
|
15
|
-
knowledge/public/cache.py,sha256=
|
|
16
|
-
knowledge/public/client.py,sha256=
|
|
15
|
+
knowledge/public/cache.py,sha256=uKEuW9WN9xPmY-fwWPLSxmdEP6xg-XG3g8fKAmGZgBQ,14510
|
|
16
|
+
knowledge/public/client.py,sha256=KA8EwLHAjn1-ggT8keUMaKIJnbJDlFEp0j8V0RT_32I,15437
|
|
17
17
|
knowledge/public/helper.py,sha256=PDsInMHMHgP8rMvcFk5E47afdE3rC7V3BzPS-DdOsww,13238
|
|
18
18
|
knowledge/public/relations.py,sha256=DrL-rYuwLzaE2H2TOM2gG1TGqHbkcPL4EsRD54LQqLs,4182
|
|
19
|
-
knowledge/public/wikidata.py,sha256=
|
|
19
|
+
knowledge/public/wikidata.py,sha256=LwMP2kq2mH5Oi9JhPvG8lN9pZMDlQvxgaZgQKQO3kaM,36683
|
|
20
20
|
knowledge/services/__init__.py,sha256=FQMTLg7RYglLwCtEO0sOrgj55YrzSNqJV-yj3aqttb8,3490
|
|
21
21
|
knowledge/services/asyncio/__init__.py,sha256=dq9yGTxg_hoQb8E1kEtY4AeB8zrdJfw3-XlPoYn2j5U,225
|
|
22
22
|
knowledge/services/asyncio/base.py,sha256=im6J1CWOp1N1tt6WdJ1uU0R-VFpvdYc6lZu8TyPrU5A,16222
|
|
@@ -37,7 +37,7 @@ knowledge/utils/__init__.py,sha256=rgLqdgZwjuCnqA4NEY9echbGFaJ5YUhqBEkyVv9R9CM,2
|
|
|
37
37
|
knowledge/utils/graph.py,sha256=kuPZEGhexVN9McoT8JK2ViIrfXTh-nFPv_8XPfG0wlA,12318
|
|
38
38
|
knowledge/utils/wikidata.py,sha256=vRH-4AMR-3xywyvmDqbjI4KSw4tF4TEYqUGCJmUMqK8,5512
|
|
39
39
|
knowledge/utils/wikipedia.py,sha256=rBuFqYVM58JCj5ISLxuhYVVl2gOIlPLWx7_CghyQgvE,5052
|
|
40
|
-
personal_knowledge_library-3.1.
|
|
41
|
-
personal_knowledge_library-3.1.
|
|
42
|
-
personal_knowledge_library-3.1.
|
|
43
|
-
personal_knowledge_library-3.1.
|
|
40
|
+
personal_knowledge_library-3.1.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
41
|
+
personal_knowledge_library-3.1.1.dist-info/METADATA,sha256=kJZ15MOIszkwgs8hv6YMnKXLc0RKNyFfYz9X4r1l6f0,57087
|
|
42
|
+
personal_knowledge_library-3.1.1.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
43
|
+
personal_knowledge_library-3.1.1.dist-info/RECORD,,
|
{personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/LICENSE
RENAMED
|
File without changes
|
{personal_knowledge_library-3.1.0.dist-info → personal_knowledge_library-3.1.1.dist-info}/WHEEL
RENAMED
|
File without changes
|