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.
更多信息和选项
- 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.
范例
打开所有单元 关闭所有单元基本范例 (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 labels:
personStore//SPARQLSelect[
RDFTriple[SPARQLVariable["s"], SPARQLVariable["p"], SPARQLVariable["o"]]
]//Map[Function[
Property[#s#o, EdgeLabels -> #p]
]]//Graph[#, VertexLabels -> "Name"]&Needs["GraphStore`"]Specify a Graph and label each edge with a property name:
g = Graph[{
Property["a" -> "b", "property" -> "p1"],
Property["b" -> "c", "property" -> "p1"],
Property["c" -> "a", "property" -> "p2"]
}]Convert the graph to an RDF graph:
ex[s_] := URL["http://example.org/" <> s];g//EdgeList//Map[Function[e,
RDFTriple[
ex[First[e]],
ex[PropertyValue[{g, e}, "property"]],
ex[Last[e]]
]
]]//RDFStore%["DefaultGraph"]文本
Wolfram Research (2019),RDFStore,Wolfram 语言函数,https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html.
CMS
Wolfram 语言. 2019. "RDFStore." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/GraphStore/ref/RDFStore.html.
APA
Wolfram 语言. (2019). RDFStore. Wolfram 语言与系统参考资料中心. 追溯自 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: 13-August-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: 13-August-2026]}