I am using the following query to get subclass of
predicate up and down for a given concept in wikidata.
SELECT ?item ?itemLabel ?linkTo {
{ wd:Q22673982 wdt:P279* ?item } UNION { ?item wdt:P279* wd:Q22673982 }
OPTIONAL { ?item wdt:P279 ?linkTo }
SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}
In order to limit the hops only to 10, I extended the aforementioned query into the following.
PREFIX gas: <http://www.bigdata.com/rdf/gas#>
SELECT ?item ?itemLabel ?linkTo {
{ SERVICE gas:service {
gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" ;
gas:in wd:Q22673982 ;
gas:traversalDirection "Forward" ;
gas:out ?item ;
gas:out1 ?depth ;
gas:maxVisited 10 ;
gas:linkType wdt:P279 .
} } UNION { SERVICE gas:service {
gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" ;
gas:in wd:Q22673982 ;
gas:traversalDirection "Reverse" ;
gas:out ?item ;
gas:out1 ?depth ;
gas:maxVisited 10 ;
gas:linkType wdt:P279 .
} }
OPTIONAL { ?item wdt:P279 ?linkTo }
SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}
I tried to do it in a similar way using DBpedia as follows.
SELECT * {
{ dbr:Word2vec dct:subject* ?item } UNION { ?item dct:subject* dbr:Word2vec }
OPTIONAL { ?item dct:subject ?linkTo }
}
However, I get the following error: Virtuoso 37000 Error SP031: SPARQL compiler: Variable '_::trans_subj_4_0' is used in subexpressions of the query but not assigned
My question is; Is it possible to do the same in DBpedia?
I am happy to provide more details if needed.
The Virtuoso 37000 Error SP031: SPARQL compiler:... error is flagged in a couple of open issues (#530, #681) on the github-hosted Virtuoso project.
As noted there, your query will likely run if you simply un-tick the Strict checking of void variables box on the SPARQL query form.