RDF.ex v0.3.0 RDF.Dataset View Source
A set of RDF.Graph
s.
It may have multiple named graphs and at most one unnamed (“default”) graph.
RDF.Dataset
implements:
- Elixirs
Access
behaviour - Elixirs
Enumerable
protocol - Elixirs
Inspect
protocol - the
RDF.Data
protocol
Link to this section Summary
Functions
Adds triples and quads to a RDF.Dataset
The default graph of a RDF.Dataset
Deletes statements from a RDF.Dataset
Deletes the default graph
Deletes the given graph
Checks if a graph of a RDF.Dataset
contains statements about the given resource
Fetches the RDF.Graph
with the given name
Fetches the RDF.Graph
with the given name
Gets and updates the graph with the given name, in a single pass
The graph with given name
The set of all graphs
Returns if a given statement is in a RDF.Dataset
Creates an empty unnamed RDF.Dataset
Creates an empty named RDF.Dataset
Creates a named RDF.Dataset
from another RDF.Dataset
The set of all resources used in the objects within a RDF.Dataset
Pops an arbitrary statement from a RDF.Dataset
Pops the graph with the given name
The set of all properties used in the predicates within all graphs of a RDF.Dataset
Adds statements to a RDF.Dataset
and overwrites all existing statements with the same subjects and predicates in the specified graph context
The set of all resources used within a RDF.Dataset
The number of statements within a RDF.Dataset
All statements within all graphs of a RDF.Dataset
The set of all subjects used in the statement within all graphs of a RDF.Dataset
Returns the names of all graphs of a RDF.Dataset
containing statements about the given subject
Link to this section Types
Link to this section Functions
Adds triples and quads to a RDF.Dataset
.
The optional third graph_context
argument allows to set a different
destination graph to which the statements are added, ignoring the graph context
of given quads or the name of given graphs.
The default graph of a RDF.Dataset
.
Deletes statements from a RDF.Dataset
.
The optional third graph_context
argument allows to set a different
destination graph from which the statements are deleted, ignoring the graph
context of given quads or the name of given graphs.
Note: When the statements to be deleted are given as another RDF.Dataset
,
the dataset name must not match dataset name of the dataset from which the statements
are deleted. If you want to delete only datasets with matching names, you can
use RDF.Data.delete/2
.
Deletes the default graph.
Deletes the given graph.
Checks if a graph of a RDF.Dataset
contains statements about the given resource.
Examples
iex> RDF.Dataset.new([{EX.S1, EX.p1, EX.O1}]) |> RDF.Dataset.describes?(EX.S1)
true
iex> RDF.Dataset.new([{EX.S1, EX.p1, EX.O1}]) |> RDF.Dataset.describes?(EX.S2)
false
Fetches the RDF.Graph
with the given name.
When a graph with the given name can not be found can not be found :error
is returned.
Examples
iex> dataset = RDF.Dataset.new([{EX.S1, EX.P1, EX.O1, EX.Graph}, {EX.S2, EX.P2, EX.O2}])
...> RDF.Dataset.fetch(dataset, EX.Graph)
{:ok, RDF.Graph.new(EX.Graph, {EX.S1, EX.P1, EX.O1})}
iex> RDF.Dataset.fetch(dataset, nil)
{:ok, RDF.Graph.new({EX.S2, EX.P2, EX.O2})}
iex> RDF.Dataset.fetch(dataset, EX.Foo)
:error
Fetches the RDF.Graph
with the given name.
When a graph with the given name can not be found can not be found the optionally
given default value or nil
is returned
Examples
iex> dataset = RDF.Dataset.new([{EX.S1, EX.P1, EX.O1, EX.Graph}, {EX.S2, EX.P2, EX.O2}])
...> RDF.Dataset.get(dataset, EX.Graph)
RDF.Graph.new(EX.Graph, {EX.S1, EX.P1, EX.O1})
iex> RDF.Dataset.get(dataset, nil)
RDF.Graph.new({EX.S2, EX.P2, EX.O2})
iex> RDF.Dataset.get(dataset, EX.Foo)
nil
iex> RDF.Dataset.get(dataset, EX.Foo, :bar)
:bar
Gets and updates the graph with the given name, in a single pass.
Invokes the passed function on the RDF.Graph
with the given name;
this function should return either {graph_to_return, new_graph}
or :pop
.
If the passed function returns {graph_to_return, new_graph}
, the
return value of get_and_update
is {graph_to_return, new_dataset}
where
new_dataset
is the input Dataset
updated with new_graph
for
the given name.
If the passed function returns :pop
the graph with the given name is
removed and a {removed_graph, new_dataset}
tuple gets returned.
Examples
iex> dataset = RDF.Dataset.new({EX.S, EX.P, EX.O, EX.Graph})
...> RDF.Dataset.get_and_update(dataset, EX.Graph, fn current_graph ->
...> {current_graph, {EX.S, EX.P, EX.NEW}}
...> end)
{RDF.Graph.new(EX.Graph, {EX.S, EX.P, EX.O}), RDF.Dataset.new({EX.S, EX.P, EX.NEW, EX.Graph})}
The graph with given name.
The set of all graphs.
Returns if a given statement is in a RDF.Dataset
.
Examples
iex> dataset = RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2},
...> {EX.S1, EX.p2, EX.O3}])
...> RDF.Dataset.include?(dataset, {EX.S1, EX.p1, EX.O1, EX.Graph})
true
Creates an empty unnamed RDF.Dataset
.
Creates an empty named RDF.Dataset
.
Creates a named RDF.Dataset
from another RDF.Dataset
.
The set of all resources used in the objects within a RDF.Dataset
.
Note: This function does collect only IRIs and BlankNodes, not Literals.
Examples
iex> RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2, EX.Graph},
...> {EX.S3, EX.p1, EX.O2},
...> {EX.S4, EX.p2, RDF.bnode(:bnode)},
...> {EX.S5, EX.p3, "foo"}
...> ]) |> RDF.Dataset.objects
MapSet.new([RDF.iri(EX.O1), RDF.iri(EX.O2), RDF.bnode(:bnode)])
Pops an arbitrary statement from a RDF.Dataset
.
Pops the graph with the given name.
When a graph with given name can not be found the optionally given default value
or nil
is returned.
Examples
iex> dataset = RDF.Dataset.new([
...> {EX.S1, EX.P1, EX.O1, EX.Graph},
...> {EX.S2, EX.P2, EX.O2}])
...> RDF.Dataset.pop(dataset, EX.Graph)
{RDF.Graph.new(EX.Graph, {EX.S1, EX.P1, EX.O1}), RDF.Dataset.new({EX.S2, EX.P2, EX.O2})}
iex> RDF.Dataset.pop(dataset, EX.Foo)
{nil, dataset}
The set of all properties used in the predicates within all graphs of a RDF.Dataset
.
Examples
iex> RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2},
...> {EX.S1, EX.p2, EX.O3}]) |>
...> RDF.Dataset.predicates
MapSet.new([EX.p1, EX.p2])
Adds statements to a RDF.Dataset
and overwrites all existing statements with the same subjects and predicates in the specified graph context.
Examples
iex> dataset = RDF.Dataset.new({EX.S, EX.P1, EX.O1})
...> RDF.Dataset.put(dataset, {EX.S, EX.P1, EX.O2})
RDF.Dataset.new({EX.S, EX.P1, EX.O2})
iex> RDF.Dataset.put(dataset, {EX.S, EX.P2, EX.O2})
RDF.Dataset.new([{EX.S, EX.P1, EX.O1}, {EX.S, EX.P2, EX.O2}])
iex> RDF.Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}]) |>
...> RDF.Dataset.put([{EX.S1, EX.P2, EX.O3}, {EX.S2, EX.P2, EX.O3}])
RDF.Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S1, EX.P2, EX.O3}, {EX.S2, EX.P2, EX.O3}])
The set of all resources used within a RDF.Dataset
.
Examples
iex> RDF.Dataset.new([ …> {EX.S1, EX.p1, EX.O1, EX.Graph}, …> {EX.S2, EX.p1, EX.O2, EX.Graph}, …> {EX.S2, EX.p2, RDF.bnode(:bnode)}, …> {EX.S3, EX.p1, “foo”} …> ]) |> RDF.Dataset.resources MapSet.new([RDF.iri(EX.S1), RDF.iri(EX.S2), RDF.iri(EX.S3),
RDF.iri(EX.O1), RDF.iri(EX.O2), RDF.bnode(:bnode), EX.p1, EX.p2])
The number of statements within a RDF.Dataset
.
Examples
iex> RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2},
...> {EX.S1, EX.p2, EX.O3}]) |>
...> RDF.Dataset.statement_count
3
All statements within all graphs of a RDF.Dataset
.
Examples
iex> RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2},
...> {EX.S1, EX.p2, EX.O3}]) |>
...> RDF.Dataset.statements
[{RDF.iri(EX.S1), RDF.iri(EX.p1), RDF.iri(EX.O1), RDF.iri(EX.Graph)},
{RDF.iri(EX.S1), RDF.iri(EX.p2), RDF.iri(EX.O3)},
{RDF.iri(EX.S2), RDF.iri(EX.p2), RDF.iri(EX.O2)}]
The set of all subjects used in the statement within all graphs of a RDF.Dataset
.
Examples
iex> RDF.Dataset.new([
...> {EX.S1, EX.p1, EX.O1, EX.Graph},
...> {EX.S2, EX.p2, EX.O2},
...> {EX.S1, EX.p2, EX.O3}]) |>
...> RDF.Dataset.subjects
MapSet.new([RDF.iri(EX.S1), RDF.iri(EX.S2)])
Returns the names of all graphs of a RDF.Dataset
containing statements about the given subject.
Examples
iex> dataset = RDF.Dataset.new([
...> {EX.S1, EX.p, EX.O},
...> {EX.S2, EX.p, EX.O},
...> {EX.S1, EX.p, EX.O, EX.Graph1},
...> {EX.S2, EX.p, EX.O, EX.Graph2}])
...> RDF.Dataset.who_describes(dataset, EX.S1)
[nil, RDF.iri(EX.Graph1)]