RDF.ex v0.4.0 RDF.Graph View Source

A set of RDF triples with an optional name.

RDF.Graph implements:

Link to this section Summary

Functions

Adds triples to a RDF.Graph

Deletes statements from a RDF.Graph

Deletes all statements with the given subjects

Checks if a RDF.Graph contains statements about the given resource

The RDF.Description of the given subject

Fetches the description of the given subject

Gets the description of the given subject

Gets and updates the description of the given subject, in a single pass

Checks if the given statement exists within a RDF.Graph

Creates an empty unnamed RDF.Graph

Creates an empty named RDF.Graph

Creates a named RDF.Graph from another RDF.Graph

Creates an unnamed RDF.Graph with initial triples

Creates a named RDF.Graph with initial triples

The set of all resources used in the objects within a RDF.Graph

Pops an arbitrary triple from a RDF.Graph

Pops the description of the given subject

The set of all properties used in the predicates of the statements within a RDF.Graph

Adds statements to a RDF.Graph and overwrites all existing statements with the same subjects and predicates

Add statements to a RDF.Graph, overwriting all statements with the same subject and predicate

Add statements to a RDF.Graph, overwriting all statements with the same subject and predicate

The set of all resources used within a RDF.Graph

The number of subjects within a RDF.Graph

The set of all subjects used in the statements within a RDF.Graph

The number of statements within a RDF.Graph

The list of all statements within a RDF.Graph

Link to this section Types

Link to this section Functions

Adds triples to a RDF.Graph.

Note: When the statements to be added are given as another RDF.Graph, the graph name must not match graph name of the graph to which the statements are added. As opposed to that RDF.Data.merge/2 will produce a RDF.Dataset containing both graphs.

Link to this function add(graph, subject, predicate, objects) View Source

Adds triples to a RDF.Graph.

Deletes statements from a RDF.Graph.

Note: When the statements to be deleted are given as another RDF.Graph, the graph name must not match graph name of the graph from which the statements are deleted. If you want to delete only graphs with matching names, you can use RDF.Data.delete/2.

Link to this function delete(graph, subject, predicate, object) View Source

Deletes statements from a RDF.Graph.

Link to this function delete_subjects(graph, subjects) View Source

Deletes all statements with the given subjects.

Link to this function describes?(graph, subject) View Source

Checks if a RDF.Graph contains statements about the given resource.

Examples

iex> RDF.Graph.new([{EX.S1, EX.p1, EX.O1}]) |> RDF.Graph.describes?(EX.S1)
  true
  iex> RDF.Graph.new([{EX.S1, EX.p1, EX.O1}]) |> RDF.Graph.describes?(EX.S2)
  false
Link to this function description(graph, subject) View Source

The RDF.Description of the given subject.

Fetches the description of the given subject.

When the subject can not be found :error is returned.

Examples

iex> RDF.Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}]) |>
...>   RDF.Graph.fetch(EX.S1)
{:ok, RDF.Description.new({EX.S1, EX.P1, EX.O1})}
iex> RDF.Graph.fetch(RDF.Graph.new, EX.foo)
:error
Link to this function get(graph, subject, default \\ nil) View Source

Gets the description of the given subject.

When the subject can not be found the optionally given default value or nil is returned.

Examples

iex> RDF.Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}]) |>
...>   RDF.Graph.get(EX.S1)
RDF.Description.new({EX.S1, EX.P1, EX.O1})
iex> RDF.Graph.get(RDF.Graph.new, EX.Foo)
nil
iex> RDF.Graph.get(RDF.Graph.new, EX.Foo, :bar)
:bar
Link to this function get_and_update(graph, subject, fun) View Source

Gets and updates the description of the given subject, in a single pass.

Invokes the passed function on the RDF.Description of the given subject; this function should return either {description_to_return, new_description} or :pop.

If the passed function returns {description_to_return, new_description}, the return value of get_and_update is {description_to_return, new_graph} where new_graph is the input Graph updated with new_description for the given subject.

If the passed function returns :pop the description for the given subject is removed and a {removed_description, new_graph} tuple gets returned.

Examples

iex> RDF.Graph.new({EX.S, EX.P, EX.O}) |>
...>   RDF.Graph.get_and_update(EX.S, fn current_description ->
...>     {current_description, {EX.P, EX.NEW}}
...>   end)
{RDF.Description.new(EX.S, EX.P, EX.O), RDF.Graph.new(EX.S, EX.P, EX.NEW)}

Checks if the given statement exists within a RDF.Graph.

Creates an empty unnamed RDF.Graph.

Creates an empty named RDF.Graph.

Creates a named RDF.Graph from another RDF.Graph.

Link to this function new(subject, predicate, objects) View Source

Creates an unnamed RDF.Graph with initial triples.

Link to this function new(name, subject, predicate, objects) View Source

Creates a named RDF.Graph with initial triples.

