Add support for list of descriptions to RDF.Graph.put/2
This commit is contained in:
parent
69fbdd60b3
commit
2a44765631
2 changed files with 30 additions and 4 deletions
|
@ -277,10 +277,20 @@ defmodule RDF.Graph do
|
|||
def put(%__MODULE__{} = graph, statements) when is_list(statements) do
|
||||
put(
|
||||
graph,
|
||||
Enum.group_by(statements, &elem(&1, 0), fn
|
||||
{_, p, o} -> {p, o}
|
||||
{_, predications} -> predications
|
||||
end)
|
||||
Enum.group_by(
|
||||
statements,
|
||||
fn
|
||||
{subject, _} -> subject
|
||||
{subject, _, _} -> subject
|
||||
{subject, _, _, _} -> subject
|
||||
%Description{subject: subject} -> subject
|
||||
end,
|
||||
fn
|
||||
{_, p, o} -> {p, o}
|
||||
{_, predications} -> predications
|
||||
%Description{} = description -> description
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -402,6 +402,22 @@ defmodule RDF.GraphTest do
|
|||
assert graph_includes_statement?(g, {EX.S2, EX.P2, EX.O2})
|
||||
end
|
||||
|
||||
test "a list of descriptions" do
|
||||
g =
|
||||
Graph.new([{EX.S1, EX.p1(), EX.O1}, {EX.S2, EX.p2(), EX.O2}, {EX.S1, EX.p3(), EX.O3}])
|
||||
|> RDF.Graph.put([
|
||||
EX.p1(EX.S1, EX.O41),
|
||||
EX.p2(EX.S2, EX.O42),
|
||||
EX.p2(EX.S2, EX.O43)
|
||||
])
|
||||
|
||||
assert Graph.triple_count(g) == 4
|
||||
assert graph_includes_statement?(g, {EX.S1, EX.p3(), EX.O3})
|
||||
assert graph_includes_statement?(g, {EX.S1, EX.p1(), EX.O41})
|
||||
assert graph_includes_statement?(g, {EX.S2, EX.p2(), EX.O42})
|
||||
assert graph_includes_statement?(g, {EX.S2, EX.p2(), EX.O43})
|
||||
end
|
||||
|
||||
test "a graph" do
|
||||
g =
|
||||
Graph.new([
|
||||
|
|
Loading…
Reference in a new issue