I want to get Wikipedia page ID from Wikidata ID from Wikidata Query Service in a single SPARQL query.
First SPARQL query to get Wikidata ID (wd:Q3131
) from title page: "Alpes-de-Haute-Provence"
SELECT ?item ?itemLabel ?itemDescription WHERE {
?url rdf:type schema:Article;
schema:about ?item; schema:name ?name ;
schema:isPartOf <https://fr.wikipedia.org/>;
schema:name "Alpes-de-Haute-Provence"@fr.
SERVICE wikibase:label {
bd:serviceParam
wikibase:language "fr,[AUTO_LANGUAGE],en"
}
}
Second SPARQL query to get Wikipedia page ID from Wikidata ID
SELECT ?pageid WHERE {
VALUES (?item) {(wd:Q3131)}
[ schema:about ?item ; schema:name ?name ;
schema:isPartOf <https://fr.wikipedia.org/> ]
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "fr.wikipedia.org" .
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam mwapi:generator "allpages" .
bd:serviceParam mwapi:gapfrom ?name .
bd:serviceParam mwapi:gapto ?name .
?pageid wikibase:apiOutput "@pageid" .
}
}
Is possible to do it in a single SPARQL query?
Solution proposed by @UninformedUser
SELECT ?item ?itemLabel ?itemDescription ?pageid WHERE {
?url rdf:type schema:Article;
schema:about ?item;
schema:name ?name ;
schema:isPartOf <https://fr.wikipedia.org/>;
schema:name "Alpes-de-Haute-Provence"@fr.
SERVICE wikibase:label {
bd:serviceParam
wikibase:language "fr,[AUTO_LANGUAGE],en"
}
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "fr.wikipedia.org" .
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam mwapi:generator "allpages" .
bd:serviceParam mwapi:gapfrom ?name .
bd:serviceParam mwapi:gapto ?name .
?pageid wikibase:apiOutput "@pageid" .
}
}