Skip to content

Commit 532bd8b

Browse files
Revert "Optimise SPARQL query for single entity metadata using wikibase:label (#6376)"
This reverts commit e5dbcfc.
1 parent 90ab7a2 commit 532bd8b

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/model/NearbyResultItem.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class NearbyResultItem(
77
private val wikipediaArticle: ResultTuple?,
88
private val commonsArticle: ResultTuple?,
99
private val location: ResultTuple?,
10-
@field:SerializedName("label")
1110
private val label: ResultTuple?,
1211
@field:SerializedName("streetAddress") private val address: ResultTuple?,
1312
private val icon: ResultTuple?,
@@ -16,7 +15,7 @@ class NearbyResultItem(
1615
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
1716
@field:SerializedName("pic") private val pic: ResultTuple?,
1817
@field:SerializedName("destroyed") private val destroyed: ResultTuple?,
19-
@field:SerializedName("itemDescription") private val description: ResultTuple?,
18+
@field:SerializedName("description") private val description: ResultTuple?,
2019
@field:SerializedName("endTime") private val endTime: ResultTuple?,
2120
@field:SerializedName("monument") private val monument: ResultTuple?,
2221
@field:SerializedName("dateOfOfficialClosure") private val dateOfOfficialClosure: ResultTuple?,
Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
11
SELECT
22
?item
3-
?itemLabel
4-
?itemDescription
5-
?class
6-
?classLabel
7-
?pic
8-
?destroyed
9-
?endTime
10-
?wikipediaArticle
11-
?commonsArticle
12-
?commonsCategory
13-
?dateOfOfficialClosure
14-
?pointInTime
3+
(SAMPLE(?label) AS ?label)
4+
(SAMPLE(?class) AS ?class)
5+
(SAMPLE(?description) AS ?description)
6+
(SAMPLE(?classLabel) AS ?classLabel)
7+
(SAMPLE(?pic) AS ?pic)
8+
(SAMPLE(?destroyed) AS ?destroyed)
9+
(SAMPLE(?endTime) AS ?endTime)
10+
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
11+
(SAMPLE(?commonsArticle) AS ?commonsArticle)
12+
(SAMPLE(?commonsCategory) AS ?commonsCategory)
13+
(SAMPLE(?dateOfOfficialClosure) AS ?dateOfOfficialClosure)
14+
(SAMPLE(?pointInTime) AS ?pointInTime)
1515
WHERE {
1616
SERVICE <https://query.wikidata.org/sparql> {
17-
VALUES ?item {${ENTITY}}
17+
values ?item {
18+
${ENTITY}
19+
}
1820
}
1921

20-
# Get item label/class label/description in the preferred language of the user, or fallback.
21-
SERVICE wikibase:label { bd:serviceParam wikibase:language "${LANG},en,aa,ab,ae,af,ak,am,an,ar,as,av,ay,az,ba,be,bg,bh,bi,bm,bn,bo,br,bs,ca,ce,ch,co,cr,cs,cu,cv,cy,da,de,dv,dz,ee,el,eo,es,et,eu,fa,ff,fi,fj,fo,fr,fy,ga,gd,gl,gn,gu,gv,ha,he,hi,ho,hr,ht,hu,hy,hz,ia,id,ie,ig,ii,ik,io,is,it,iu,ja,jv,ka,kg,ki,kj,kk,kl,km,kn,ko,kr,ks,ku,kv,kw,ky,la,lb,lg,li,ln,lo,lt,lu,lv,mg,mh,mi,mk,ml,mn,mo,mr,ms,mt,my,na,nb,nd,ne,ng,nl,nn,no,ny,oc,oj,om,or,os,pa,pi,pl,ps,pt,qu,rm,rn,ro,ru,rw,sa,sc,sd,se,sg,sh,si,sk,sl,sm,sn,so,sq,sr,ss,st,su,sv,sw,ta,te,tg,th,ti,tk,tl,tn,to,tr,ts,tt,tw,ty,ug,uk,ur,uz,ve,vi,vo,wa,wo,xh,yi,yo,za,zh,zu". }
22+
# Get the label in the preferred language of the user, or any other language if no label is available in that language.
23+
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
24+
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
25+
BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label)
2226

23-
# Get class (such as forest or bridge)
24-
OPTIONAL {?item p:P31/ps:P31 ?class}
27+
# Get the description in the preferred language of the user, or any other language if no description is available in that language.
28+
OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")}
29+
OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage}
30+
BIND(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?") as ?description)
2531

26-
# Get picture (items without a picture will be shown in red on the Nearby map)
32+
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
33+
OPTIONAL {
34+
?item p:P31/ps:P31 ?class.
35+
OPTIONAL {?class rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")}
36+
OPTIONAL {?class rdfs:label ?classLabelAnyLanguage}
37+
BIND(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?") as ?classLabel)
38+
}
39+
40+
OPTIONAL {
41+
?item p:P31/ps:P31 ?class.
42+
}
43+
44+
# Get picture
2745
OPTIONAL {?item wdt:P18 ?pic}
2846

29-
# Get existence (whether an item still exists or not)
47+
# Get existence
3048
OPTIONAL {?item wdt:P576 ?destroyed}
3149
OPTIONAL {?item wdt:P582 ?endTime}
3250
OPTIONAL {?item wdt:P3999 ?dateOfOfficialClosure}
@@ -47,3 +65,4 @@ WHERE {
4765
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
4866
}
4967
}
68+
GROUP BY ?item

0 commit comments

Comments
 (0)