Various changes of types

This commit is contained in:
Marcel Otto 2022-03-13 21:39:48 +01:00
parent 62f3df7dcb
commit e357686f88
12 changed files with 48 additions and 35 deletions

View file

@ -13,8 +13,17 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- `:implicit_base` option on the `RDF.Turtle.Encoder`
- `:base_description` option on the `RDF.Turtle.Encoder`
- `RDF.Resource.t` type
- `RDF.Triple.coercible_t`, `RDF.Quad.coercible_t`, `RDF.Star.Triple.coercible_t`
and `RDF.Star.Quad.coercible_t` types
- `RDF.Triple.coercible`, `RDF.Quad.coercible`, `RDF.Star.Triple.coercible`
and `RDF.Star.Quad.coercible` types
### Changed
- some types were renamed for consistency reasons; the old types were deprecated
and will be removed in v0.11
- `RDF.Statement.coercible_t` -> `RDF.Statement.coercible`
- `RDF.Star.Statement.coercible_t` -> `RDF.Star.Statement.coercible`
- `RDF.Triple.t_values` -> `RDF.Triple.mapping_value`
- `RDF.Quad.t_values` -> `RDF.Quad.mapping_value`
### Fixed

View file

@ -10,9 +10,7 @@ defmodule RDF.BlankNode do
and <https://www.w3.org/TR/rdf11-concepts/#section-blank-nodes>
"""
@type t :: %__MODULE__{
value: String.t()
}
@type t :: %__MODULE__{value: String.t()}
@enforce_keys [:value]
defstruct [:value]

View file

@ -26,7 +26,7 @@ defmodule RDF.Description do
@type predications :: %{Statement.predicate() => %{Statement.object() => nil}}
@type input ::
Statement.coercible_t()
Statement.coercible()
| {
Statement.coercible_predicate(),
Statement.coercible_object() | [Statement.coercible_object()]
@ -36,7 +36,7 @@ defmodule RDF.Description do
Statement.coercible_object() | [Statement.coercible_object()]
}
| [
Statement.coercible_t()
Statement.coercible()
| {
Statement.coercible_predicate(),
Statement.coercible_object() | [Statement.coercible_object()]

View file

@ -30,7 +30,7 @@ defmodule RDF.Graph do
}
@type input ::
Statement.coercible_t()
Statement.coercible()
| {
Statement.coercible_subject(),
Description.input()

View file

@ -19,9 +19,7 @@ defmodule RDF.IRI do
alias RDF.Namespace
import RDF.Guards
@type t :: %__MODULE__{
value: String.t()
}
@type t :: %__MODULE__{value: String.t()}
@type coercible :: String.t() | URI.t() | module | t

View file

@ -15,7 +15,7 @@ defmodule RDF.Quad do
Statement.graph_name()
}
@type coercible_t ::
@type coercible ::
{
Statement.coercible_subject(),
Statement.coercible_predicate(),
@ -23,7 +23,9 @@ defmodule RDF.Quad do
Statement.coercible_graph_name()
}
@type t_values :: {String.t(), String.t(), any, String.t()}
@type mapping_value :: {String.t(), String.t(), any, String.t()}
# deprecated: This will be removed in v0.11.
@type t_values :: mapping_value
@doc """
Creates a `RDF.Quad` with proper RDF values.
@ -91,7 +93,7 @@ defmodule RDF.Quad do
iex> RDF.Quad.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")}
"""
@spec new(Statement.coercible_t(), PropertyMap.t() | nil) :: t
@spec new(Statement.coercible(), PropertyMap.t() | nil) :: t
def new(statement, property_map \\ nil)
def new({subject, predicate, object, graph_name}, property_map) do
@ -120,7 +122,7 @@ defmodule RDF.Quad do
{"http://example.com/S", :p, 42, "http://example.com/Graph"}
"""
@spec values(t, keyword) :: t_values | nil
@spec values(t, keyword) :: mapping_value | nil
def values(quad, opts \\ []) do
if property_map = PropertyMap.from_opts(opts) do
map(quad, Statement.default_property_mapping(property_map))
@ -154,7 +156,7 @@ defmodule RDF.Quad do
{:S, :p, 42, ~I<http://example.com/Graph>}
"""
@spec map(t, Statement.term_mapping()) :: t_values | nil
@spec map(t, Statement.term_mapping()) :: mapping_value | nil
def map({subject, predicate, object, graph_name}, fun) do
with subject_value when not is_nil(subject_value) <- fun.({:subject, subject}),
predicate_value when not is_nil(predicate_value) <- fun.({:predicate, predicate}),

View file

@ -6,4 +6,6 @@ defmodule RDF.Resource do
alias RDF.{IRI, BlankNode}
@type t :: IRI.t() | BlankNode.t()
@type coercible :: IRI.coercible() | BlankNode.t()
end

View file

@ -17,7 +17,7 @@ defmodule RDF.Star.Quad do
Statement.graph_name()
}
@type coercible_t ::
@type coercible ::
{
Statement.coercible_subject(),
Statement.coercible_predicate(),
@ -25,8 +25,6 @@ defmodule RDF.Star.Quad do
Statement.coercible_graph_name()
}
@type t_values :: {String.t(), String.t(), any, String.t()}
@doc """
Creates a `RDF.Star.Quad` with proper RDF-star values.
@ -104,7 +102,7 @@ defmodule RDF.Star.Quad do
{{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43), ~I<http://example.com/Graph>}
"""
@spec new(Statement.coercible_t(), PropertyMap.t() | nil) :: t
@spec new(Statement.coercible(), PropertyMap.t() | nil) :: t
def new(statement, property_map \\ nil)
def new({subject, predicate, object, graph_name}, property_map) do

View file

@ -19,7 +19,9 @@ defmodule RDF.Star.Statement do
@type coercible_graph_name :: RDF.Statement.coercible_graph_name()
@type t :: Triple.t() | Quad.t()
@type coercible_t :: Triple.coercible_t() | Quad.coercible_t()
@type coercible :: Triple.coercible() | Quad.coercible()
# deprecated: This will be removed in v0.11.
@type coercible_t :: coercible
@type term_mapping :: RDF.Statement.term_mapping()
@ -60,7 +62,7 @@ defmodule RDF.Star.Statement do
iex> RDF.Star.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(), PropertyMap.t() | nil) :: Triple.t() | Quad.t()
@spec coerce(coercible(), 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)

View file

@ -12,7 +12,7 @@ defmodule RDF.Star.Triple do
@type t :: {Statement.subject(), Statement.predicate(), Statement.object()}
@type coercible_t ::
@type coercible ::
{
Statement.coercible_subject(),
Statement.coercible_predicate(),
@ -88,7 +88,7 @@ defmodule RDF.Star.Triple do
iex> RDF.Star.Triple.new({{EX.S, :p, 42}, :p2, 43}, RDF.PropertyMap.new(p: EX.p, p2: EX.p2))
{{~I<http://example.com/S>, ~I<http://example.com/p>, RDF.literal(42)}, ~I<http://example.com/p2>, RDF.literal(43)}
"""
@spec new(Statement.coercible_t(), PropertyMap.t() | nil) :: t
@spec new(Statement.coercible(), PropertyMap.t() | nil) :: t
def new(statement, property_map \\ nil)
def new({subject, predicate, object}, property_map),

View file

@ -13,8 +13,8 @@ defmodule RDF.Statement do
@type object :: Resource.t() | Literal.t()
@type graph_name :: Resource.t() | nil
@type coercible_subject :: subject | atom | String.t()
@type coercible_predicate :: predicate | atom | String.t()
@type coercible_subject :: Resource.coercible()
@type coercible_predicate :: Resource.coercible()
@type coercible_object :: object | any
@type coercible_graph_name :: graph_name | atom | String.t()
@ -23,7 +23,9 @@ defmodule RDF.Statement do
@type term_mapping :: (qualified_term -> any | nil)
@type t :: Triple.t() | Quad.t()
@type coercible_t :: Triple.coercible_t() | Quad.coercible_t()
@type coercible :: Triple.coercible() | Quad.coercible()
# deprecated: This will be removed in v0.11.
@type coercible_t :: coercible
@doc """
Creates a `RDF.Triple` or `RDF.Quad` with proper RDF values.
@ -62,7 +64,7 @@ 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(), PropertyMap.t() | nil) :: Triple.t() | Quad.t()
@spec coerce(coercible(), 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)
@ -140,7 +142,7 @@ defmodule RDF.Statement do
{"http://example.com/S", :p, 42}
"""
@spec values(t, keyword) :: Triple.t_values() | Quad.t_values() | nil
@spec values(t, keyword) :: Triple.mapping_value() | Quad.mapping_value() | nil
def values(quad, opts \\ [])
def values({_, _, _} = triple, opts), do: Triple.values(triple, opts)
def values({_, _, _, _} = quad, opts), do: Quad.values(quad, opts)
@ -173,7 +175,7 @@ defmodule RDF.Statement do
{"S", :p, 42, ~I<http://example.com/Graph>}
"""
@spec map(t, term_mapping()) :: Triple.t_values() | Quad.t_values() | nil | nil
@spec map(t, term_mapping()) :: Triple.mapping_value() | Quad.mapping_value() | nil | nil
def map(statement, fun)
def map({_, _, _} = triple, fun), do: RDF.Triple.map(triple, fun)
def map({_, _, _, _} = quad, fun), do: RDF.Quad.map(quad, fun)

View file

@ -10,14 +10,16 @@ defmodule RDF.Triple do
@type t :: {Statement.subject(), Statement.predicate(), Statement.object()}
@type coercible_t ::
@type coercible ::
{
Statement.coercible_subject(),
Statement.coercible_predicate(),
Statement.coercible_object()
}
@type t_values :: {String.t(), String.t(), any}
@type mapping_value :: {String.t(), String.t(), any}
# deprecated: This will be removed in v0.11.
@type t_values :: mapping_value
@doc """
Creates a `RDF.Triple` with proper RDF values.
@ -82,7 +84,7 @@ defmodule RDF.Triple do
iex> RDF.Triple.new {EX.S, :p, 42}, RDF.PropertyMap.new(p: EX.p)
{RDF.iri("http://example.com/S"), RDF.iri("http://example.com/p"), RDF.literal(42)}
"""
@spec new(Statement.coercible_t(), PropertyMap.t() | nil) :: t
@spec new(Statement.coercible(), PropertyMap.t() | nil) :: t
def new(statement, property_map \\ nil)
def new({subject, predicate, object}, property_map),
@ -109,7 +111,7 @@ defmodule RDF.Triple do
{"http://example.com/S", :p, 42}
"""
@spec values(t, keyword) :: t_values | nil
@spec values(t, keyword) :: mapping_value | nil
def values(triple, opts \\ []) do
if property_map = PropertyMap.from_opts(opts) do
map(triple, Statement.default_property_mapping(property_map))
@ -139,7 +141,7 @@ defmodule RDF.Triple do
{"S", "p", 42}
"""
@spec map(t, Statement.term_mapping()) :: t_values | nil
@spec map(t, Statement.term_mapping()) :: mapping_value | nil
def map({subject, predicate, object}, fun) do
with subject_value when not is_nil(subject_value) <- fun.({:subject, subject}),
predicate_value when not is_nil(predicate_value) <- fun.({:predicate, predicate}),