query-56bfbe6cec18c2f824a283e15bc4d2e8
.?thesis applies to the wdt:P953So that it's clearer that the for how we workaround this difficulty.Wikidata:SPARQL_query_service/WDQS_graph_split/Internal_Federation_Guide#Returning_variables_bound_by_OPTIONAL clause, these variables are annoying with federation, see OPTIONALAnd finally you are returning a variable bound under an which requires triples from the main graph, this is also explained in the section I linked abovewdt:P31/wdt:P279*You were select thesis using a property path )Wikidata:SPARQL_query_service/WDQS_graph_split/Internal_Federation_Guide#What_is_where? matches a triple owned by the publication and thus must also be part of the federated query on the scholarly_article (see ?thesis wdt:P50 ?author.The pattern SELECT or by selecting them in a ?thesisLabel in the same way you bind the BIND(?thesisDescription AS ?thesisDescription)You need the thesis' descriptions which are extracted via the label service, in the federation query you need to instruct this service that you need them with After there was several other things incorrect: Please see below your query rewritten with federation (to run on query-main) and some explanations in the comments:
Use at
- https://query.wikidata.org/sparql
PREFIX wdsubgraph: <https://query.wikidata.org/subgraph/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT
?thesis
?thesisDescription
?thesisLabel
(COALESCE(IF(BOUND(?author), ?author, 'N/A')) AS ?author)
?authorLabel (COALESCE(IF(BOUND(?authorwp), ?authorwp, 'N/A')) AS ?authorwp)
?lse_url
WHERE {
hint:Query hint:optimizer "None" .
# Ideally we want to select thesis with: ?thesis wdt:P31/wdt:P279* wd:Q1266946
# This property path might require navigating triples in the two subgraphs and thus we can't use it
# We extract ?thesisType first so that we will match it with a simple pattern ?thesis wdt:P31 ?thesisType
?thesisType wdt:P279* wd:Q1266946 .
{
SERVICE wdsubgraph:scholarly_articles {
SELECT ?thesis ?thesisLabel ?thesisDescription ?thesisType ?lse_url (COALESCE(IF(BOUND(?author), ?author, 'N/A')) AS ?author) {
?thesis wdt:P31 ?thesisType ;
wdt:P953 ?lse_url.
FILTER(STRSTARTS(STR(?lse_url), "http://etheses.lse.ac.uk"))
# We return a variable bound in an OPTIONAL clause, we have to be careful here
# see https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/WDQS_graph_split/Internal_Federation_Guide#Returning_variables_bound_by_OPTIONAL
OPTIONAL { ?thesis wdt:P50 ?author. }
# No need to use the BIND(?thesisLabel AS ?thesisLabel)/BIND(?thesisDescription AS ?thesisDescription) trick here since we wrap our federated query
# with a SELECT to workaround issues with the optionally bound ?author variable
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}
} UNION {
# Union them with the publications in the main graph (blogs, articles...)
?thesis wdt:P31 ?thesisType ;
wdt:P953 ?lse_url.
FILTER(STRSTARTS(STR(?lse_url), "http://etheses.lse.ac.uk"))
OPTIONAL { ?thesis wdt:P50 ?author. }
}
OPTIONAL {
?authorwp schema:about ?author;
schema:isPartOf <https://en.wikipedia.org/> .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY (?thesisDescription)