Fix RDF.Graph.put/2 to ignore empty RDF.Descriptions
This commit is contained in:
parent
f83ac494fc
commit
96bb678ffc
3 changed files with 25 additions and 4 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -23,10 +23,16 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
|
||||
### Changed
|
||||
|
||||
- `RDF.Description.new` now requires the `subject` to be passed always as first argument;
|
||||
if you want to add some initial data this must be done with the `:init` option
|
||||
- for consistency reasons the internal `:id` struct field of `RDF.BlankNode` was renamed
|
||||
to `:value`
|
||||
- `RDF.Description.new` now requires the `subject` to be passed always as first argument;
|
||||
if you want to add some initial data this must be done with the `:init` option
|
||||
|
||||
### Fixed
|
||||
|
||||
- `RDF.Graph.put/2` ignores empty descriptions; this should be the final piece to ensure
|
||||
that `RDF.Graph`s never contain empty descriptions, which would distort results of
|
||||
functions like `RDF.Graph.subjects/1`, `RDF.Graph.subject_count/1`, `RDF.Graph.descriptions/1`
|
||||
|
||||
|
||||
[Compare v0.8.2...HEAD](https://github.com/rdf-elixir/rdf-ex/compare/v0.8.2...HEAD)
|
||||
|
|
|
@ -250,8 +250,13 @@ defmodule RDF.Graph do
|
|||
def put(graph, {subject, predicate, object, _}),
|
||||
do: put(graph, {subject, predicate, object})
|
||||
|
||||
def put(%__MODULE__{} = graph, %Description{subject: subject} = description),
|
||||
do: do_put(graph, subject, description)
|
||||
def put(%__MODULE__{} = graph, %Description{subject: subject} = description) do
|
||||
if Description.count(description) > 0 do
|
||||
do_put(graph, subject, description)
|
||||
else
|
||||
graph
|
||||
end
|
||||
end
|
||||
|
||||
def put(graph, %__MODULE__{descriptions: descriptions, prefixes: prefixes}) do
|
||||
graph =
|
||||
|
|
|
@ -244,6 +244,11 @@ defmodule RDF.GraphTest do
|
|||
assert graph_includes_statement?(g, {EX.Subject1, EX.predicate3(), EX.Object3})
|
||||
end
|
||||
|
||||
test "an empty description is ignored" do
|
||||
g = Graph.new() |> Graph.add(Description.new(EX.Subject))
|
||||
assert empty_graph?(g)
|
||||
end
|
||||
|
||||
test "a list of descriptions" do
|
||||
g =
|
||||
Graph.add(graph(), [
|
||||
|
@ -402,6 +407,11 @@ defmodule RDF.GraphTest do
|
|||
assert graph_includes_statement?(g, {EX.S2, EX.P2, EX.O2})
|
||||
end
|
||||
|
||||
test "an empty description is ignored" do
|
||||
g = Graph.new() |> Graph.put(Description.new(EX.Subject))
|
||||
assert empty_graph?(g)
|
||||
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}])
|
||||
|
|
Loading…
Reference in a new issue