mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
parent
34ab6f581b
commit
0e5ba98c2e
82 changed files with 474 additions and 1480 deletions
|
|
@ -6,7 +6,6 @@ import com.google.gson.Gson;
|
|||
import fr.free.nrw.commons.achievements.FeaturedImages;
|
||||
import fr.free.nrw.commons.achievements.FeedbackResponse;
|
||||
import fr.free.nrw.commons.campaigns.CampaignResponseDTO;
|
||||
import fr.free.nrw.commons.depictions.subClass.models.SparqlResponse;
|
||||
import fr.free.nrw.commons.explore.depictions.DepictsClient;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
|
@ -210,16 +209,19 @@ public class OkHttpJsonApiClient {
|
|||
* Get the QIDs of all Wikidata items that are subclasses of the given Wikidata item. Example:
|
||||
* bridge -> suspended bridge, aqueduct, etc
|
||||
*/
|
||||
public Observable<List<DepictedItem>> getChildQIDs(String qid) throws IOException {
|
||||
return depictedItemsFrom(sparqlQuery(qid, "/queries/subclasses_query.rq"));
|
||||
public Observable<List<DepictedItem>> getChildDepictions(String qid, int startPosition,
|
||||
int limit) throws IOException {
|
||||
return depictedItemsFrom(sparqlQuery(qid, startPosition, limit,"/queries/subclasses_query.rq"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the QIDs of all Wikidata items that are subclasses of the given Wikidata item. Example:
|
||||
* bridge -> suspended bridge, aqueduct, etc
|
||||
*/
|
||||
public Observable<List<DepictedItem>> getParentQIDs(String qid) throws IOException {
|
||||
return depictedItemsFrom(sparqlQuery(qid, "/queries/parentclasses_query.rq"));
|
||||
public Observable<List<DepictedItem>> getParentDepictions(String qid, int startPosition,
|
||||
int limit) throws IOException {
|
||||
return depictedItemsFrom(sparqlQuery(qid, startPosition, limit,
|
||||
"/queries/parentclasses_query.rq"));
|
||||
}
|
||||
|
||||
private Observable<List<DepictedItem>> depictedItemsFrom(Request request) {
|
||||
|
|
@ -231,10 +233,12 @@ public class OkHttpJsonApiClient {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
private Request sparqlQuery(String qid, String fileName) throws IOException {
|
||||
String query = FileUtils.readFromResource(fileName).
|
||||
replace("${QID}", qid)
|
||||
.replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"");
|
||||
private Request sparqlQuery(String qid, int startPosition, int limit, String fileName) throws IOException {
|
||||
String query = FileUtils.readFromResource(fileName)
|
||||
.replace("${QID}", qid)
|
||||
.replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"")
|
||||
.replace("${LIMIT}",""+ limit)
|
||||
.replace("${OFFSET}",""+ startPosition);
|
||||
HttpUrl.Builder urlBuilder = HttpUrl
|
||||
.parse(sparqlQueryUrl)
|
||||
.newBuilder()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package fr.free.nrw.commons.mwapi
|
||||
|
||||
data class SparqlResponse(val results: Result)
|
||||
|
||||
data class Result(val bindings: List<Binding>)
|
||||
|
||||
data class Binding(
|
||||
val item: SparqInfo
|
||||
) {
|
||||
val id: String
|
||||
get() = item.value.substringAfterLast("/")
|
||||
}
|
||||
|
||||
data class SparqInfo(val type: String, val value: String)
|
||||
Loading…
Add table
Add a link
Reference in a new issue