diff --git a/lib/rdf/literal/datatype/registry.ex b/lib/rdf/literal/datatype/registry.ex index 6fb00b2..c055d8a 100644 --- a/lib/rdf/literal/datatype/registry.ex +++ b/lib/rdf/literal/datatype/registry.ex @@ -1,7 +1,7 @@ defmodule RDF.Literal.Datatype.Registry do @moduledoc false - alias RDF.{Literal, IRI, XSD} + alias RDF.{Literal, IRI, XSD, Namespace} alias RDF.Literal.Datatype.Registry.Registration import RDF.Guards @@ -46,15 +46,9 @@ defmodule RDF.Literal.Datatype.Registry do """ @spec get(Literal.t | IRI.t | String.t) :: Literal.Datatype.t def get(%Literal{} = literal), do: Literal.datatype(literal) - def get(id) when is_binary(id), do: id |> IRI.new() |> get() - def get(id) when maybe_ns_term(id), do: id |> IRI.new() |> get() - def get(id), do: @mapping[id] || get_custom_datatype(id) - - defp get_custom_datatype(id) do - id - |> to_string() - |> Registration.datatype() - end + def get(%IRI{} = id), do: id |> to_string() |> get() + def get(id) when maybe_ns_term(id), do: id |> Namespace.resolve_term!() |> get() + def get(id) when is_binary(id), do: Registration.datatype(id) defp implements_datatype_behaviour?(module) do module.module_info[:attributes] diff --git a/lib/rdf/literal/datatypes/lang_string.ex b/lib/rdf/literal/datatypes/lang_string.ex index 8d601b2..6759ca8 100644 --- a/lib/rdf/literal/datatypes/lang_string.ex +++ b/lib/rdf/literal/datatypes/lang_string.ex @@ -7,8 +7,7 @@ defmodule RDF.LangString do use RDF.Literal.Datatype, name: "langString", - id: RDF.Utils.Bootstrapping.rdf_iri("langString"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.rdf_iri("langString") alias RDF.Literal.Datatype alias RDF.Literal diff --git a/lib/rdf/xsd/datatypes/any_uri.ex b/lib/rdf/xsd/datatypes/any_uri.ex index 3943cb0..d1e15ff 100644 --- a/lib/rdf/xsd/datatypes/any_uri.ex +++ b/lib/rdf/xsd/datatypes/any_uri.ex @@ -11,8 +11,7 @@ defmodule RDF.XSD.AnyURI do use RDF.XSD.Datatype.Primitive, name: "anyURI", - id: RDF.Utils.Bootstrapping.xsd_iri("anyURI"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("anyURI") @impl RDF.XSD.Datatype @spec lexical_mapping(String.t(), Keyword.t()) :: valid_value diff --git a/lib/rdf/xsd/datatypes/boolean.ex b/lib/rdf/xsd/datatypes/boolean.ex index 740e6c3..6e012f1 100644 --- a/lib/rdf/xsd/datatypes/boolean.ex +++ b/lib/rdf/xsd/datatypes/boolean.ex @@ -8,8 +8,7 @@ defmodule RDF.XSD.Boolean do use RDF.XSD.Datatype.Primitive, name: "boolean", - id: RDF.Utils.Bootstrapping.xsd_iri("boolean"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("boolean") @impl RDF.XSD.Datatype def lexical_mapping(lexical, _) do diff --git a/lib/rdf/xsd/datatypes/byte.ex b/lib/rdf/xsd/datatypes/byte.ex index e63a46e..b1e4a8d 100644 --- a/lib/rdf/xsd/datatypes/byte.ex +++ b/lib/rdf/xsd/datatypes/byte.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.Byte do use RDF.XSD.Datatype.Restriction, name: "byte", id: RDF.Utils.Bootstrapping.xsd_iri("byte"), - base: RDF.XSD.Short, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Short def_facet_constraint RDF.XSD.Facets.MinInclusive, -128 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 127 diff --git a/lib/rdf/xsd/datatypes/date.ex b/lib/rdf/xsd/datatypes/date.ex index 803931b..95b94d1 100644 --- a/lib/rdf/xsd/datatypes/date.ex +++ b/lib/rdf/xsd/datatypes/date.ex @@ -11,8 +11,7 @@ defmodule RDF.XSD.Date do use RDF.XSD.Datatype.Primitive, name: "date", - id: RDF.Utils.Bootstrapping.xsd_iri("date"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("date") # TODO: Are GMT/UTC actually allowed? Maybe because it is supported by Elixir's Datetime ... diff --git a/lib/rdf/xsd/datatypes/date_time.ex b/lib/rdf/xsd/datatypes/date_time.ex index efe2a17..e49f501 100644 --- a/lib/rdf/xsd/datatypes/date_time.ex +++ b/lib/rdf/xsd/datatypes/date_time.ex @@ -7,8 +7,7 @@ defmodule RDF.XSD.DateTime do use RDF.XSD.Datatype.Primitive, name: "dateTime", - id: RDF.Utils.Bootstrapping.xsd_iri("dateTime"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("dateTime") @impl RDF.XSD.Datatype def lexical_mapping(lexical, opts) do diff --git a/lib/rdf/xsd/datatypes/decimal.ex b/lib/rdf/xsd/datatypes/decimal.ex index 60c1b5e..835ec07 100644 --- a/lib/rdf/xsd/datatypes/decimal.ex +++ b/lib/rdf/xsd/datatypes/decimal.ex @@ -7,8 +7,7 @@ defmodule RDF.XSD.Decimal do use RDF.XSD.Datatype.Primitive, name: "decimal", - id: RDF.Utils.Bootstrapping.xsd_iri("decimal"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("decimal") alias Elixir.Decimal, as: D diff --git a/lib/rdf/xsd/datatypes/double.ex b/lib/rdf/xsd/datatypes/double.ex index f54f896..b7861c7 100644 --- a/lib/rdf/xsd/datatypes/double.ex +++ b/lib/rdf/xsd/datatypes/double.ex @@ -8,8 +8,7 @@ defmodule RDF.XSD.Double do use RDF.XSD.Datatype.Primitive, name: "double", - id: RDF.Utils.Bootstrapping.xsd_iri("double"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("double") @special_values ~W[positive_infinity negative_infinity nan]a diff --git a/lib/rdf/xsd/datatypes/float.ex b/lib/rdf/xsd/datatypes/float.ex index 7c0fcc0..6e3108a 100644 --- a/lib/rdf/xsd/datatypes/float.ex +++ b/lib/rdf/xsd/datatypes/float.ex @@ -9,6 +9,5 @@ defmodule RDF.XSD.Float do use RDF.XSD.Datatype.Restriction, name: "float", id: RDF.Utils.Bootstrapping.xsd_iri("float"), - base: RDF.XSD.Double, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Double end diff --git a/lib/rdf/xsd/datatypes/int.ex b/lib/rdf/xsd/datatypes/int.ex index 6f3fbb5..1844084 100644 --- a/lib/rdf/xsd/datatypes/int.ex +++ b/lib/rdf/xsd/datatypes/int.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.Int do use RDF.XSD.Datatype.Restriction, name: "int", id: RDF.Utils.Bootstrapping.xsd_iri("int"), - base: RDF.XSD.Long, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Long def_facet_constraint RDF.XSD.Facets.MinInclusive, -2_147_483_648 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 2_147_483_647 diff --git a/lib/rdf/xsd/datatypes/integer.ex b/lib/rdf/xsd/datatypes/integer.ex index 4078bad..05e8135 100644 --- a/lib/rdf/xsd/datatypes/integer.ex +++ b/lib/rdf/xsd/datatypes/integer.ex @@ -10,8 +10,7 @@ defmodule RDF.XSD.Integer do use RDF.XSD.Datatype.Primitive, name: "integer", - id: RDF.Utils.Bootstrapping.xsd_iri("integer"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("integer") def_applicable_facet RDF.XSD.Facets.MinInclusive def_applicable_facet RDF.XSD.Facets.MaxInclusive diff --git a/lib/rdf/xsd/datatypes/long.ex b/lib/rdf/xsd/datatypes/long.ex index f3094fa..fc6617b 100644 --- a/lib/rdf/xsd/datatypes/long.ex +++ b/lib/rdf/xsd/datatypes/long.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.Long do use RDF.XSD.Datatype.Restriction, name: "long", id: RDF.Utils.Bootstrapping.xsd_iri("long"), - base: RDF.XSD.Integer, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Integer def_facet_constraint RDF.XSD.Facets.MinInclusive, -9_223_372_036_854_775_808 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 9_223_372_036_854_775_807 diff --git a/lib/rdf/xsd/datatypes/negative_integer.ex b/lib/rdf/xsd/datatypes/negative_integer.ex index 2f934a7..4bb0c4f 100644 --- a/lib/rdf/xsd/datatypes/negative_integer.ex +++ b/lib/rdf/xsd/datatypes/negative_integer.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.NegativeInteger do use RDF.XSD.Datatype.Restriction, name: "negativeInteger", id: RDF.Utils.Bootstrapping.xsd_iri("negativeInteger"), - base: RDF.XSD.NonPositiveInteger, - register: false # core datatypes don't need to be registered + base: RDF.XSD.NonPositiveInteger def_facet_constraint RDF.XSD.Facets.MaxInclusive, -1 end diff --git a/lib/rdf/xsd/datatypes/non_negative_integer.ex b/lib/rdf/xsd/datatypes/non_negative_integer.ex index 547ddca..3129cdf 100644 --- a/lib/rdf/xsd/datatypes/non_negative_integer.ex +++ b/lib/rdf/xsd/datatypes/non_negative_integer.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.NonNegativeInteger do use RDF.XSD.Datatype.Restriction, name: "nonNegativeInteger", id: RDF.Utils.Bootstrapping.xsd_iri("nonNegativeInteger"), - base: RDF.XSD.Integer, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Integer def_facet_constraint RDF.XSD.Facets.MinInclusive, 0 end diff --git a/lib/rdf/xsd/datatypes/non_positive_integer.ex b/lib/rdf/xsd/datatypes/non_positive_integer.ex index 9206eb3..5048529 100644 --- a/lib/rdf/xsd/datatypes/non_positive_integer.ex +++ b/lib/rdf/xsd/datatypes/non_positive_integer.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.NonPositiveInteger do use RDF.XSD.Datatype.Restriction, name: "nonPositiveInteger", id: RDF.Utils.Bootstrapping.xsd_iri("nonPositiveInteger"), - base: RDF.XSD.Integer, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Integer def_facet_constraint RDF.XSD.Facets.MaxInclusive, 0 end diff --git a/lib/rdf/xsd/datatypes/positive_integer.ex b/lib/rdf/xsd/datatypes/positive_integer.ex index dcb5c18..1b8117f 100644 --- a/lib/rdf/xsd/datatypes/positive_integer.ex +++ b/lib/rdf/xsd/datatypes/positive_integer.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.PositiveInteger do use RDF.XSD.Datatype.Restriction, name: "positiveInteger", id: RDF.Utils.Bootstrapping.xsd_iri("positiveInteger"), - base: RDF.XSD.NonNegativeInteger, - register: false # core datatypes don't need to be registered + base: RDF.XSD.NonNegativeInteger def_facet_constraint RDF.XSD.Facets.MinInclusive, 1 end diff --git a/lib/rdf/xsd/datatypes/short.ex b/lib/rdf/xsd/datatypes/short.ex index 1ea8a15..96df409 100644 --- a/lib/rdf/xsd/datatypes/short.ex +++ b/lib/rdf/xsd/datatypes/short.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.Short do use RDF.XSD.Datatype.Restriction, name: "short", id: RDF.Utils.Bootstrapping.xsd_iri("short"), - base: RDF.XSD.Int, - register: false # core datatypes don't need to be registered + base: RDF.XSD.Int def_facet_constraint RDF.XSD.Facets.MinInclusive, -32768 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 32767 diff --git a/lib/rdf/xsd/datatypes/string.ex b/lib/rdf/xsd/datatypes/string.ex index 3544dd0..aeeb8f3 100644 --- a/lib/rdf/xsd/datatypes/string.ex +++ b/lib/rdf/xsd/datatypes/string.ex @@ -7,8 +7,7 @@ defmodule RDF.XSD.String do use RDF.XSD.Datatype.Primitive, name: "string", - id: RDF.Utils.Bootstrapping.xsd_iri("string"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("string") @impl RDF.XSD.Datatype @spec lexical_mapping(String.t(), Keyword.t()) :: valid_value diff --git a/lib/rdf/xsd/datatypes/time.ex b/lib/rdf/xsd/datatypes/time.ex index a85ae3d..78d4ecc 100644 --- a/lib/rdf/xsd/datatypes/time.ex +++ b/lib/rdf/xsd/datatypes/time.ex @@ -7,8 +7,7 @@ defmodule RDF.XSD.Time do use RDF.XSD.Datatype.Primitive, name: "time", - id: RDF.Utils.Bootstrapping.xsd_iri("time"), - register: false # core datatypes don't need to be registered + id: RDF.Utils.Bootstrapping.xsd_iri("time") # TODO: Are GMT/UTC actually allowed? Maybe because it is supported by Elixir's Datetime ... @grammar ~r/\A(\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z/ diff --git a/lib/rdf/xsd/datatypes/unsigned_byte.ex b/lib/rdf/xsd/datatypes/unsigned_byte.ex index ece87f4..9742bd1 100644 --- a/lib/rdf/xsd/datatypes/unsigned_byte.ex +++ b/lib/rdf/xsd/datatypes/unsigned_byte.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.UnsignedByte do use RDF.XSD.Datatype.Restriction, name: "unsignedByte", id: RDF.Utils.Bootstrapping.xsd_iri("unsignedByte"), - base: RDF.XSD.UnsignedShort, - register: false # core datatypes don't need to be registered + base: RDF.XSD.UnsignedShort def_facet_constraint RDF.XSD.Facets.MinInclusive, 0 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 255 diff --git a/lib/rdf/xsd/datatypes/unsigned_int.ex b/lib/rdf/xsd/datatypes/unsigned_int.ex index 63d1ad1..5864444 100644 --- a/lib/rdf/xsd/datatypes/unsigned_int.ex +++ b/lib/rdf/xsd/datatypes/unsigned_int.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.UnsignedInt do use RDF.XSD.Datatype.Restriction, name: "unsignedInt", id: RDF.Utils.Bootstrapping.xsd_iri("unsignedInt"), - base: RDF.XSD.UnsignedLong, - register: false # core datatypes don't need to be registered + base: RDF.XSD.UnsignedLong def_facet_constraint RDF.XSD.Facets.MinInclusive, 0 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 4_294_967_295 diff --git a/lib/rdf/xsd/datatypes/unsigned_long.ex b/lib/rdf/xsd/datatypes/unsigned_long.ex index 9aed230..f7d0d8c 100644 --- a/lib/rdf/xsd/datatypes/unsigned_long.ex +++ b/lib/rdf/xsd/datatypes/unsigned_long.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.UnsignedLong do use RDF.XSD.Datatype.Restriction, name: "unsignedLong", id: RDF.Utils.Bootstrapping.xsd_iri("unsignedLong"), - base: RDF.XSD.NonNegativeInteger, - register: false # core datatypes don't need to be registered + base: RDF.XSD.NonNegativeInteger def_facet_constraint RDF.XSD.Facets.MinInclusive, 0 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 18_446_744_073_709_551_615 diff --git a/lib/rdf/xsd/datatypes/unsigned_short.ex b/lib/rdf/xsd/datatypes/unsigned_short.ex index cf8e84f..baa2d72 100644 --- a/lib/rdf/xsd/datatypes/unsigned_short.ex +++ b/lib/rdf/xsd/datatypes/unsigned_short.ex @@ -2,8 +2,7 @@ defmodule RDF.XSD.UnsignedShort do use RDF.XSD.Datatype.Restriction, name: "unsignedShort", id: RDF.Utils.Bootstrapping.xsd_iri("unsignedShort"), - base: RDF.XSD.UnsignedInt, - register: false # core datatypes don't need to be registered + base: RDF.XSD.UnsignedInt def_facet_constraint RDF.XSD.Facets.MinInclusive, 0 def_facet_constraint RDF.XSD.Facets.MaxInclusive, 65535 diff --git a/test/unit/literal/datatype/registry_test.exs b/test/unit/literal/datatype/registry_test.exs index 0e225d7..30e2345 100644 --- a/test/unit/literal/datatype/registry_test.exs +++ b/test/unit/literal/datatype/registry_test.exs @@ -66,11 +66,4 @@ defmodule RDF.Literal.Datatype.RegistryTest do assert Age == Datatype.Registry.get(EX.Age) end end - - test "core datatypes are handled differently and should not be registered (for performance reasons)" do - Enum.each(Datatype.Registry.core_datatypes(), fn datatype -> - refute Datatype.Registry.Registration.datatype(datatype.id) - refute Datatype.Registry.Registration.datatype(to_string(datatype.id)) - end) - end end