Add support for PropertyMap on RDF.Statement.new/2 and coerce/2
This commit is contained in:
parent
266ca1f159
commit
737b67095d
3 changed files with 26 additions and 12 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -5,6 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
[Keep a CHANGELOG](http://keepachangelog.com).
|
||||
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- support for `RDF.PropertyMap` on `RDF.Statement.new/2` and `RDF.Statement.coerce/2`
|
||||
|
||||
|
||||
[Compare v0.9.4...HEAD](https://github.com/rdf-elixir/rdf-ex/compare/v0.9.4...HEAD)
|
||||
|
||||
|
||||
|
||||
## 0.9.4 - 2021-05-26
|
||||
|
||||
### Added
|
||||
|
|
10
lib/rdf.ex
10
lib/rdf.ex
|
@ -243,15 +243,15 @@ defmodule RDF do
|
|||
defdelegate literal(value), to: Literal, as: :new
|
||||
defdelegate literal(value, opts), to: Literal, as: :new
|
||||
|
||||
defdelegate triple(s, p, o), to: Triple, as: :new
|
||||
defdelegate triple(tuple), to: Triple, as: :new
|
||||
defdelegate triple(s, p, o, property_map \\ nil), to: Triple, as: :new
|
||||
defdelegate triple(tuple, property_map \\ nil), to: Triple, as: :new
|
||||
|
||||
defdelegate quad(s, p, o, g), to: Quad, as: :new
|
||||
defdelegate quad(tuple), to: Quad, as: :new
|
||||
defdelegate quad(s, p, o, g, property_map \\ nil), to: Quad, as: :new
|
||||
defdelegate quad(tuple, property_map \\ nil), to: Quad, as: :new
|
||||
|
||||
defdelegate statement(s, p, o), to: Statement, as: :new
|
||||
defdelegate statement(s, p, o, g), to: Statement, as: :new
|
||||
defdelegate statement(tuple), to: Statement, as: :new
|
||||
defdelegate statement(tuple, property_map \\ nil), to: Statement, as: :new
|
||||
|
||||
defdelegate description(subject, opts \\ []), to: Description, as: :new
|
||||
|
||||
|
|
|
@ -41,10 +41,13 @@ defmodule RDF.Statement do
|
|||
|
||||
iex> RDF.Statement.new({EX.S, EX.p, 42, EX.Graph})
|
||||
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
|
||||
|
||||
iex> RDF.Statement.new({EX.S, :p, 42, EX.Graph}, RDF.PropertyMap.new(p: EX.p))
|
||||
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42), RDF.iri("http://example.com/Graph")}
|
||||
"""
|
||||
def new(tuple)
|
||||
def new({_, _, _} = tuple), do: Triple.new(tuple)
|
||||
def new({_, _, _, _} = tuple), do: Quad.new(tuple)
|
||||
def new(tuple, property_map \\ nil)
|
||||
def new({_, _, _} = tuple, property_map), do: Triple.new(tuple, property_map)
|
||||
def new({_, _, _, _} = tuple, property_map), do: Quad.new(tuple, property_map)
|
||||
|
||||
defdelegate new(s, p, o), to: Triple, as: :new
|
||||
defdelegate new(s, p, o, g), to: Quad, as: :new
|
||||
|
@ -61,10 +64,10 @@ defmodule RDF.Statement do
|
|||
iex> RDF.Statement.coerce {"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
|
||||
{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42), ~I<http://example.com/Graph>}
|
||||
"""
|
||||
@spec coerce(coercible_t()) :: Triple.t() | Quad.t()
|
||||
def coerce(statement)
|
||||
def coerce({_, _, _} = triple), do: Triple.new(triple)
|
||||
def coerce({_, _, _, _} = quad), do: Quad.new(quad)
|
||||
@spec coerce(coercible_t(), PropertyMap.t() | nil) :: Triple.t() | Quad.t()
|
||||
def coerce(statement, property_map \\ nil)
|
||||
def coerce({_, _, _} = triple, property_map), do: Triple.new(triple, property_map)
|
||||
def coerce({_, _, _, _} = quad, property_map), do: Quad.new(quad, property_map)
|
||||
|
||||
@doc false
|
||||
@spec coerce_subject(coercible_subject) :: subject
|
||||
|
|
Loading…
Reference in a new issue