RDFStore[{t1,t2,…}]
represents an RDF graph with triples ti.
RDFStore[{t1,t2,…},name1{s11,s12,…},…]
represents an RDF dataset with default graph consisting of the triples ti and named graphs consisting of the triples sij with names namei.
RDFStore
RDFStore[{t1,t2,…}]
represents an RDF graph with triples ti.
RDFStore[{t1,t2,…},name1{s11,s12,…},…]
represents an RDF dataset with default graph consisting of the triples ti and named graphs consisting of the triples sij with names namei.
Details and Options
- RDF stands for Resource Description Framework.
- Resources are identified by IRIs.
- Statements about resources are made with triples RDFTriple[subj, pred, obj] where subj is the subject to be described, pred is the predicate and obj is the value.
- Subjects, predicates and objects are typically IRIs or blank nodes. Objects can also be literals like strings, numbers and Booleans.
- When querying an RDF dataset using SPARQLSelect[pattern] then pattern is matched against the default graph. SPARQLSelect[SPARQLGraph[name,pattern]] can be used to match pattern against the graph named name.
Examples
open all close allBasic Examples (1)
Needs["GraphStore`"]Introduce vocabulary helper functions:
rdf[s_] := URL["http://www.w3.org/1999/02/22-rdf-syntax-ns#" <> s];
rdfs[s_] := URL["http://www.w3.org/2000/01/rdf-schema#" <> s];
schema[s_] := URL["http://schema.org/" <> s];
ex[s_] := URL["http://example.org/" <> s];Represent information about Albert Einstein:
einsteinStore = RDFStore[{
RDFTriple[ex["einstein"], rdf["type"], schema["Person"]],
RDFTriple[ex["einstein"], rdfs["label"], "Albert Einstein"],
RDFTriple[ex["einstein"], schema["birthDate"], DateObject[{1879, 3, 14}, TimeZone -> None]]
}];einsteinStore//SPARQLSelect[
RDFTriple[SPARQLVariable["s"], SPARQLVariable["p"], SPARQLVariable["o"]] -> "p",
"Distinct" -> True
]Look up the name and birth date:
einsteinStore//SPARQLSelect[{
RDFTriple[SPARQLVariable["person"], rdfs["label"], SPARQLVariable["name"]],
RDFTriple[SPARQLVariable["person"], schema["birthDate"], SPARQLVariable["birthDate"]]
} -> {"name", "birthDate"}]Export in the "Turtle" format:
ExportString[einsteinStore, "Turtle", "Prefixes" -> <|
"rdfs" -> "http://www.w3.org/2000/01/rdf-schema#",
"xsd" -> "http://www.w3.org/2001/XMLSchema#",
"schema" -> "http://schema.org/",
"ex" -> "http://example.org/"
|>]Scope (2)
Needs["GraphStore`"]Represent information about countries:
rdf[s_] := URL["http://www.w3.org/1999/02/22-rdf-syntax-ns#" <> s];
rdfs[s_] := URL["http://www.w3.org/2000/01/rdf-schema#" <> s];
owl[s_] := URL["http://www.w3.org/2002/07/owl#" <> s];
wd[s_] := URL["http://www.wikidata.org/entity/" <> s];
schema[s_] := URL["http://schema.org/" <> s];
ex[s_] := URL["http://example.org/" <> s];countryStore = RDFStore[{
(* Spain *)
RDFTriple[ex["spain"], rdf["type"], schema["Country"]],
RDFTriple[ex["spain"], rdfs["label"], "Spain"],
RDFTriple[ex["spain"], ex["population"], 46528024],
RDFTriple[ex["spain"], owl["sameAs"], wd["Q29"]],
(* Hungary *)
RDFTriple[ex["hungary"], rdf["type"], schema["Country"]],
RDFTriple[ex["hungary"], rdfs["label"], "Hungary"],
RDFTriple[ex["hungary"], ex["population"], 9817958],
RDFTriple[ex["hungary"], owl["sameAs"], wd["Q28"]]
}]countryStore//SPARQLSelect[RDFTriple[ex["spain"], ex["population"], SPARQLVariable["pop"]]]countryStore//SPARQLSelect[{
RDFTriple[SPARQLVariable["country"], rdfs["label"], SPARQLVariable["label"]],
RDFTriple[SPARQLVariable["country"], ex["population"], SPARQLVariable["pop"]]
} -> {"label", "pop"}]countryStore//SPARQLSelect[{
RDFTriple[SPARQLVariable["country"], owl["sameAs"], wd["Q29"]],
RDFTriple[SPARQLVariable["country"], rdfs["label"], SPARQLVariable["label"]],
RDFTriple[SPARQLVariable["country"], ex["population"], SPARQLVariable["pop"]]
} -> {"label", "pop"}]Needs["GraphStore`"]Country data with current data in the default graph and historical data in graphs named after the year:
rdf[s_] := URL["http://www.w3.org/1999/02/22-rdf-syntax-ns#" <> s];
rdfs[s_] := URL["http://www.w3.org/2000/01/rdf-schema#" <> s];
owl[s_] := URL["http://www.w3.org/2002/07/owl#" <> s];
wd[s_] := URL["http://www.wikidata.org/entity/" <> s];
schema[s_] := URL["http://schema.org/" <> s];
time[s_] := URL["http://www.w3.org/2006/time#" <> s];
ex[s_] := URL["http://example.org/" <> s];countryStore = RDFStore[
{
(* Spain *)
RDFTriple[ex["spain"], rdf["type"], schema["Country"]],
RDFTriple[ex["spain"], rdfs["label"], "Spain"],
RDFTriple[ex["spain"], ex["population"], 46528024],
RDFTriple[ex["spain"], owl["sameAs"], wd["Q29"]],
(* Hungary *)
RDFTriple[ex["hungary"], rdf["type"], schema["Country"]],
RDFTriple[ex["hungary"], rdfs["label"], "Hungary"],
RDFTriple[ex["hungary"], ex["population"], 9817958],
RDFTriple[ex["hungary"], owl["sameAs"], wd["Q28"]]
},
<|
ex["historical/1961"] -> {
RDFTriple[ex["historical/1961"], time["year"], 1961],
RDFTriple[ex["spain"], ex["population"], 30739250]
},
ex["historical/1980"] -> {
RDFTriple[ex["historical/1980"], time["year"], 1980],
RDFTriple[ex["spain"], ex["population"], 37439035]
}
|>
];Find the current population of all countries in the default graph of the dataset:
countryStore//SPARQLSelect[{
RDFTriple[SPARQLVariable["country"], rdfs["label"], SPARQLVariable["label"]],
RDFTriple[SPARQLVariable["country"], ex["population"], SPARQLVariable["pop"]]
} -> {"label", "pop"}]Access historical population data of Spain:
countryStore//SPARQLSelect[SPARQLGraph[SPARQLVariable["g"], {
RDFTriple[SPARQLVariable["g"], time["year"], SPARQLVariable["year"]],
RDFTriple[ex["spain"], ex["population"], SPARQLVariable["pop"]]
}] -> {"year", "pop"}]Properties & Relations (2)
Needs["GraphStore`"]ex[s_] := URL["http://example.org/" <> s];personStore = RDFStore[{
RDFTriple[ex["maria"], ex["age"], 39],
RDFTriple[ex["maria"], ex["hasParent"], ex["jesus"]],
RDFTriple[ex["jesus"], ex["age"], 64]
}];Create a Graph with subject-object pairs as edges and predicates as edge tags:
personStore//SPARQLSelect[
RDFTriple[SPARQLVariable["s"], SPARQLVariable["p"], SPARQLVariable["o"]]
]//Map[Function[
DirectedEdge[#s, #o, #p]
]]//Graph[#, VertexLabels -> "Name", ImageSize -> Medium]&Needs["GraphStore`"]Specify a Graph with tagged edges:
g = Graph[{
DirectedEdge["a", "b", "p1"],
DirectedEdge["b", "c", "p1"],
DirectedEdge["c", "a", "p2"]
}, VertexLabels -> Automatic, EdgeLabels -> Automatic]Convert the graph to an RDF graph:
ex[s_] := URL["http://example.org/" <> s];RDFStore[
Function[{u, v, t},
RDFTriple[ex[u], ex[t], ex[v]]
]@@@EdgeList[g]
]%["DefaultGraph"]See Also
Text
Wolfram Research (2019), RDFStore, Wolfram Language function, https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html.
CMS
Wolfram Language. 2019. "RDFStore." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html.
APA
Wolfram Language. (2019). RDFStore. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html
BibTeX
@misc{reference.wolfram_2026_rdfstore, author="Wolfram Research", title="{RDFStore}", year="2019", howpublished="\url{https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_rdfstore, organization={Wolfram Research}, title={RDFStore}, year={2019}, url={https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html}, note=[Accessed: 12-June-2026]}