Rename RDF.Graph.delete_subjects/2 to RDF.Graph.delete_descriptions/2
This commit is contained in:
parent
6315b85edf
commit
f83ac494fc
3 changed files with 21 additions and 19 deletions
|
@ -360,24 +360,26 @@ defmodule RDF.Graph do
|
|||
end
|
||||
|
||||
@doc """
|
||||
Deletes all statements with the given subjects.
|
||||
Deletes all statements with the given `subjects`.
|
||||
|
||||
If `subjects` contains subjects that are not in `graph`, they're simply ignored.
|
||||
"""
|
||||
@spec delete_subjects(
|
||||
@spec delete_descriptions(
|
||||
t,
|
||||
Statement.coercible_subject() | [Statement.coercible_subject()]
|
||||
) :: t
|
||||
def delete_subjects(graph, subjects)
|
||||
def delete_descriptions(graph, subjects)
|
||||
|
||||
def delete_subjects(%__MODULE__{} = graph, subjects) when is_list(subjects) do
|
||||
Enum.reduce(subjects, graph, &delete_subjects(&2, &1))
|
||||
def delete_descriptions(%__MODULE__{} = graph, subjects) when is_list(subjects) do
|
||||
Enum.reduce(subjects, graph, &delete_descriptions(&2, &1))
|
||||
end
|
||||
|
||||
def delete_subjects(%__MODULE__{descriptions: descriptions} = graph, subject) do
|
||||
with subject = coerce_subject(subject) do
|
||||
%__MODULE__{graph | descriptions: Map.delete(descriptions, subject)}
|
||||
end
|
||||
def delete_descriptions(%__MODULE__{descriptions: descriptions} = graph, subject) do
|
||||
%__MODULE__{graph | descriptions: Map.delete(descriptions, coerce_subject(subject))}
|
||||
end
|
||||
|
||||
defdelegate delete_subjects(graph, subjects), to: __MODULE__, as: :delete_descriptions
|
||||
|
||||
@doc """
|
||||
Updates the description of the `subject` in `graph` with the given function.
|
||||
|
||||
|
@ -433,11 +435,11 @@ defmodule RDF.Graph do
|
|||
|> fun.()
|
||||
|> case do
|
||||
nil ->
|
||||
delete_subjects(graph, subject)
|
||||
delete_descriptions(graph, subject)
|
||||
|
||||
new_description ->
|
||||
graph
|
||||
|> delete_subjects(subject)
|
||||
|> delete_descriptions(subject)
|
||||
|> add(Description.new(subject, init: new_description))
|
||||
end
|
||||
end
|
||||
|
@ -753,7 +755,7 @@ defmodule RDF.Graph do
|
|||
@spec triples(t) :: [Statement.t()]
|
||||
def triples(%__MODULE__{} = graph), do: Enum.to_list(graph)
|
||||
|
||||
defdelegate statements(graph), to: RDF.Graph, as: :triples
|
||||
defdelegate statements(graph), to: __MODULE__, as: :triples
|
||||
|
||||
@doc """
|
||||
Checks if the given `input` statements exist within `graph`.
|
||||
|
|
|
@ -353,8 +353,8 @@ defmodule RDF.DataTest do
|
|||
assert RDF.Data.equal?(Graph.new(description, name: EX.Graph), description)
|
||||
assert RDF.Data.equal?(graph, Dataset.new(graph))
|
||||
|
||||
refute RDF.Data.equal?(graph, graph |> Graph.delete_subjects(EX.S2))
|
||||
refute RDF.Data.equal?(graph |> Graph.delete_subjects(EX.S2), graph)
|
||||
refute RDF.Data.equal?(graph, graph |> Graph.delete_descriptions(EX.S2))
|
||||
refute RDF.Data.equal?(graph |> Graph.delete_descriptions(EX.S2), graph)
|
||||
refute RDF.Data.equal?(graph, description)
|
||||
refute RDF.Data.equal?(graph, dataset)
|
||||
end
|
||||
|
|
|
@ -577,7 +577,7 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "delete_subjects/2" do
|
||||
describe "delete_descriptions/2" do
|
||||
setup do
|
||||
{:ok,
|
||||
graph1: Graph.new({EX.S, EX.p(), [EX.O1, EX.O2]}, name: EX.Graph),
|
||||
|
@ -590,13 +590,13 @@ defmodule RDF.GraphTest do
|
|||
end
|
||||
|
||||
test "a single subject", %{graph1: graph1} do
|
||||
assert Graph.delete_subjects(graph1, EX.Other) == graph1
|
||||
assert Graph.delete_subjects(graph1, EX.S) == Graph.new(name: EX.Graph)
|
||||
assert Graph.delete_descriptions(graph1, EX.Other) == graph1
|
||||
assert Graph.delete_descriptions(graph1, EX.S) == Graph.new(name: EX.Graph)
|
||||
end
|
||||
|
||||
test "a list of subjects", %{graph1: graph1, graph2: graph2} do
|
||||
assert Graph.delete_subjects(graph1, [EX.S, EX.Other]) == Graph.new(name: EX.Graph)
|
||||
assert Graph.delete_subjects(graph2, [EX.S1, EX.S2, EX.S3]) == Graph.new()
|
||||
assert Graph.delete_descriptions(graph1, [EX.S, EX.Other]) == Graph.new(name: EX.Graph)
|
||||
assert Graph.delete_descriptions(graph2, [EX.S1, EX.S2, EX.S3]) == Graph.new()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue