({{, SPARQLAsk[pattern] 
is a query operator that can be applied to an (PackageLink[RDFStore, paclet:GraphStore/ref/RDFStore, GraphStore Package Symbol]), which returns (RefLink[True, paclet:ref/True]) if pattern matches, and (RefLink[False, paclet:ref/False]) otherwise.}})

OpenersNotesSection(Spacer1)Details

SPARQLAsk can be used in (PackageLink[SPARQLExecute, paclet:GraphStore/ref/SPARQLExecute, GraphStore Package Symbol]) to query a SPARQL endpoint.

The result of executing SPARQLAsk[pattern] is (RefLink[True, paclet:ref/True]) if there is a subgraph matching pattern, and (RefLink[False, paclet:ref/False]) otherwise.

In SPARQLAsk[pattern], pattern can take the same form as in (PackageLink[SPARQLSelect, paclet:GraphStore/ref/SPARQLSelect, GraphStore Package Symbol])[pattern].

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Needs["GraphStore`"]

Data about fruits:

schema[s_]:=IRI["http://schema.org/"<>s];
ex[s_]:=IRI["http://example.org/"<>s];

fruitGraph=RDFStore[{
RDFTriple[ex["banana"],schema["color"],"yellow"],
RDFTriple[ex["strawberry"],schema["color"],"red"],
RDFTriple[ex["strawberry"],ex["shape"],ex["round"]]
}];

Check whether there is a fruit that is both red and rectangular:

fruitGraph//SPARQLAsk[{
RDFTriple[SPARQLVariable["fruit"],schema["color"],"red"],
RDFTriple[SPARQLVariable["fruit"],ex["shape"],ex["rectangular"]]
}]

A red and round fruit exists:

fruitGraph//SPARQLAsk[{
RDFTriple[SPARQLVariable["fruit"],schema["color"],"red"],
RDFTriple[SPARQLVariable["fruit"],ex["shape"],ex["round"]]
}]

OpenersExampleSection1(Spacer1)Scope  (1)

Needs["GraphStore`"]

Ask Wikidata whether there is a human (Q5) with German label "Albert Einstein":

rdfs[s_]:=IRI["http://www.w3.org/2000/01/rdf-schema#"<>s];
wd[s_]:=IRI["http://www.wikidata.org/entity/"<>s];
wdt[s_]:=IRI["http://www.wikidata.org/prop/direct/"<>s];

SPARQLExecute[
"https://query.wikidata.org/sparql",
SPARQLAsk[{
RDFTriple[SPARQLVariable["human"],wdt["P31"],wd["Q5"]],
RDFTriple[SPARQLVariable["human"],rdfs["label"],RDFString["Albert Einstein","de"]]
}]
]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(PackageLink[SPARQLSelect, paclet:GraphStore/ref/SPARQLSelect, GraphStore Package Symbol])  ▪  (PackageLink[SPARQLConstruct, paclet:GraphStore/ref/SPARQLConstruct, GraphStore Package Symbol])  ▪  (PackageLink[SPARQLExecute, paclet:GraphStore/ref/SPARQLExecute, GraphStore Package Symbol])  ▪  (PackageLink[RDFStore, paclet:GraphStore/ref/RDFStore, GraphStore Package Symbol])  ▪  (PackageLink[SPARQLQuery, paclet:GraphStore/ref/SPARQLQuery, GraphStore Package Symbol])  ▪  (PackageLink[SPARQLVariable, paclet:GraphStore/ref/SPARQLVariable, GraphStore Package Symbol])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Store Overview, paclet:GraphStore/guide/GraphStoreOverview])}, {▪(RefLinkPlain[Querying RDF Stores Using SPARQL, paclet:GraphStore/guide/SPARQLQuery])}})}})