-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_index.py
159 lines (145 loc) · 4.61 KB
/
create_index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
from data.personen import personen
from data.locaties import locaties
from data.commissies import commissies
from data.hoedanigheden import hoedanigheden
from data.organisaties import organisaties
from indexer import Indexer
def index_peronen():
for pers in personen:
element = {}
element["id"] = pers["id"]
element["name"] = pers["name"]
element["category"] = 'Persoonsnaam'
element["labels"] = pers["labels"]
element = add_labels(element)
element["raa"] = pers["raa"]
element = add_raa(element)
element["delegates"] = pers["delegates"]
element = add_delegates(element)
element["envoyes"] = pers["envoyes"]
element = add_envoys(element)
indexer.add_to_index(element)
def index_organisaties():
for organisatie in organisaties:
element = {}
element["id"] = organisatie["id"]
element["name"] = organisatie["name"]
element["category"] = 'Organisatie'
element["labels"] = organisatie["labels"]
element = add_labels(element)
element["links"] = organisatie["links"]
indexer.add_to_index(element)
def index_commissies():
for commissie in commissies:
element = {}
element["id"] = commissie["id"]
element["name"] = commissie["name"]
element["category"] = 'Commissie'
if commissie["comment"]:
element["comment"] = commissie["comment"]
element["labels"] = commissie["labels"]
element = add_labels(element)
indexer.add_to_index(element)
def index_hoedanigheden():
for hoedanigheid in hoedanigheden:
element = {}
element["id"] = hoedanigheid["id"]
element["name"] = hoedanigheid["name"]
element["category"] = 'Hoedanigheid'
element["labels"] = hoedanigheid["labels"]
element = add_labels(element)
indexer.add_to_index(element)
def index_locaties():
for locatie in locaties:
element = {}
element["id"] = locatie["id"]
element["name"] = locatie["name"]
try:
element["comment"] = locatie["comment"]
except:
pass
try:
element["links"] = locatie["links"]
except:
pass
element["geo_data"] = locatie["geo_data"]
element["category"] = "Locatie"
try:
element["labels"] = locatie["labels"]
element = add_labels(element)
except:
print("No labels")
element = get_lat_lon(element)
indexer.add_to_index(element)
def get_lat_lon(el):
try:
point = el["geo_data"]["coordinates"]
point = point.replace("(", "");
point = point.replace(")", "");
latlon = point.split(',')
el["geo_data"].update({'lat': latlon[0].strip(), 'lon': latlon[1].strip()})
except Exception as error:
print(error)
return el
def add_raa(el):
if el["raa"] and len(el["raa"]) > 0:
buffer = []
for element in el["raa"]:
buffer.append({"name": element[0], "id": element[1]})
el["raa"] = buffer
else:
el.pop('raa')
return el
def add_delegates(el):
if el["delegates"] and len(el["delegates"]) > 0:
buffer = []
for element in el["delegates"]:
buffer.append({"name": element[0], "id": element[1]})
el["delegates"] = buffer
if not el["name"]:
el["name"] = add_name(el["delegates"])
else:
el.pop('delegates')
return el
def add_name(list):
buffer = list[0][0].split(',')
return buffer[0]
def add_envoys(el):
if el["envoyes"] and len(el["envoyes"]) > 0:
buffer = []
item = {}
for element in el["envoyes"]:
if len(item) == 0:
item['name'] = element
else:
if len(item) == 1:
item['link'] = element
buffer.append(item)
item = {}
el["envoyes"] = buffer
if not el['name']:
el["name"] = el["envoyes"][0]["name"].split(',')[0]
else:
el.pop('envoyes')
return el
def add_labels(el):
if el["labels"] and len(el["labels"]) > 0:
buffer = []
for label in el["labels"]:
buffer.append({"label": label})
el["labels"] = buffer
else:
el.pop('labels')
return el
indexer = Indexer()
index_peronen()
print("Persons indexed...")
index_locaties()
print("Locations indexed...")
index_commissies()
print("Commissions indexed...")
index_hoedanigheden()
print("Roles indexed...")
index_organisaties()
print("Organisations indexed...")
print("All done!")