Skip to content
Permalink
Browse files

Add RDF.Description.take/2

  • Loading branch information
marcelotto committed Oct 14, 2019
1 parent 9e81f69 commit cf568dd06eb4b346ddcafc9b6f77b87b12d32dde
Showing with 28 additions and 1 deletion.
  1. +13 −0 CHANGELOG.md
  2. +9 −0 lib/rdf/description.ex
  3. +6 −1 test/unit/description_test.exs
@@ -5,6 +5,19 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
[Keep a CHANGELOG](http://keepachangelog.com).


## Unreleased

### Added

- `RDF.Description.take/2` creates a description from another one by limiting
its statements to a set of predicates
- Mix formatter configuration for using `defvocab` without parens


[Compare v0.6.2...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.6.2...HEAD)



## 0.6.2 - 2019-09-08

### Added
@@ -616,6 +616,15 @@ defmodule RDF.Description do
end
end

@doc """
Creates a description from another one by limiting its statements to those using one of the given `predicates`.
If `predicates` contains properties that are not used in the `description`, they're simply ignored.
"""
def take(%RDF.Description{predications: predications} = description, predicates) do
predicates = Enum.map(predicates, &(coerce_predicate/1))
%RDF.Description{description | predications: Map.take(predications, predicates)}
end

@doc """
Checks if two `RDF.Description`s are equal.
@@ -144,7 +144,6 @@ defmodule RDF.DescriptionTest do
refute description_includes_predication(desc, {EX.predicate, iri(EX.Object3)})
end


test "another description" do
desc = description([{EX.predicate1, EX.Object1}, {EX.predicate2, EX.Object2}])
|> Description.add(Description.new({EX.Other, EX.predicate3, EX.Object3}))
@@ -358,6 +357,12 @@ defmodule RDF.DescriptionTest do
%{p: ["Foo"]}
end

test "take/2" do
assert Description.new([{EX.S, EX.p1, EX.O1}, {EX.S, EX.p2, EX.O2}])
|> Description.take([EX.p2, EX.p3]) ==
Description.new({EX.S, EX.p2, EX.O2})
end

test "equal/2" do
assert Description.new({EX.S, EX.p, EX.O}) |> Description.equal?(Description.new({EX.S, EX.p, EX.O}))
refute Description.new({EX.S, EX.p, EX.O}) |> Description.equal?(Description.new({EX.S, EX.p, EX.O2}))

0 comments on commit cf568dd

Please sign in to comment.
You can’t perform that action at this time.