Skip to content

Commit 74ec73e

Browse files
Fixes commons-app#4595 - Updated nearby query (commons-app#4622)
* Fixes commons-app#4595 - Updated nearby query * Removed logic to replace local language in nearby query - that might acccidentally replace other strings * Fetch property location in usual nearby query
1 parent 174b476 commit 74ec73e

File tree

3 files changed

+113
-187
lines changed

3 files changed

+113
-187
lines changed

app/src/main/resources/queries/monuments_query.rq

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,56 @@
11
SELECT
2-
(SAMPLE(?location) as ?location)
3-
?item
4-
(SAMPLE(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage)) as ?label)
5-
(SAMPLE(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?")) as ?description)
6-
(SAMPLE(?classId) as ?class)
7-
(SAMPLE(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?")) as ?classLabel)
8-
(SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
9-
?wikipediaArticle
10-
?commonsArticle
11-
(SAMPLE(?commonsCategory) as ?commonsCategory)
12-
(SAMPLE(?pic) as ?pic)
13-
(SAMPLE(?destroyed) as ?destroyed)
14-
(SAMPLE(?endTime) as ?endTime)
15-
WHERE {
16-
# Around given location...
17-
SERVICE wikibase:around {
18-
?item wdt:P625 ?location.
19-
bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral.
20-
bd:serviceParam wikibase:radius "${RAD}" . # Radius in kilometers.
21-
}
22-
23-
# Get the label in the preferred language of the user, or any other language if no label is available in that language.
24-
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
25-
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
26-
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-
31-
# Get Commons category (P373)
32-
OPTIONAL { ?item wdt:P373 ?commonsCategory. }
33-
34-
# Get (P18)
35-
OPTIONAL { ?item wdt:P18 ?pic. }
36-
37-
# Get (P576)
38-
OPTIONAL { ?item wdt:P576 ?destroyed. }
39-
40-
# Get (P582)
41-
OPTIONAL { ?item wdt:P582 ?endTime. }
42-
43-
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
44-
OPTIONAL {
45-
?item p:P31/ps:P31 ?classId.
46-
OPTIONAL {?classId rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")}
47-
OPTIONAL {?classId rdfs:label ?classLabelAnyLanguage}
48-
49-
OPTIONAL {
50-
?wikipediaArticle schema:about ?item ;
51-
schema:isPartOf <https://${LANG}.wikipedia.org/> .
52-
}
53-
OPTIONAL {
54-
?wikipediaArticle schema:about ?item ;
55-
schema:isPartOf <https://en.wikipedia.org/> .
56-
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
57-
}
58-
59-
OPTIONAL {
60-
?commonsArticle schema:about ?item ;
61-
schema:isPartOf <https://commons.wikimedia.org/> .
62-
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
63-
}
64-
}
65-
}
66-
GROUP BY ?item ?wikipediaArticle ?commonsArticle
2+
?item
3+
(SAMPLE(?location) as ?location)
4+
(SAMPLE(?label) AS ?label)
5+
(SAMPLE(?description) AS ?description)
6+
(SAMPLE(?class) AS ?class)
7+
(SAMPLE(?classLabel) AS ?classLabel)
8+
(SAMPLE(?pic) AS ?pic)
9+
(SAMPLE(?destroyed) AS ?destroyed)
10+
(SAMPLE(?endTime) AS ?endTime)
11+
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
12+
(SAMPLE(?commonsArticle) AS ?commonsArticle)
13+
(SAMPLE(?commonsCategory) AS ?commonsCategory)
14+
WHERE {
15+
# Around given location
16+
SERVICE wikibase:around {
17+
?item wdt:P625 ?location.
18+
bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral. # Longitude latitude
19+
bd:serviceParam wikibase:radius "${RAD}". # Radius in kilometers.
20+
}
21+
22+
OPTIONAL {
23+
?item p:P31/ps:P31 ?class.
24+
}
25+
26+
# Get picture
27+
OPTIONAL {?item wdt:P18 ?pic}
28+
29+
# Get existence
30+
OPTIONAL {?item wdt:P576 ?destroyed}
31+
OPTIONAL {?item wdt:P582 ?endTime}
32+
33+
# Get Commons category
34+
OPTIONAL {?item wdt:P373 ?commonsCategory}
35+
36+
# Get Wikipedia article
37+
OPTIONAL {
38+
?wikipediaArticle schema:about ?item.
39+
?wikipediaArticle schema:isPartOf <https://${LANG}.wikipedia.org/>.
40+
}
41+
42+
# Get Commons article
43+
OPTIONAL {
44+
?commonsArticle schema:about ?item.
45+
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
46+
}
47+
48+
# Labels and descriptions
49+
SERVICE wikibase:label {
50+
bd:serviceParam wikibase:language "${LANG},en,fr,de,es,ja,ru,it,zh,pt,ar,fa,pl,nl,id,uk,he,sv,cs,ko,vi,ca,no,fi,hu,tr,th,hi,bn,ceb,ro,sw,kk,da,eo,sr,lt,sk,bg,sl,eu,et,hr,ms,el,arz,ur,ta,te,nn,gl,az,af,bs,be,ml,ka,is,sq,uz,la,br,mk,lv,azb,mr,sh,tl,cy,ckb,ast,be-tarask,zh-yue,hy,pa,as,my,kn,ne,si,tt,ha,war,zh-min-nan,vo,min,lmo,ht,lb,gu,tg,sco,ku,new,bpy,nds,io,pms,su,oc,jv,nap,ba,scn,wa,bar,an,ksh,szl,fy,frr,als,ia,ga,yi,mg,gd,vec,ce,sa,mai,xmf,sd,wuu,mrj,mhr,km,roa-tara,am,roa-rup,map-bms,bh,mnw,shn,bcl,co,cv,dv,nds-nl,fo,hif,fur,gan,glk,hak,ilo,pam,csb,avk,lij,li,gv,mi,mt,nah,nrm,se,nov,qu,os,pi,pag,ps,pdc,rm,bat-smg,sc,to,tk,hsb,fiu-vro,vls,yo,diq,zh-classical,frp,lad,kw,mn,haw,ang,ln,ie,wo,tpi,ty,crh,nv,jbo,ay,pcd,zea,eml,ky,ig,or,cbk-zam,kg,arc,rmy,ab,gn,so,kab,ug,stq,udm,ext,mzn,pap,cu,sah,tet,sn,lo,pnb,iu,na,got,bo,dsb,chr,cdo,om,sm,ee,ti,av,bm,zu,pnt,cr,pih,ss,ve,bi,rw,ch,xh,kl,ik,bug,dz,ts,tn,kv,tum,xal,st,tw,bxr,ak,ny,fj,lbe,za,ks,ff,lg,sg,rn,chy,mwl,lez,bjn,gom,tyv,vep,nso,kbd,ltg,rue,pfl,gag,koi,krc,ace,olo,kaa,mdf,myv,srn,ady,jam,tcy,dty,atj,kbp,din,lfn,gor,inh,sat,hyw,nqo,ban,szy,awa,ary,lld,smn,skr,mad,dag,shi,nia,ki,gcr".
51+
?item rdfs:label ?label.
52+
?item schema:description ?description.
53+
?class rdfs:label ?classLabel.
54+
}
55+
}
56+
GROUP BY ?item
Lines changed: 58 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,67 @@
11
SELECT
2-
(SAMPLE(?location) as ?location)
3-
?item
4-
(SAMPLE(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage)) as ?label)
5-
(SAMPLE(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?")) as ?description)
6-
(SAMPLE(?classId) as ?class)
7-
(SAMPLE(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?")) as ?classLabel)
8-
(SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
9-
?wikipediaArticle
10-
?commonsArticle
11-
(SAMPLE(?commonsCategory) as ?commonsCategory)
12-
(SAMPLE(?pic) as ?pic)
13-
(SAMPLE(?destroyed) as ?destroyed)
14-
(SAMPLE(?endTime) as ?endTime)
15-
(SAMPLE(?monument) as ?monument)
16-
WHERE {
17-
# Around given location...
18-
SERVICE wikibase:around {
19-
?item wdt:P625 ?location.
20-
bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral.
21-
bd:serviceParam wikibase:radius "${RAD}" . # Radius in kilometers.
22-
}
2+
?item
3+
(SAMPLE(?location) as ?location)
4+
(SAMPLE(?label) AS ?label)
5+
(SAMPLE(?description) AS ?description)
6+
(SAMPLE(?class) AS ?class)
7+
(SAMPLE(?classLabel) AS ?classLabel)
8+
(SAMPLE(?pic) AS ?pic)
9+
(SAMPLE(?destroyed) AS ?destroyed)
10+
(SAMPLE(?endTime) AS ?endTime)
11+
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
12+
(SAMPLE(?commonsArticle) AS ?commonsArticle)
13+
(SAMPLE(?commonsCategory) AS ?commonsCategory)
14+
(SAMPLE(?monument) AS ?monument)
15+
WHERE {
16+
# Around given location
17+
SERVICE wikibase:around {
18+
?item wdt:P625 ?location.
19+
bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral. # Longitude latitude
20+
bd:serviceParam wikibase:radius "${RAD}". # Radius in kilometers.
21+
}
2322

24-
OPTIONAL {
25-
{ ?item p:P1435 ?monument } UNION { ?item p:P2186 ?monument } UNION { ?item p:P1459 ?monument } UNION { ?item p:P1460 ?monument } UNION { ?item p:P1216 ?monument } UNION { ?item p:P709 ?monument } UNION { ?item p:P718 ?monument } UNION { ?item p:P5694 ?monument }
26-
}
23+
OPTIONAL {
24+
?item p:P31/ps:P31 ?class.
25+
}
2726

28-
# Get the label in the preferred language of the user, or any other language if no label is available in that language.
29-
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
30-
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
27+
# Get picture
28+
OPTIONAL {?item wdt:P18 ?pic}
3129

32-
# Get the description in the preferred language of the user, or any other language if no description is available in that language.
33-
OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")}
34-
OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage }
30+
# Get existence
31+
OPTIONAL {?item wdt:P576 ?destroyed}
32+
OPTIONAL {?item wdt:P582 ?endTime}
3533

36-
# Get Commons category (P373)
37-
OPTIONAL { ?item wdt:P373 ?commonsCategory. }
34+
# Get Commons category
35+
OPTIONAL {?item wdt:P373 ?commonsCategory}
3836

39-
# Get (P18)
40-
OPTIONAL { ?item wdt:P18 ?pic. }
37+
# Get Wikipedia article
38+
OPTIONAL {
39+
?wikipediaArticle schema:about ?item.
40+
?wikipediaArticle schema:isPartOf <https://${LANG}.wikipedia.org/>.
41+
}
4142

42-
# Get (P576)
43-
OPTIONAL { ?item wdt:P576 ?destroyed. }
43+
# Get Commons article
44+
OPTIONAL {
45+
?commonsArticle schema:about ?item.
46+
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
47+
}
4448

45-
# Get (P582)
46-
OPTIONAL { ?item wdt:P582 ?endTime. }
49+
# Wiki Loves Monuments
50+
OPTIONAL {?item p:P1435 ?monument}
51+
OPTIONAL {?item p:P2186 ?monument}
52+
OPTIONAL {?item p:P1459 ?monument}
53+
OPTIONAL {?item p:P1460 ?monument}
54+
OPTIONAL {?item p:P1216 ?monument}
55+
OPTIONAL {?item p:P709 ?monument}
56+
OPTIONAL {?item p:P718 ?monument}
57+
OPTIONAL {?item p:P5694 ?monument}
4758

48-
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
49-
OPTIONAL {
50-
?item p:P31/ps:P31 ?classId.
51-
OPTIONAL {?classId rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")}
52-
OPTIONAL {?classId rdfs:label ?classLabelAnyLanguage}
53-
54-
OPTIONAL {
55-
?wikipediaArticle schema:about ?item ;
56-
schema:isPartOf <https://${LANG}.wikipedia.org/> .
57-
}
58-
OPTIONAL {
59-
?wikipediaArticle schema:about ?item ;
60-
schema:isPartOf <https://en.wikipedia.org/> .
61-
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
62-
}
63-
64-
OPTIONAL {
65-
?commonsArticle schema:about ?item ;
66-
schema:isPartOf <https://commons.wikimedia.org/> .
67-
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
68-
}
69-
}
70-
}
71-
GROUP BY ?item ?wikipediaArticle ?commonsArticle
59+
# Labels and descriptions
60+
SERVICE wikibase:label {
61+
bd:serviceParam wikibase:language "${LANG},en,fr,de,es,ja,ru,it,zh,pt,ar,fa,pl,nl,id,uk,he,sv,cs,ko,vi,ca,no,fi,hu,tr,th,hi,bn,ceb,ro,sw,kk,da,eo,sr,lt,sk,bg,sl,eu,et,hr,ms,el,arz,ur,ta,te,nn,gl,az,af,bs,be,ml,ka,is,sq,uz,la,br,mk,lv,azb,mr,sh,tl,cy,ckb,ast,be-tarask,zh-yue,hy,pa,as,my,kn,ne,si,tt,ha,war,zh-min-nan,vo,min,lmo,ht,lb,gu,tg,sco,ku,new,bpy,nds,io,pms,su,oc,jv,nap,ba,scn,wa,bar,an,ksh,szl,fy,frr,als,ia,ga,yi,mg,gd,vec,ce,sa,mai,xmf,sd,wuu,mrj,mhr,km,roa-tara,am,roa-rup,map-bms,bh,mnw,shn,bcl,co,cv,dv,nds-nl,fo,hif,fur,gan,glk,hak,ilo,pam,csb,avk,lij,li,gv,mi,mt,nah,nrm,se,nov,qu,os,pi,pag,ps,pdc,rm,bat-smg,sc,to,tk,hsb,fiu-vro,vls,yo,diq,zh-classical,frp,lad,kw,mn,haw,ang,ln,ie,wo,tpi,ty,crh,nv,jbo,ay,pcd,zea,eml,ky,ig,or,cbk-zam,kg,arc,rmy,ab,gn,so,kab,ug,stq,udm,ext,mzn,pap,cu,sah,tet,sn,lo,pnb,iu,na,got,bo,dsb,chr,cdo,om,sm,ee,ti,av,bm,zu,pnt,cr,pih,ss,ve,bi,rw,ch,xh,kl,ik,bug,dz,ts,tn,kv,tum,xal,st,tw,bxr,ak,ny,fj,lbe,za,ks,ff,lg,sg,rn,chy,mwl,lez,bjn,gom,tyv,vep,nso,kbd,ltg,rue,pfl,gag,koi,krc,ace,olo,kaa,mdf,myv,srn,ady,jam,tcy,dty,atj,kbp,din,lfn,gor,inh,sat,hyw,nqo,ban,szy,awa,ary,lld,smn,skr,mad,dag,shi,nia,ki,gcr".
62+
?item rdfs:label ?label.
63+
?item schema:description ?description.
64+
?class rdfs:label ?classLabel.
65+
}
66+
}
67+
GROUP BY ?item

0 commit comments

Comments
 (0)