diff --git a/CHANGELOG.md b/CHANGELOG.md index d841115..eaba01a 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/rdf.ex b/lib/rdf.ex index 6b5cbd9..3381dcf 100644 --- a/lib/rdf.ex +++ b/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 diff --git a/lib/rdf/statement.ex b/lib/rdf/statement.ex index 9376a85..1de8a2a 100644 --- a/lib/rdf/statement.ex +++ b/lib/rdf/statement.ex @@ -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, ~I, RDF.literal(42), ~I} """ - @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