Skip to content

Commit b9713b7

Browse files
authored
Merge pull request #105 from filak/dev-1.7.6
Dev 1.7.6
2 parents a8903ac + a1edca0 commit b9713b7

File tree

12 files changed

+678
-50
lines changed

12 files changed

+678
-50
lines changed

flask-app/application/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create_app(
5555
dict(
5656
APPLICATION_ROOT=url_prefix,
5757
APP_NAME="MTW",
58-
APP_VER="1.7.5",
58+
APP_VER="1.7.6",
5959
API_VER="1.0.0",
6060
DBVERSION=1.0,
6161
CACHE_DIR=mtu.get_instance_dir(app, "cache"),

flask-app/application/modules/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def intro():
9595
stats_actual = {}
9696
show_stats = False
9797
worker = app.config["WORKER_HOST"]
98-
endpoint = app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/query"
98+
endpoint = mtu.getSparqlEndpoint()
9999

100100
initial = mtu.getStatsFpath("initial")
101101
actual = mtu.getStatsFpath("actual")
@@ -1835,7 +1835,7 @@ def update_stats(stat):
18351835
# fpath = mtu.getStatsFpath(stat)
18361836
lpath = mtu.getLockFpath("stats")
18371837
worker = app.config["WORKER_HOST"]
1838-
endpoint = app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/query"
1838+
endpoint = mtu.getSparqlEndpoint()
18391839

18401840
force = False
18411841
if request.args.get("force"):

flask-app/application/modules/sparql.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ def clear_cached(dui=None, cache=None):
2727

2828
def show_elapsed(begin, tag=""):
2929

30-
# TURN OFF:
31-
return
32-
3330
elapsed = timer() - begin
34-
print(" %.3f" % elapsed, tag)
31+
32+
if app.debug:
33+
print("Elapsed: %.3f" % elapsed, tag)
3534

3635
return elapsed
3736

@@ -94,14 +93,13 @@ def getSparqlData(
9493
if app.debug:
9594
print(sparql, "\n")
9695

97-
endpoint = app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/query"
96+
endpoint = mtu.getSparqlEndpoint()
9897

9998
if output in ["tsv", "csv", "json"]:
10099
endpoint += "?format=" + output
101100

102101
headers = {"Content-Type": "application/sparql-query; charset=utf-8"}
103-
# headers = {'Content-Type': 'application/sparql-query; charset=utf-8', 'Connection': 'close'}
104-
# headers = {'Content-Type': 'application/sparql-query; charset=utf-8', 'Connection': 'keep-alive'}
102+
# headers = {"Content-Type": "application/sparql-query; charset=utf-8", "Accept-Encoding": "gzip"}
105103

106104
try:
107105
with closing(
@@ -206,13 +204,16 @@ def updateSparqlBatch(
206204
)
207205
# print(sparql)
208206

209-
endpoint = app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/update"
207+
endpoint = mtu.getSparqlEndpoint(sufix="update")
210208
headers = {
211209
"Accept": "application/json",
212210
"Content-Type": "application/sparql-update; charset=utf-8",
213211
"Connection": "close",
214212
}
215213

214+
# if app.debug:
215+
# print(sparql, "\n")
216+
216217
try:
217218
with closing(
218219
requests.post(
@@ -264,13 +265,16 @@ def updateTriple(
264265
)
265266
# pp.pprint(sparql)
266267

267-
endpoint = app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/update"
268+
endpoint = mtu.getSparqlEndpoint(sufix="update")
268269
headers = {
269270
"Accept": "application/json",
270271
"Content-Type": "application/sparql-update; charset=utf-8",
271272
"Connection": "close",
272273
}
273274

275+
if app.debug:
276+
print(sparql, "\n")
277+
274278
try:
275279
with closing(
276280
requests.post(

flask-app/application/modules/utils.py

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ def getLocalConfValue(conf, fp=""):
277277
print("ERROR: " + error)
278278

279279

280+
def getSparqlEndpoint(sufix="query"):
281+
return app.config["SPARQL_HOST"] + app.config["SPARQL_DATASET"] + "/" + sufix
282+
283+
280284
def refreshStats(stat, force=False):
281285
interval = None
282286
lpath = getLockFpath("stats")
@@ -1138,14 +1142,18 @@ def getMarcFields(
11381142
btd = {}
11391143
btdx = []
11401144
for d in item.get("btd", []):
1141-
des = descriptors.get(d)
1142-
if des.get("active", True) is True:
1143-
trx = des.get("trx")
1144-
if not trx:
1145-
trx = des.get("eng")
1145+
if d.startswith("Q"):
1146+
des = qualifiers.get(d)
1147+
else:
1148+
des = descriptors.get(d)
1149+
if des:
1150+
if des.get("active", True) is True:
1151+
trx = des.get("trx")
1152+
if not trx:
1153+
trx = des.get("eng")
11461154

1147-
btd[trx] = d
1148-
btdx.append(trx)
1155+
btd[trx] = d
1156+
btdx.append(trx)
11491157

11501158
for x in sorted(btdx, key=coll.sort_key):
11511159
xtr = "$w" + fw + "g" + fw + "$a" + fw + x + fw + "$7" + fw + btd[x]
@@ -1154,14 +1162,18 @@ def getMarcFields(
11541162
ntd = {}
11551163
ntdx = []
11561164
for d in item.get("ntd", []):
1157-
des = descriptors.get(d)
1158-
if des.get("active", True) is True:
1159-
trx = des.get("trx")
1160-
if not trx:
1161-
trx = des.get("eng")
1165+
if d.startswith("Q"):
1166+
des = qualifiers.get(d)
1167+
else:
1168+
des = descriptors.get(d)
1169+
if des:
1170+
if des.get("active", True) is True:
1171+
trx = des.get("trx")
1172+
if not trx:
1173+
trx = des.get("eng")
11621174

1163-
ntd[trx] = d
1164-
ntdx.append(trx)
1175+
ntd[trx] = d
1176+
ntdx.append(trx)
11651177

11661178
for x in sorted(ntdx, key=coll.sort_key):
11671179
xtr = "$w" + fw + "h" + fw + "$a" + fw + x + fw + "$7" + fw + ntd[x]
@@ -1170,14 +1182,19 @@ def getMarcFields(
11701182
rtd = {}
11711183
rtdx = []
11721184
for d in item.get("rtd", []):
1173-
des = descriptors.get(d)
1174-
if des.get("active", True) is True:
1175-
trx = des.get("trx")
1176-
if not trx:
1177-
trx = des.get("eng")
1185+
if d.startswith("Q"):
1186+
des = qualifiers.get(d)
1187+
else:
1188+
des = descriptors.get(d)
1189+
if des:
1190+
des = descriptors.get(d)
1191+
if des.get("active", True) is True:
1192+
trx = des.get("trx")
1193+
if not trx:
1194+
trx = des.get("eng")
11781195

1179-
rtd[trx] = d
1180-
rtdx.append(trx)
1196+
rtd[trx] = d
1197+
rtdx.append(trx)
11811198

11821199
for x in sorted(rtdx, key=coll.sort_key):
11831200
xtr = (
@@ -1203,13 +1220,14 @@ def getMarcFields(
12031220
pax = []
12041221
for d in item.get("pa", []):
12051222
des = descriptors.get(d)
1206-
if des.get("active", True) is True:
1207-
trx = des.get("trx")
1208-
if not trx:
1209-
trx = des.get("eng")
1210-
1211-
pa[trx] = d
1212-
pax.append(trx)
1223+
if des:
1224+
if des.get("active", True) is True:
1225+
trx = des.get("trx")
1226+
if not trx:
1227+
trx = des.get("eng")
1228+
1229+
pa[trx] = d
1230+
pax.append(trx)
12131231

12141232
for x in sorted(pax, key=coll.sort_key):
12151233
xtr = (

flask-app/application/templates/sparql/search.sparql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ WHERE {
136136
?descriptor meshv:preferredConcept ?concept2 .
137137
?concept2 mesht:preferredTerm ?pt2 .
138138
?pt2 mesht:prefLabel ?label_cs .
139-
FILTER(lang(?label_cs) = "cs")
139+
FILTER(lang(?label_cs) = "{{ lang }}")
140140
}
141141

142142
#################################################################

0 commit comments

Comments
 (0)