Skip to content

Commit 5eb4c26

Browse files
committed
Load ID map from file
1 parent 1eea3c6 commit 5eb4c26

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import libs.LidoRDFConverter as LRC
33
from pathlib import Path
44
from libs.x3ml_classes import X3ml
5+
from libs.x3ml import load_lido_map
56
from flask import Flask, render_template, request, jsonify, make_response
67
import logging
78
import json
@@ -175,6 +176,7 @@ def get_version_data():
175176
logging.basicConfig(filename='app.log', level=logging.INFO)
176177

177178
get_version_data()
179+
load_lido_map()
178180

179181
if args.wsgi:
180182
print(f"Starting WSGI server at http://localhost:{args.port}/")

libs/x3ml.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def elements(self, elem: etree.Element) -> list:
159159
return ch
160160
return []
161161

162-
162+
163163
'''Mapping lido tags to its ID hosts'''
164164
LIDO_ID_MAP = {
165165
'lido:lido': ID_Host('lido:lidoRecID'),
@@ -179,6 +179,19 @@ def elements(self, elem: etree.Element) -> list:
179179
'lido:repositoryName': ID_Host('lido:legalBodyID')
180180
}
181181

182+
def load_lido_map(fname='./lido-id-map.json'):
183+
'''Loads the LIDO ID map from file'''
184+
global LIDO_ID_MAP
185+
p = Path(fname)
186+
if p.is_file():
187+
LIDO_ID_MAP.clear()
188+
data = json.loads(p.read_text(encoding='UTF-8'))
189+
for k, v in data.get('mapping').items():
190+
if w := v.get('tags'):
191+
LIDO_ID_MAP[k] = ID_Host_List(tags=w)
192+
elif w := v.get('tag'):
193+
LIDO_ID_MAP[k] = ID_Host(tag=w)
194+
182195

183196
def get_ID_elements(elem):
184197
'''Returns all ID child elements'''

lido-id-map.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
"tag": "lido:workID"
2020
},
2121
"lido:place": {
22-
"tags": [
23-
"lido:placeID",
24-
"lido:namePlaceSet/lido:appellationValue"
25-
]
22+
"tag": "lido:placeID"
2623
},
2724
"lido:namePlaceSet": {
2825
"tag": "lido:appellationValue"

0 commit comments

Comments
 (0)