8

(When) will the following be possible:

  • For a wikipedia page: get the list of all wikipedia links on that page with their respective wikidata IDs in a single query/API call.

  • Receive additional information of the respective wikidata items like a property value with the query.

user_0
  • 324
  • 1
  • 10

1 Answers1

3

(When) will the following be possible:

Search in their Phabricator.

For a wikipedia page: get the list of all wikipedia links on that page with their respective wikidata IDs in a single query/API call.

To some extent, it is possible right now. There are two ways.

1

PREFIX mw: <http://tools.wmflabs.org/mw2sparql/ontology#>

SELECT ?link_to ?wikidata_item WHERE {
  hint:Query hint:optimizer "None"
  VALUES (?link_from) {(<https://en.wikipedia.org/wiki/SPARQL>)}
  SERVICE <http://tools.wmflabs.org/mw2sparql/sparql> {
    ?link_from mw:internalLinkTo ?link_to .
  }
  ?link_to schema:about ?wikidata_item .
}

Try it!

See also:

2

SELECT DISTINCT ?link_to ?wikidata_item ?page_title WHERE {
  VALUES (?link_from) {(<https://en.wikipedia.org/wiki/SPARQL>)} 
  ?link_from schema:name ?title .
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:endpoint "en.wikipedia.org" ;
                      wikibase:api "Generator" ;
                      mwapi:generator "links" ;
                      mwapi:titles ?title ;
                      mwapi:inprop "url" ;
                      mwapi:redirects "true" .
    ?link_to wikibase:apiOutputURI "@fullurl" .
    ?wikidata_item wikibase:apiOutputItem mwapi:item .
    ?page_title wikibase:apiOutput mwapi:title .
  }
}

Try it!

See also:

Receive additional information of the respective wikidata items like a property value with the query.

Add regular SPARQL to the above queries, e. g.

FILTER (bound(?wikidata_item))
OPTIONAL {?wikidata_item wdt:P1482 ?stackexchange_tag}
Stanislav Kralin
  • 2,975
  • 1
  • 12
  • 33