Upgrade to RDF.ex 0.3
This commit is contained in:
parent
8410f4b747
commit
038b170b5b
12 changed files with 40 additions and 44 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -5,6 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
[Keep a CHANGELOG](http://keepachangelog.com).
|
||||
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade to RDF.ex 0.3
|
||||
|
||||
|
||||
[Compare v0.1.0...HEAD](https://github.com/marcelotto/jsonld-ex/compare/v0.1.0...HEAD)
|
||||
|
||||
|
||||
|
||||
## 0.1.1 - 2017-08-06
|
||||
|
||||
### Changed
|
||||
|
@ -15,6 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
[Compare v0.1.0...v0.1.1](https://github.com/marcelotto/jsonld-ex/compare/v0.1.0...v0.1.1)
|
||||
|
||||
|
||||
|
||||
## 0.1.0 - 2017-06-25
|
||||
|
||||
Initial release
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.1.1
|
||||
0.2.0-dev
|
||||
|
|
|
@ -9,6 +9,7 @@ defmodule JSON.LD.Context do
|
|||
import JSON.LD.Utils
|
||||
|
||||
alias JSON.LD.Context.TermDefinition
|
||||
alias RDF.IRI
|
||||
|
||||
|
||||
def base(%JSON.LD.Context{base_iri: false, api_base_iri: api_base_iri}),
|
||||
|
@ -74,7 +75,7 @@ defmodule JSON.LD.Context do
|
|||
defp set_base(active, base, _) do
|
||||
cond do
|
||||
# TODO: this slightly differs from the spec, due to our false special value for base_iri; add more tests
|
||||
is_nil(base) or absolute_iri?(base) ->
|
||||
is_nil(base) or IRI.absolute?(base) ->
|
||||
%JSON.LD.Context{active | base_iri: base}
|
||||
active.base_iri ->
|
||||
%JSON.LD.Context{active | base_iri: absolute_iri(base, active.base_iri)}
|
||||
|
@ -86,7 +87,7 @@ defmodule JSON.LD.Context do
|
|||
|
||||
defp set_vocab(active, false), do: active
|
||||
defp set_vocab(active, vocab) do
|
||||
if is_nil(vocab) or absolute_iri?(vocab) or blank_node_id?(vocab) do
|
||||
if is_nil(vocab) or IRI.absolute?(vocab) or blank_node_id?(vocab) do
|
||||
%JSON.LD.Context{active | vocab: vocab}
|
||||
else
|
||||
raise JSON.LD.InvalidVocabMappingError,
|
||||
|
@ -190,7 +191,7 @@ defmodule JSON.LD.Context do
|
|||
defp do_create_type_definition(definition, active, local, %{"@type" => type}, defined) do
|
||||
{expanded_type, active, defined} =
|
||||
expand_iri(type, active, false, true, local, defined)
|
||||
if absolute_iri?(expanded_type) or expanded_type in ~w[@id @vocab] do
|
||||
if IRI.absolute?(expanded_type) or expanded_type in ~w[@id @vocab] do
|
||||
{%TermDefinition{definition | type_mapping: expanded_type}, active, defined}
|
||||
else
|
||||
raise JSON.LD.InvalidTypeMappingError,
|
||||
|
@ -214,7 +215,7 @@ defmodule JSON.LD.Context do
|
|||
true -> # 11.3)
|
||||
{expanded_reverse, active, defined} =
|
||||
expand_iri(reverse, active, false, true, local, defined)
|
||||
if absolute_iri?(expanded_reverse) or blank_node_id?(expanded_reverse) do
|
||||
if IRI.absolute?(expanded_reverse) or blank_node_id?(expanded_reverse) do
|
||||
definition = %TermDefinition{definition | iri_mapping: expanded_reverse}
|
||||
else
|
||||
raise JSON.LD.InvalidIRIMappingError,
|
||||
|
@ -249,7 +250,7 @@ defmodule JSON.LD.Context do
|
|||
raise JSON.LD.InvalidKeywordAliasError,
|
||||
message: "cannot alias @context"
|
||||
JSON.LD.keyword?(expanded_id) or
|
||||
absolute_iri?(expanded_id) or
|
||||
IRI.absolute?(expanded_id) or
|
||||
blank_node_id?(expanded_id) ->
|
||||
{%TermDefinition{definition | iri_mapping: expanded_id}, active, defined}
|
||||
true ->
|
||||
|
|
|
@ -6,7 +6,7 @@ defmodule JSON.LD.Encoder do
|
|||
|
||||
import JSON.LD.Utils
|
||||
|
||||
alias RDF.{Dataset, Graph, BlankNode, Literal}
|
||||
alias RDF.{Dataset, Graph, IRI, BlankNode, Literal}
|
||||
alias RDF.NS.{XSD}
|
||||
|
||||
@rdf_type to_string(RDF.NS.RDF.type)
|
||||
|
@ -107,7 +107,7 @@ defmodule JSON.LD.Encoder do
|
|||
{subject, predicate, node_object} =
|
||||
{to_string(subject), to_string(predicate), nil}
|
||||
node = Map.get(node_map, subject, %{"@id" => subject})
|
||||
if is_node_object = (match?(%URI{}, object) || match?(%BlankNode{}, object)) do
|
||||
if is_node_object = (match?(%IRI{}, object) || match?(%BlankNode{}, object)) do
|
||||
node_object = to_string(object)
|
||||
node_map = Map.put_new(node_map, node_object, %{"@id" => node_object})
|
||||
end
|
||||
|
@ -260,8 +260,8 @@ defmodule JSON.LD.Encoder do
|
|||
do: {list, list_nodes, [subject, property], head}
|
||||
|
||||
|
||||
defp rdf_to_object(%URI{} = uri, _use_native_types) do
|
||||
%{"@id" => to_string(uri)}
|
||||
defp rdf_to_object(%IRI{} = iri, _use_native_types) do
|
||||
%{"@id" => to_string(iri)}
|
||||
end
|
||||
|
||||
defp rdf_to_object(%BlankNode{} = bnode, _use_native_types) do
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
defmodule JSON.LD.Utils do
|
||||
|
||||
alias RDF.IRI
|
||||
|
||||
@doc """
|
||||
Resolves a relative IRI against a base IRI.
|
||||
|
||||
|
@ -10,36 +12,17 @@ defmodule JSON.LD.Utils do
|
|||
Characters additionally allowed in IRI references are treated in the same way that unreserved
|
||||
characters are treated in URI references, per [section 6.5 of RFC3987](http://tools.ietf.org/html/rfc3987#section-6.5)
|
||||
"""
|
||||
# TODO: This should be part of a dedicated RDF.IRI implementation and properly tested.
|
||||
def absolute_iri(value, base_iri)
|
||||
|
||||
def absolute_iri(value, nil), do: value
|
||||
def absolute_iri(value, nil),
|
||||
do: value
|
||||
def absolute_iri(value, base_iri),
|
||||
do: value |> RDF.IRI.absolute(base_iri) |> to_string
|
||||
|
||||
def absolute_iri(value, base_iri) do
|
||||
case URI.parse(value) do
|
||||
# absolute?
|
||||
uri = %URI{scheme: scheme} when not is_nil(scheme) -> uri
|
||||
# relative
|
||||
_ ->
|
||||
URI.merge(base_iri, value)
|
||||
end
|
||||
|> to_string
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks if the given value is an absolute IRI.
|
||||
|
||||
An absolute IRI is defined in [RFC3987](http://www.ietf.org/rfc/rfc3987.txt)
|
||||
containing a scheme along with a path and optional query and fragment segments.
|
||||
|
||||
see <https://www.w3.org/TR/json-ld-api/#dfn-absolute-iri>
|
||||
"""
|
||||
# TODO: This should be part of a dedicated RDF.IRI implementation and properly tested.
|
||||
def absolute_iri?(value), do: RDF.uri?(value)
|
||||
|
||||
# TODO: This should be part of a dedicated RDF.IRI implementation and properly tested.
|
||||
def relative_iri?(value),
|
||||
do: not (JSON.LD.keyword?(value) or absolute_iri?(value) or blank_node_id?(value))
|
||||
do: not (JSON.LD.keyword?(value) or IRI.absolute?(value) or blank_node_id?(value))
|
||||
|
||||
def compact_iri_parts(compact_iri, exclude_bnode \\ true) do
|
||||
with [prefix, suffix] <- String.split(compact_iri, ":", parts: 2) do
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -59,7 +59,7 @@ defmodule JSON.LD.Mixfile do
|
|||
|
||||
defp deps do
|
||||
[
|
||||
{:rdf, "~> 0.1"},
|
||||
{:rdf, "~> 0.3"},
|
||||
{:poison, "~> 3.0"},
|
||||
{:dialyxir, "~> 0.4", only: [:dev, :test], runtime: false},
|
||||
{:credo, "~> 0.6", only: [:dev, :test], runtime: false},
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -14,6 +14,6 @@
|
|||
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
|
||||
"mix_test_watch": {:hex, :mix_test_watch, "0.4.0", "7e44b681b0238999d4c39b5beed77b4ac45aef1c112a763aae414bdb5bc34523", [:mix], [{:fs, "~> 2.12", [hex: :fs, optional: false]}]},
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
|
||||
"rdf": {:hex, :rdf, "0.1.1", "94b2ae892740169b6631924a0dd2bb8909c9bd130294f33d5c8b1ed18fafd37a", [:mix], []},
|
||||
"rdf": {:hex, :rdf, "0.3.0", "31cfbde6fac432e71eb145726ccb76c115db8ba5d00a8c21dffe400c9b781171", [:mix], []},
|
||||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
|
||||
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], []}}
|
||||
|
|
|
@ -114,12 +114,12 @@ defmodule JSON.LD.CompactionTest do
|
|||
"http://example.com/b" => %{"@value" => "2012-01-04", "@type" => to_string(XSD.date)}
|
||||
},
|
||||
context: %{
|
||||
"xsd" => XSD.__base_uri__,
|
||||
"xsd" => XSD.__base_iri__,
|
||||
"b" => %{"@id" => "http://example.com/b", "@type" => "xsd:date"}
|
||||
},
|
||||
output: %{
|
||||
"@context" => %{
|
||||
"xsd" => XSD.__base_uri__,
|
||||
"xsd" => XSD.__base_iri__,
|
||||
"b" => %{"@id" => "http://example.com/b", "@type" => "xsd:date"}
|
||||
},
|
||||
"b" => "2012-01-04"
|
||||
|
|
|
@ -11,8 +11,8 @@ defmodule JSON.LD.DecoderTest do
|
|||
|
||||
defmodule TestNS do
|
||||
use RDF.Vocabulary.Namespace
|
||||
defvocab EX, base_uri: "http://example.org/#", terms: [], strict: false
|
||||
defvocab S, base_uri: "http://schema.org/", terms: [], strict: false
|
||||
defvocab EX, base_iri: "http://example.org/#", terms: [], strict: false
|
||||
defvocab S, base_iri: "http://schema.org/", terms: [], strict: false
|
||||
end
|
||||
|
||||
alias TestNS.{EX, S}
|
||||
|
|
|
@ -11,8 +11,8 @@ defmodule JSON.LD.EncoderTest do
|
|||
|
||||
defmodule TestNS do
|
||||
use RDF.Vocabulary.Namespace
|
||||
defvocab EX, base_uri: "http://example.com/", terms: [], strict: false
|
||||
defvocab S, base_uri: "http://schema.org/", terms: [], strict: false
|
||||
defvocab EX, base_iri: "http://example.com/", terms: [], strict: false
|
||||
defvocab S, base_iri: "http://schema.org/", terms: [], strict: false
|
||||
end
|
||||
|
||||
alias TestNS.{EX, S}
|
||||
|
|
|
@ -96,7 +96,7 @@ defmodule JSON.LD.IRICompactionTest do
|
|||
describe "with value" do
|
||||
setup do
|
||||
context = JSON.LD.context(%{
|
||||
"xsd" => XSD.__base_uri__,
|
||||
"xsd" => XSD.__base_iri__,
|
||||
"plain" => "http://example.com/plain",
|
||||
"lang" => %{"@id" => "http://example.com/lang", "@language" => "en"},
|
||||
"bool" => %{"@id" => "http://example.com/bool", "@type" => "xsd:boolean"},
|
||||
|
|
|
@ -10,7 +10,7 @@ defmodule JSON.LD.ValueCompactionTest do
|
|||
"dc" => "http://purl.org/dc/terms/", # TODO: RDF::Vocab::DC.to_uri.to_s,
|
||||
"ex" => "http://example.org/",
|
||||
"foaf" => "http://xmlns.com/foaf/0.1/", # TODO: RDF::Vocab::FOAF.to_uri.to_s,
|
||||
"xsd" => to_string(XSD.__base_uri__),
|
||||
"xsd" => to_string(XSD.__base_iri__),
|
||||
"langmap" => %{"@id" => "http://example.com/langmap", "@container" => "@language"},
|
||||
"list" => %{"@id" => "http://example.org/list", "@container" => "@list"},
|
||||
"nolang" => %{"@id" => "http://example.org/nolang", "@language" => nil},
|
||||
|
|
Loading…
Reference in a new issue