-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcone_pers.py
46 lines (33 loc) · 1.14 KB
/
cone_pers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from tqdm import tqdm
from pybman import utils
from pybman.rest import PersonConeController
from .utils_paths import BASE_DIR
PURE_DIR = BASE_DIR + 'pure/'
#######################################
### RETRIEVE LIST OF PERSONS (CoNE) ###
#######################################
pers_controller = PersonConeController()
pers = pers_controller.get_entities()
utils.write_json(PURE_DIR + "pers/all.json", pers)
##############################
### EXTRACT UNIQUE PERSONS ###
##############################
pers_unique = {}
for p in pers:
idx = p['id'].split("/")[-1:][0]
if idx in pers_unique:
pers_unique[idx].append(p['value'])
else:
pers_unique[idx] = [p['value']]
utils.write_json(PURE_DIR + "pers/unique.json", pers_unique)
###############################################
### RETRIEVE INDIVIDUAL ENTRIES FOR PERSONS ###
###############################################
pers_ids = list(pers_unique.keys())
pers_ids.sort()
# request data
pers_data = {}
for idx in tqdm(pers_ids):
pers_details = pers_controller.get_entity(idx)
pers_data[idx] = pers_details
utils.write_json(PURE_DIR + "pers/collection.json", pers_data)