Optimize handling of descriptions in RDF.Description.include?/2
This commit is contained in:
parent
08a97ff2dc
commit
d815200b4a
1 changed files with 21 additions and 4 deletions
|
@ -610,10 +610,6 @@ defmodule RDF.Description do
|
|||
@spec include?(t, input) :: boolean
|
||||
def include?(description, input)
|
||||
|
||||
def include?(description, predications) when is_map(predications) or is_list(predications) do
|
||||
Enum.all?(predications, fn predication -> include?(description, predication) end)
|
||||
end
|
||||
|
||||
def include?(%__MODULE__{} = description, {subject, predicate, objects}) do
|
||||
coerce_subject(subject) == description.subject &&
|
||||
include?(description, {predicate, objects})
|
||||
|
@ -634,6 +630,27 @@ defmodule RDF.Description do
|
|||
end
|
||||
end
|
||||
|
||||
def include?(
|
||||
%__MODULE__{subject: subject, predications: predications},
|
||||
%__MODULE__{subject: subject} = input
|
||||
) do
|
||||
Enum.all?(input.predications, fn {predicate, objects} ->
|
||||
if existing_objects = predications[predicate] do
|
||||
Enum.all?(objects, fn {object, _} ->
|
||||
Map.has_key?(existing_objects, object)
|
||||
end)
|
||||
else
|
||||
false
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def include?(%__MODULE__{}, %__MODULE__{}), do: false
|
||||
|
||||
def include?(description, predications) when is_map(predications) or is_list(predications) do
|
||||
Enum.all?(predications, fn predication -> include?(description, predication) end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks if a `RDF.Description` has the given resource as subject.
|
||||
|
||||
|
|
Loading…
Reference in a new issue