Example SPARQL queries in Wolfram Language: Difference between revisions

From Synthesis Infrastructures
No edit summary
No edit summary
 
Line 1: Line 1:
<syntaxhighlight lang="mathematica">
This code transforms the string SPARQL query into  a Wolfram Language SPARQLQuery.<syntaxhighlight lang="mathematica">
ImportString[
ImportString[
  "SELECT?subject?predicate?object
  "SELECT?subject?predicate?object
WHERE {?subject ?predicate ?object .}",
WHERE {?subject ?predicate ?object .}",
  "SPARQLQuery"]
  "SPARQLQuery"]
</syntaxhighlight><syntaxhighlight lang="mathematica">
</syntaxhighlight>The query below is the Wolfram Language representation of the query above,<syntaxhighlight lang="mathematica">
query = SPARQLQuery[
query = SPARQLQuery[
   SPARQLSelect[{RDFTriple[SPARQLVariable["subject"],  
   SPARQLSelect[{RDFTriple[SPARQLVariable["subject"],  
       SPARQLVariable["predicate"], SPARQLVariable["object"]]}]/*
       SPARQLVariable["predicate"], SPARQLVariable["object"]]}]/*
   SPARQLProject[{"subject", "predicate", "object"}]]
   SPARQLProject[{"subject", "predicate", "object"}]]
</syntaxhighlight><syntaxhighlight lang="mathematica">
</syntaxhighlight>This code executes the query above agains the semiWiki RDFStore created in [[Import SMW .jsonld as RDFStore in Wolfram Language]]<syntaxhighlight lang="mathematica">
SPARQLExecute[semiWiki, query]
SPARQLExecute[semiWiki, query]
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 16:30, 13 November 2022

This code transforms the string SPARQL query into a Wolfram Language SPARQLQuery.

ImportString[
 "SELECT?subject?predicate?object
WHERE {?subject ?predicate ?object .}",
 "SPARQLQuery"]

The query below is the Wolfram Language representation of the query above,

query = SPARQLQuery[
  SPARQLSelect[{RDFTriple[SPARQLVariable["subject"], 
      SPARQLVariable["predicate"], SPARQLVariable["object"]]}]/*
   SPARQLProject[{"subject", "predicate", "object"}]]

This code executes the query above agains the semiWiki RDFStore created in Import SMW .jsonld as RDFStore in Wolfram Language

SPARQLExecute[semiWiki, query]