Skip to content

Commit

Permalink
Merge pull request #67 from filak/dev-1.6.7
Browse files Browse the repository at this point in the history
Support for broaderQualifier
  • Loading branch information
filak authored Oct 31, 2024
2 parents f440738 + adf5a65 commit 75c7963
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
15 changes: 12 additions & 3 deletions flask-app/application/modules/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions flask-app/application/modules/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -92,15 +92,15 @@ 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):
return cache.get(key)

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)
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions flask-app/application/templates/sparql/descriptor_view.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% include 'sparql/_namespaces.sparql' %}
{% endif %}

## Descriptor view query v1.0
## Descriptor view query v1.1

SELECT DISTINCT * {
{SELECT ?p ?o
Expand Down Expand Up @@ -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 {
Expand All @@ -89,3 +89,4 @@ WHERE {
}}

} ORDER BY ?p ?o

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% include 'sparql/_namespaces.sparql' %}
PREFIX a: <http://aaa>

## Descriptor trx view query v1.0
## Descriptor trx view query v1.1

SELECT DISTINCT * {
{SELECT ?p ?o
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Base export query v1.0
## Base export query v1.1

{% include 'sparql/_namespaces.sparql' %}

Expand Down Expand Up @@ -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
Expand All @@ -52,3 +60,4 @@ WHERE {
}
GROUP BY ?dui ?cui ?dtype ?den ?trx ?notrx ?active ?crt ?est ?nlm ?cas ?rn
###LIMIT 100

0 comments on commit 75c7963

Please sign in to comment.