Add RDF.Graph.annotations/1
This commit is contained in:
parent
8469be877d
commit
d0a1106b5d
2 changed files with 29 additions and 0 deletions
|
@ -636,6 +636,21 @@ defmodule RDF.Graph do
|
|||
Map.values(graph.descriptions)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the `RDF.Graph` of all annotations.
|
||||
|
||||
Note: The graph includes only triples where the subject is a quoted triple.
|
||||
Triples where only the object is a quoted triple are NOT included.
|
||||
"""
|
||||
@spec annotations(t) :: t
|
||||
def annotations(%__MODULE__{} = graph) do
|
||||
%__MODULE__{
|
||||
graph
|
||||
| descriptions:
|
||||
for(annotation = {{_, _, _}, _} <- graph.descriptions, into: %{}, do: annotation)
|
||||
}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets and updates the description of the given subject, in a single pass.
|
||||
|
||||
|
|
|
@ -715,6 +715,20 @@ defmodule RDF.Star.Graph.Test do
|
|||
end
|
||||
end
|
||||
|
||||
describe "annotations/1" do
|
||||
test "when no annotations exist" do
|
||||
assert Graph.annotations(graph()) == graph()
|
||||
end
|
||||
|
||||
test "when annotations exist" do
|
||||
assert Graph.annotations(graph_with_annotation()) == graph_with_annotation()
|
||||
|
||||
assert graph_with_annotation()
|
||||
|> Graph.add(statement())
|
||||
|> Graph.annotations() == graph_with_annotation()
|
||||
end
|
||||
end
|
||||
|
||||
test "include?/3" do
|
||||
assert Graph.include?(graph_with_annotations(), star_statement())
|
||||
assert Graph.include?(graph_with_annotations(), {EX.As, EX.ap(), statement()})
|
||||
|
|
Loading…
Reference in a new issue