SPARQLConstruct
Details and Options
- SPARQLConstruct can be used in SPARQLExecute to query a SPARQL endpoint.
- The result of executing SPARQLConstruct[patterntemplate] is a RDFStore object containing for each solution the triples of template where variables have been replaced with values of this solution.
- In SPARQLConstruct[pattern], pattern can take the same form as in SPARQLSelect[pattern].
Examples
open all close allBasic Examples (1)
Needs["GraphStore`"]Specify a graph of first and family names:
foaf[s_] := URL["http://xmlns.com/foaf/0.1/" <> s];
ex[s_] := URL["http://example.org/" <> s];peopleGraph = RDFStore[{
RDFTriple[ex["tom"], foaf["firstName"], "Tom"],
RDFTriple[ex["tom"], foaf["familyName"], "Smith"],
RDFTriple[ex["alice"], foaf["firstName"], "Alice"],
RDFTriple[ex["alice"], foaf["familyName"], "Meier"]
}];Construct a graph with only the family names:
peopleGraph//SPARQLConstruct[RDFTriple[SPARQLVariable["person"], foaf["firstName"], SPARQLVariable["first"]]]Scope (1)
Needs["GraphStore`"]Retrieve a graph of cats and their names from Wikidata:
rdfs[s_] := URL["http://www.w3.org/2000/01/rdf-schema#" <> s];
wikibase[s_] := URL["http://wikiba.se/ontology#" <> s];
bd[s_] := URL["http://www.bigdata.com/rdf#" <> s];
wd[s_] := URL["http://www.wikidata.org/entity/" <> s];
wdt[s_] := URL["http://www.wikidata.org/prop/direct/" <> s];SPARQLExecute[
"https://query.wikidata.org/sparql",
SPARQLConstruct[{
RDFTriple[SPARQLVariable["item"], wdt["P31"], wd["Q146"]],
SPARQLService[wikibase["label"], RDFTriple[bd["serviceParam"], wikibase["language"], "en"]]
} -> RDFTriple[SPARQLVariable["item"], rdfs["label"], SPARQLVariable["itemLabel"]]
]
]Related Guides
Text
Wolfram Research (2019), SPARQLConstruct, Wolfram Language function, https://reference.wolfram.com/language/GraphStore/ref/SPARQLConstruct.html.
CMS
Wolfram Language. 2019. "SPARQLConstruct." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphStore/ref/SPARQLConstruct.html.
APA
Wolfram Language. (2019). SPARQLConstruct. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphStore/ref/SPARQLConstruct.html
BibTeX
@misc{reference.wolfram_2026_sparqlconstruct, author="Wolfram Research", title="{SPARQLConstruct}", year="2019", howpublished="\url{https://reference.wolfram.com/language/GraphStore/ref/SPARQLConstruct.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sparqlconstruct, organization={Wolfram Research}, title={SPARQLConstruct}, year={2019}, url={https://reference.wolfram.com/language/GraphStore/ref/SPARQLConstruct.html}, note=[Accessed: 13-June-2026]}