The set of all resources used in the objects within a RDF.Graph.

Note: This function does collect only IRIs and BlankNodes, not Literals.

Examples

iex> RDF.Graph.new([
...>   {EX.S1, EX.p1, EX.O1},
...>   {EX.S2, EX.p2, EX.O2},
...>   {EX.S3, EX.p1, EX.O2},
...>   {EX.S4, EX.p2, RDF.bnode(:bnode)},
...>   {EX.S5, EX.p3, "foo"}
...> ]) |> RDF.Graph.objects
MapSet.new([RDF.iri(EX.O1), RDF.iri(EX.O2), RDF.bnode(:bnode)])

Pops an arbitrary triple from a RDF.Graph.

Pops the description of the given subject.

When the subject can not be found the optionally given default value or nil is returned.

Examples

iex> RDF.Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}]) |>
...>   RDF.Graph.pop(EX.S1)
{RDF.Description.new({EX.S1, EX.P1, EX.O1}), RDF.Graph.new({EX.S2, EX.P2, EX.O2})}
iex> RDF.Graph.pop(RDF.Graph.new({EX.S, EX.P, EX.O}), EX.Missing)
{nil, RDF.Graph.new({EX.S, EX.P, EX.O})}

The set of all properties used in the predicates of the statements within a RDF.Graph.

Examples

iex> RDF.Graph.new([
...>   {EX.S1, EX.p1, EX.O1},
...>   {EX.S2, EX.p2, EX.O2},
...>   {EX.S1, EX.p2, EX.O3}]) |>
...>   RDF.Graph.predicates
MapSet.new([EX.p1, EX.p2])

Adds statements to a RDF.Graph and overwrites all existing statements with the same subjects and predicates.

Examples

iex> RDF.Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}]) |>
...>   RDF.Graph.put([{EX.S1, EX.P2, EX.O3}, {EX.S2, EX.P2, EX.O3}])
RDF.Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S1, EX.P2, EX.O3}, {EX.S2, EX.P2, EX.O3}])
Link to this function put(graph, subject, predications) View Source

Add statements to a RDF.Graph, overwriting all statements with the same subject and predicate.

Link to this function put(graph, subject, predicate, objects) View Source

Add statements to a RDF.Graph, overwriting all statements with the same subject and predicate.

Examples

iex> RDF.Graph.new(EX.S, EX.P, EX.O1) |> RDF.Graph.put(EX.S, EX.P, EX.O2)
RDF.Graph.new(EX.S, EX.P, EX.O2)
iex> RDF.Graph.new(EX.S, EX.P1, EX.O1) |> RDF.Graph.put(EX.S, EX.P2, EX.O2)
RDF.Graph.new([{EX.S, EX.P1, EX.O1}, {EX.S, EX.P2, EX.O2}])

The set of all resources used within a RDF.Graph.

Examples

iex> RDF.Graph.new([ …> {EX.S1, EX.p1, EX.O1}, …> {EX.S2, EX.p1, EX.O2}, …> {EX.S2, EX.p2, RDF.bnode(:bnode)}, …> {EX.S3, EX.p1, “foo”} …> ]) |> RDF.Graph.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 subjects within a RDF.Graph.

Examples

iex> RDF.Graph.new([
...>   {EX.S1, EX.p1, EX.O1},
...>   {EX.S2, EX.p2, EX.O2},
...>   {EX.S1, EX.p2, EX.O3}]) |>
...>   RDF.Graph.subject_count
2

The set of all subjects used in the statements within a RDF.Graph.

Examples

iex> RDF.Graph.new([
...>   {EX.S1, EX.p1, EX.O1},
...>   {EX.S2, EX.p2, EX.O2},
...>   {EX.S1, EX.p2, EX.O3}]) |>
...>   RDF.Graph.subjects
MapSet.new([RDF.iri(EX.S1), RDF.iri(EX.S2)])

The number of statements within a RDF.Graph.

Examples

iex> RDF.Graph.new([
...>   {EX.S1, EX.p1, EX.O1},
...>   {EX.S2, EX.p2, EX.O2},
...>   {EX.S1, EX.p2, EX.O3}]) |>
...>   RDF.Graph.triple_count
3

The list of all statements within a RDF.Graph.

Examples

iex> RDF.Graph.new([
  ...>   {EX.S1, EX.p1, EX.O1},
  ...>   {EX.S2, EX.p2, EX.O2},
  ...>   {EX.S1, EX.p2, EX.O3}
  ...> ]) |> RDF.Graph.triples
  [{RDF.iri(EX.S1), RDF.iri(EX.p1), RDF.iri(EX.O1)},
   {RDF.iri(EX.S1), RDF.iri(EX.p2), RDF.iri(EX.O3)},
   {RDF.iri(EX.S2), RDF.iri(EX.p2), RDF.iri(EX.O2)}]