2

I was working on the Issue https://github.com/commons-app/apps-android-commons/issues/3114 to add all wikidata items that are sublasses or instances of the given wikidata item(depictions)

I was using this API https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&type=item&language=en&uselang=en&search=rabbit&limit=25 to fetch all the depicted items. Now how can I get subclasses of each of these depicted items.

Can anyone please help.

Thanks in advance!

  • if you can use SPARQL it's simple: `SELECT * WHERE { SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "EntitySearch" . bd:serviceParam wikibase:endpoint "www.wikidata.org" . bd:serviceParam mwapi:search "rabbit" . bd:serviceParam mwapi:language "en" . ?item wikibase:apiOutputItem mwapi:item . ?num wikibase:apiOrdinal true . } ?entity (wdt:P279|wdt:P31) ?item } ORDER BY ASC(?num) LIMIT 25` – UninformedUser Aug 11 '19 at 13:31
  • get all entities that are either (direct) subclass (`wdt:P279`) or instance of (`wdt:P31`) of the items found by the entity search service. – UninformedUser Aug 11 '19 at 13:32
  • I guess without SPARQL it's not possible because you can only get outgoing properties of the entities – UninformedUser Aug 11 '19 at 13:36
  • more details you might need (part1): `SELECT ?item ?itemLabel ?itemDescription ?img ?instancesOrSubclasses ?instancesOrSubclassesLabel ?typesOrSuperclasses ?typesOrSuperclassesLabel WHERE { SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "EntitySearch" . bd:serviceParam wikibase:endpoint "www.wikidata.org" . bd:serviceParam mwapi:search "rabbit" . bd:serviceParam mwapi:language "en" . ?item wikibase:apiOutputItem mwapi:item . ?num wikibase:apiOrdinal true . }` – UninformedUser Aug 11 '19 at 13:45
  • part2: `?instancesOrSubclasses (wdt:P279|wdt:P31) ?item. ?item (wdt:P279|wdt:P31) ?typesOrSuperclasses OPTIONAL {?item wdt:P18 ?img} SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY ASC(?num) LIMIT 50` – UninformedUser Aug 11 '19 at 13:45
  • @AKSW thanks for your comment. But, I cannot use SPARQL i was working with the Wikimedia Commons Android App. I need some API that can give me the desired result. Can you please help? – Vanshika Arora Aug 12 '19 at 06:10
  • not sure what you want to hear now, it's not possible. And honestly, I don't understand why it would not be possible to send a request to the SPARQL endpoint ... it nothing more like you're doing with sending a request to any other service. – UninformedUser Aug 12 '19 at 07:51
  • @VanshikaArora Checkout the manual for the SPARQL endpoint: https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual#SPARQL_endpoint SPARQL is not all about the GUI at query.wikidata.org. – Ainali Oct 22 '19 at 13:02

0 Answers0