diff --git a/flask-app/application/modules/routes.py b/flask-app/application/modules/routes.py index a04a249..a73e45b 100644 --- a/flask-app/application/modules/routes.py +++ b/flask-app/application/modules/routes.py @@ -836,11 +836,12 @@ def compare(dui): if dui: dui = dui.replace('?', '').strip() - dview_data = sparql.getSparqlData('descriptor_view', query=dui, output='tsv', key=dui + '_diff', cache=cache) + otype = getObjType(dui) + dview_data = sparql.getSparqlData('descriptor_view', query=dui, output='tsv', key=dui + '_diff', cache=cache, otype=otype) if dview_data: dview = mtu.cleanDescView(dview_data) - prev_data = sparql.getSparqlDataExt(dui, 'tsv', year=year, key=dui + '_prev_' + year, cache=cache) + prev_data = sparql.getSparqlDataExt(dui, 'tsv', year=year, key=dui + '_prev_' + year, cache=cache, otype=otype) if prev_data: prev = mtu.cleanDescView(prev_data) @@ -1129,7 +1130,8 @@ def search(dui, action): tree = sparql.parseSparqlData(tree_data) started = timer() - dview = sparql.getSparqlData('descriptor_view_trx', query=dui, output='tsv', key=dui + '_dview', cache=cache) + otype = getObjType(dui) + dview = sparql.getSparqlData('descriptor_view_trx', query=dui, output='tsv', key=dui + '_dview', cache=cache, otype=otype) show_elapsed(t0, started=started, tag='dview_data') dview = mtu.cleanDescView(dview) @@ -1702,6 +1704,13 @@ def logout(): # Functions, context_processors, etc. +def getObjType(dui): + otype = "Descriptor" + if dui.startswith('Q'): + otype = "Qualifier" + return otype + + def checkWorker(worker): try: with closing(requests.get(worker, timeout=10)) as r: diff --git a/flask-app/application/modules/sparql.py b/flask-app/application/modules/sparql.py index 1291391..92f6da3 100644 --- a/flask-app/application/modules/sparql.py +++ b/flask-app/application/modules/sparql.py @@ -35,7 +35,7 @@ def show_elapsed(begin, tag=''): return elapsed -def getSparqlData(template, query='', show='', status='', top='', tn='', concept='', +def getSparqlData(template, query='', show='', status='', top='', tn='', concept='', otype='Descriptor', output='json', slang=None, lang=None, scr=None, key=None, cache=None): t0 = timer() @@ -58,7 +58,7 @@ def getSparqlData(template, query='', show='', status='', top='', tn='', concept lang_umls = mtu.getLangCodeUmls(lang) - sparql = render_template('sparql/' + template + '.sparql', query=cleanQuery(query), + sparql = render_template('sparql/' + template + '.sparql', query=cleanQuery(query), otype=otype, show=show, status=status, top=top, tn=tn, toptn=toptn, concept=concept, lang=lang, lang_umls=lang_umls, slang=slang, scr=scr) @@ -92,7 +92,7 @@ def getSparqlData(template, query='', show='', status='', top='', tn='', concept app.logger.error('%s \n\n %s \n\n %s \n\n %s', endpoint, template, query, str(err)) -def getSparqlDataExt(dui, output, year='', key=None, cache=None): +def getSparqlDataExt(dui, output, year='', key=None, cache=None, otype='Descriptor'): if key and cache: if cache.get(key): @@ -100,7 +100,7 @@ def getSparqlDataExt(dui, output, year='', key=None, cache=None): endpoint = app.config['MESH_RDF'] - dview_ext_query = render_template('sparql/descriptor_view.sparql', query=dui, official=True, year=year) + dview_ext_query = render_template('sparql/descriptor_view.sparql', query=dui, official=True, year=year, otype=otype) # print(dview_ext_query) query = mtu.encodeMeshRdfQuery(dview_ext_query) @@ -343,7 +343,7 @@ def parseDescriptor(descriptor): val = row['label']['value'] qualifiers.append({'ui': ui, 'val': val}) - elif p in ['broaderDescriptor', 'seeAlso', 'pharmacologicalAction', 'preferredTerm']: + elif p in ['broaderDescriptor', 'broaderQualifier', 'seeAlso', 'pharmacologicalAction', 'preferredTerm']: if p == 'preferredTerm': result['labels']['prefTerm'] = row['o']['value'].replace(app.config['SOURCE_NS'], '') else: diff --git a/flask-app/application/templates/sparql/descriptor_view.sparql b/flask-app/application/templates/sparql/descriptor_view.sparql index 16cca96..c65828d 100644 --- a/flask-app/application/templates/sparql/descriptor_view.sparql +++ b/flask-app/application/templates/sparql/descriptor_view.sparql @@ -4,7 +4,7 @@ {% include 'sparql/_namespaces.sparql' %} {% endif %} -## Descriptor view query v1.0 +## Descriptor view query v1.1 SELECT DISTINCT * { {SELECT ?p ?o @@ -63,10 +63,10 @@ WHERE { }} UNION { SELECT ?p ?o WHERE { - BIND(meshv:narrowerDescriptor as ?p) + BIND(meshv:narrower{{ otype }} as ?p) ?id ?px mesh:{{ query }} . ?id rdfs:label ?val - FILTER(?px IN(meshv:broaderDescriptor)) + FILTER(?px IN(meshv:broader{{ otype }})) FILTER(!isLiteral(?id)) BIND(STR(?val) AS ?o) }} UNION { @@ -89,3 +89,4 @@ WHERE { }} } ORDER BY ?p ?o + diff --git a/flask-app/application/templates/sparql/descriptor_view_trx.sparql b/flask-app/application/templates/sparql/descriptor_view_trx.sparql index ca4a5e6..b28d16c 100644 --- a/flask-app/application/templates/sparql/descriptor_view_trx.sparql +++ b/flask-app/application/templates/sparql/descriptor_view_trx.sparql @@ -1,7 +1,7 @@ {% include 'sparql/_namespaces.sparql' %} PREFIX a: -## Descriptor trx view query v1.0 +## Descriptor trx view query v1.1 SELECT DISTINCT * { {SELECT ?p ?o @@ -61,8 +61,8 @@ WHERE { }} UNION { SELECT ?p ?o WHERE { - BIND(meshv:narrowerDescriptor as ?p) - ?id meshv:broaderDescriptor mesh:{{ query }} . + BIND(meshv:narrower{{ otype }} as ?p) + ?id meshv:broader{{ otype }} mesh:{{ query }} . ?id rdfs:label ?val FILTER(!isLiteral(?id)) BIND(STR(?val) AS ?o) diff --git a/flask-app/application/templates/sparql/exports/lookups_base.sparql b/flask-app/application/templates/sparql/exports/lookups_base.sparql index afe38f6..998356a 100644 --- a/flask-app/application/templates/sparql/exports/lookups_base.sparql +++ b/flask-app/application/templates/sparql/exports/lookups_base.sparql @@ -1,4 +1,4 @@ -## Base export query v1.0 +## Base export query v1.1 {% include 'sparql/_namespaces.sparql' %} @@ -36,6 +36,14 @@ WHERE { ?ndx meshv:broaderDescriptor ?d . ?ndx meshv:identifier ?nd } + OPTIONAL { + ?d meshv:broaderQualifier ?bdx . + ?bdx meshv:identifier ?bd + } + OPTIONAL { + ?ndx meshv:broaderQualifier ?d . + ?ndx meshv:identifier ?nd + } OPTIONAL { ?d meshv:seeAlso ?rdx . ?rdx meshv:identifier ?rd @@ -52,3 +60,4 @@ WHERE { } GROUP BY ?dui ?cui ?dtype ?den ?trx ?notrx ?active ?crt ?est ?nlm ?cas ?rn ###LIMIT 100 +