I am trying to get the properties that the linked pages from a wikipedia page have.

SELECT ?item ?wikipediaTitle ?target WHERE {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "en.wikipedia.org".
    bd:serviceParam wikibase:api "Generator".
    bd:serviceParam mwapi:generator "links".
    bd:serviceParam mwapi:titles "Arduino".
    bd:serviceParam mwapi:prop "pageprops".

    ?wikipediaTitle wikibase:apiOutput mwapi:title.

    ?item wikibase:apiOutputItem mwapi:item .
  ?item wdt:P31 ?target.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }


However, this query always timeout, even with the LIMIT 1. The problem line is the ?item wdt:P31 ?target. Any way to fix this?

Also, assuming that it is working. It will generate one line for each P31 found. Is there any way to make all properties fit one single line? Maybe concatenating them and separating with ", "?

  • 1
    1. Add FILTER(bound(?item)) before ?item wdt:P31 ?target. 2. GROUP_CONCAT + something to extract strings you want to concatenate. – Stanislav Kralin Apr 30 '19 at 8:34
  • 1
    Like this: w.wiki/3Vh – Stanislav Kralin Apr 30 '19 at 12:12
  • Thank you very much, you are being very helpful! But, why the filter is needed? – Henrique Bruno Apr 30 '19 at 19:09
  • 1
    Some bindings for ?item returned by SERVICE are "undefined" (like UNDEF in VALUES). Then ?item wdt:P31 ?target behaves like [] wdt:P31 ?target, i. e. matches all truthy P31 triples (more than 50 millions). – Stanislav Kralin Apr 30 '19 at 20:37
  • 1
    OK. BTW, yoy can post answers to your questions yourself and accept them. – Stanislav Kralin May 1 '19 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.