2016-12-07 23:20:12 +00:00
|
|
|
defmodule JSON.LD do
|
2017-02-10 14:16:51 +00:00
|
|
|
|
|
|
|
@keywords ~w[
|
|
|
|
@base
|
|
|
|
@container
|
|
|
|
@context
|
2017-04-09 20:55:54 +00:00
|
|
|
@default
|
2017-02-10 14:16:51 +00:00
|
|
|
@graph
|
|
|
|
@id
|
|
|
|
@index
|
|
|
|
@language
|
|
|
|
@list
|
|
|
|
@reverse
|
|
|
|
@set
|
|
|
|
@type
|
|
|
|
@value
|
|
|
|
@vocab
|
|
|
|
:
|
|
|
|
]
|
|
|
|
|
2017-03-21 00:01:55 +00:00
|
|
|
@doc """
|
|
|
|
The set of all JSON-LD keywords.
|
|
|
|
|
|
|
|
see <https://www.w3.org/TR/json-ld/#syntax-tokens-and-keywords>
|
|
|
|
"""
|
2017-02-10 14:16:51 +00:00
|
|
|
def keywords, do: @keywords
|
|
|
|
|
2017-03-21 00:01:55 +00:00
|
|
|
@doc """
|
|
|
|
Returns if the given value is a JSON-LD keyword.
|
|
|
|
"""
|
2017-02-10 14:16:51 +00:00
|
|
|
def keyword?(value) when is_binary(value) and value in @keywords, do: true
|
|
|
|
def keyword?(value), do: false
|
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Expands the given input according to the steps in the JSON-LD Expansion Algorithm.
|
|
|
|
|
|
|
|
> Expansion is the process of taking a JSON-LD document and applying a `@context`
|
|
|
|
> such that all IRIs, types, and values are expanded so that the `@context` is
|
|
|
|
> no longer necessary.
|
|
|
|
|
|
|
|
-- <https://www.w3.org/TR/json-ld/#expanded-document-form>
|
|
|
|
|
|
|
|
Details at <http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm>
|
|
|
|
"""
|
|
|
|
defdelegate expand(input, options \\ %JSON.LD.Options{}),
|
2017-02-19 02:47:05 +00:00
|
|
|
to: JSON.LD.Expansion
|
2017-02-10 14:16:51 +00:00
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Compacts the given input according to the steps in the JSON-LD Compaction Algorithm.
|
|
|
|
|
|
|
|
> Compaction is the process of applying a developer-supplied context to shorten
|
|
|
|
> IRIs to terms or compact IRIs and JSON-LD values expressed in expanded form
|
|
|
|
> to simple values such as strings or numbers. Often this makes it simpler to
|
|
|
|
> work with document as the data is expressed in application-specific terms.
|
|
|
|
> Compacted documents are also typically easier to read for humans.
|
|
|
|
|
|
|
|
-- <https://www.w3.org/TR/json-ld/#compacted-document-form>
|
|
|
|
|
|
|
|
Details at <https://www.w3.org/TR/json-ld-api/#compaction-algorithms>
|
|
|
|
"""
|
|
|
|
defdelegate compact(input, context, options \\ %JSON.LD.Options{}),
|
2017-03-03 20:51:16 +00:00
|
|
|
to: JSON.LD.Compaction
|
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Flattens the given input according to the steps in the JSON-LD Flattening Algorithm.
|
|
|
|
|
|
|
|
> Flattening collects all properties of a node in a single JSON object and labels
|
|
|
|
> all blank nodes with blank node identifiers. This ensures a shape of the data
|
|
|
|
> and consequently may drastically simplify the code required to process JSON-LD
|
|
|
|
> in certain applications.
|
|
|
|
|
|
|
|
-- <https://www.w3.org/TR/json-ld/#flattened-document-form>
|
|
|
|
|
|
|
|
Details at <https://www.w3.org/TR/json-ld-api/#flattening-algorithms>
|
|
|
|
"""
|
|
|
|
defdelegate flatten(input, context \\ nil, options \\ %JSON.LD.Options{}),
|
2017-03-18 20:52:41 +00:00
|
|
|
to: JSON.LD.Flattening
|
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
|
2017-02-10 14:16:51 +00:00
|
|
|
@doc """
|
2017-02-19 02:47:05 +00:00
|
|
|
Generator function for `JSON.LD.Context`s.
|
2017-03-21 00:01:55 +00:00
|
|
|
|
|
|
|
You can either pass a map with a `"@context"` key having the JSON-LD context
|
|
|
|
object its value, or the JSON-LD context object directly.
|
2017-02-10 14:16:51 +00:00
|
|
|
"""
|
2017-03-21 23:35:05 +00:00
|
|
|
def context(args, opts \\ %JSON.LD.Options{})
|
2017-02-10 14:16:51 +00:00
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
def context(%{"@context" => _} = object, options),
|
|
|
|
do: JSON.LD.Context.create(object, options)
|
2017-02-10 14:16:51 +00:00
|
|
|
|
2017-03-21 23:35:05 +00:00
|
|
|
def context(context, options),
|
|
|
|
do: JSON.LD.Context.create(%{"@context" => context}, options)
|
2017-02-10 14:16:51 +00:00
|
|
|
|
2017-04-09 20:55:54 +00:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Generator function for JSON-LD node maps.
|
|
|
|
"""
|
|
|
|
def node_map(input, node_id_map \\ nil),
|
|
|
|
do: JSON.LD.Flattening.node_map(input, node_id_map)
|
|
|
|
|
2016-12-07 23:20:12 +00:00
|
|
|
end
|