From 75257632ba7bf47fc582b013b7ccb4af1bb27204 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 25 Nov 2019 13:46:25 +0000 Subject: [PATCH] Show more than just paintings during browse --- app.py | 18 +++++++++++++++++- templates/query/facet.sparql | 4 ++-- templates/query/find_more.sparql | 5 +++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 40acf9e..9a23811 100755 --- a/app.py +++ b/app.py @@ -47,6 +47,8 @@ find_more_props = { 'P2348': 'time period', 'P361': 'part of', 'P608': 'exhibition history', + 'P180': 'depicts', + 'P31': 'instance of', # possible future props # 'P571': 'inception', @@ -55,6 +57,17 @@ find_more_props = { # 'P123': 'publisher', (only 1) } +isa_list = [ + 'Q60520', # sketchbook + 'Q93184', # drawing + 'Q3305213', # painting + 'Q15123870', # lithograph + 'Q18761202', # watercolor painting + 'Q79218', # triptych + 'Q2647254', # study + 'Q46686' # reredos +] + @app.teardown_appcontext def shutdown_session(exception=None): database.session.remove() @@ -550,6 +563,7 @@ def get_facets(params): q = render_template('query/facet.sparql', params=params, + isa_list=isa_list, properties=properties) bindings = wdqs.run_query_with_cache(q, flat + '_facets') @@ -575,7 +589,9 @@ def get_artwork_params(): def filter_artwork(params): flat = '_'.join(f'{pid}={qid}' for pid, qid in params) - q = render_template('query/find_more.sparql', params=params) + q = render_template('query/find_more.sparql', + params=params, + isa_list=isa_list) bindings = wdqs.run_query_with_cache(q, flat) return bindings diff --git a/templates/query/facet.sparql b/templates/query/facet.sparql index a558f5e..3699fd6 100644 --- a/templates/query/facet.sparql +++ b/templates/query/facet.sparql @@ -1,11 +1,11 @@ select ?property ?object ?objectLabel (count(*) as ?count) { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } - ?item wdt:P31 wd:Q3305213 . + VALUES ?isa { {% for isa in isa_list %} wd:{{ isa }} {% endfor %} } + ?item wdt:P31 ?isa . ?item wdt:P18 ?image . {% for pid, qid in params %} ?item wdt:{{pid}} wd:{{qid}} . {% endfor %} values ?property { {% for pid in properties %} wdt:{{pid}}{% endfor %} } ?item ?property ?object . - FILTER NOT EXISTS { ?item wdt:P180 ?depicts } } group by ?property ?propertyLabel ?object ?objectLabel diff --git a/templates/query/find_more.sparql b/templates/query/find_more.sparql index 4412327..4bc2baa 100644 --- a/templates/query/find_more.sparql +++ b/templates/query/find_more.sparql @@ -1,6 +1,8 @@ select ?item ?itemLabel ?image ?artist ?artistLabel ?title ?titleLang ?time ?timeprecision { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } - ?item wdt:P31 wd:Q3305213 . + VALUES ?isa { {% for isa in isa_list %} wd:{{ isa }} {% endfor %} } + + ?item wdt:P31 ?isa . {% for pid, qid in params %} ?item wdt:{{pid}} wd:{{qid}} . {% endfor %} @@ -15,5 +17,4 @@ select ?item ?itemLabel ?image ?artist ?artistLabel ?title ?titleLang ?time ?tim BIND(LANG(?title) as ?titleLang) } OPTIONAL { ?item wdt:P170 ?artist } - FILTER NOT EXISTS { ?item wdt:P180 ?depicts } }