mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Support both label and itemLabel for robust NearbyResultItem mapping.
This commit is contained in:
parent
b2816e1459
commit
6c147019df
2 changed files with 23 additions and 41 deletions
|
|
@ -6,8 +6,9 @@ class NearbyResultItem(
|
||||||
private val item: ResultTuple?,
|
private val item: ResultTuple?,
|
||||||
private val wikipediaArticle: ResultTuple?,
|
private val wikipediaArticle: ResultTuple?,
|
||||||
private val commonsArticle: ResultTuple?,
|
private val commonsArticle: ResultTuple?,
|
||||||
private val location: ResultTuple?,
|
private val location: ResultTuple?, @field:SerializedName("label")
|
||||||
private val label: ResultTuple?,
|
private val label: ResultTuple?,
|
||||||
|
@field:SerializedName("itemLabel") private val itemLabel: ResultTuple?,
|
||||||
@field:SerializedName("streetAddress") private val address: ResultTuple?,
|
@field:SerializedName("streetAddress") private val address: ResultTuple?,
|
||||||
private val icon: ResultTuple?,
|
private val icon: ResultTuple?,
|
||||||
@field:SerializedName("class") private val className: ResultTuple?,
|
@field:SerializedName("class") private val className: ResultTuple?,
|
||||||
|
|
@ -29,7 +30,7 @@ class NearbyResultItem(
|
||||||
|
|
||||||
fun getLocation(): ResultTuple = location ?: ResultTuple()
|
fun getLocation(): ResultTuple = location ?: ResultTuple()
|
||||||
|
|
||||||
fun getLabel(): ResultTuple = label ?: ResultTuple()
|
fun getLabel(): ResultTuple = label ?: itemLabel ?: ResultTuple()
|
||||||
|
|
||||||
fun getIcon(): ResultTuple = icon ?: ResultTuple()
|
fun getIcon(): ResultTuple = icon ?: ResultTuple()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,32 @@
|
||||||
SELECT
|
SELECT
|
||||||
?item
|
?item
|
||||||
(SAMPLE(?label) AS ?label)
|
?itemLabel
|
||||||
(SAMPLE(?class) AS ?class)
|
?itemDescription
|
||||||
(SAMPLE(?description) AS ?description)
|
?class
|
||||||
(SAMPLE(?classLabel) AS ?classLabel)
|
?classLabel
|
||||||
(SAMPLE(?pic) AS ?pic)
|
?pic
|
||||||
(SAMPLE(?destroyed) AS ?destroyed)
|
?destroyed
|
||||||
(SAMPLE(?endTime) AS ?endTime)
|
?endTime
|
||||||
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
|
?wikipediaArticle
|
||||||
(SAMPLE(?commonsArticle) AS ?commonsArticle)
|
?commonsArticle
|
||||||
(SAMPLE(?commonsCategory) AS ?commonsCategory)
|
?commonsCategory
|
||||||
(SAMPLE(?dateOfOfficialClosure) AS ?dateOfOfficialClosure)
|
?dateOfOfficialClosure
|
||||||
(SAMPLE(?pointInTime) AS ?pointInTime)
|
?pointInTime
|
||||||
WHERE {
|
WHERE {
|
||||||
SERVICE <https://query.wikidata.org/sparql> {
|
SERVICE <https://query.wikidata.org/sparql> {
|
||||||
values ?item {
|
VALUES ?item {${ENTITY}}
|
||||||
${ENTITY}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the label in the preferred language of the user, or any other language if no label is available in that language.
|
# Get item label/class label/description in the preferred language of the user, or fallback.
|
||||||
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
|
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". }
|
||||||
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
|
|
||||||
BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label)
|
|
||||||
|
|
||||||
# Get the description in the preferred language of the user, or any other language if no description is available in that language.
|
# Get class (such as forest or bridge)
|
||||||
OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")}
|
OPTIONAL {?item p:P31/ps:P31 ?class}
|
||||||
OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage}
|
|
||||||
BIND(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?") as ?description)
|
|
||||||
|
|
||||||
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
|
# Get picture (items without a picture will be shown in red on the Nearby map)
|
||||||
OPTIONAL {
|
|
||||||
?item p:P31/ps:P31 ?class.
|
|
||||||
OPTIONAL {?class rdfs:label ?classLabelPreferredLanguage. FILTER (lang(?classLabelPreferredLanguage) = "${LANG}")}
|
|
||||||
OPTIONAL {?class rdfs:label ?classLabelAnyLanguage}
|
|
||||||
BIND(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?") as ?classLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
OPTIONAL {
|
|
||||||
?item p:P31/ps:P31 ?class.
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get picture
|
|
||||||
OPTIONAL {?item wdt:P18 ?pic}
|
OPTIONAL {?item wdt:P18 ?pic}
|
||||||
|
|
||||||
# Get existence
|
# Get existence (whether an item still exists or not)
|
||||||
OPTIONAL {?item wdt:P576 ?destroyed}
|
OPTIONAL {?item wdt:P576 ?destroyed}
|
||||||
OPTIONAL {?item wdt:P582 ?endTime}
|
OPTIONAL {?item wdt:P582 ?endTime}
|
||||||
OPTIONAL {?item wdt:P3999 ?dateOfOfficialClosure}
|
OPTIONAL {?item wdt:P3999 ?dateOfOfficialClosure}
|
||||||
|
|
@ -65,4 +47,3 @@ WHERE {
|
||||||
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
|
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GROUP BY ?item
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue