2016-10-15 16:26:56 +00:00
|
|
|
defmodule RDF do
|
2017-06-18 19:12:51 +00:00
|
|
|
@moduledoc """
|
|
|
|
The top-level module of RDF.ex.
|
|
|
|
|
|
|
|
RDF.ex consists of:
|
|
|
|
|
|
|
|
- modules for the nodes of an RDF graph
|
2017-08-20 20:35:14 +00:00
|
|
|
- `RDF.IRI`
|
2017-06-18 19:12:51 +00:00
|
|
|
- `RDF.BlankNode`
|
|
|
|
- `RDF.Literal`
|
|
|
|
- a facility for the mapping of URIs of a vocabulary to Elixir modules and
|
|
|
|
functions: `RDF.Vocabulary.Namespace`
|
|
|
|
- modules for the construction of statements
|
|
|
|
- `RDF.Triple`
|
|
|
|
- `RDF.Quad`
|
|
|
|
- `RDF.Statement`
|
|
|
|
- modules for collections of statements
|
|
|
|
- `RDF.Description`
|
|
|
|
- `RDF.Graph`
|
|
|
|
- `RDF.Dataset`
|
|
|
|
- `RDF.Data`
|
2017-08-20 20:35:14 +00:00
|
|
|
- `RDF.List`
|
2018-03-09 20:15:43 +00:00
|
|
|
- functions for working with RDF serializations: `RDF.Serialization`
|
|
|
|
- behaviours for the definition of RDF serialization formats
|
|
|
|
- `RDF.Serialization.Format`
|
2017-06-18 19:12:51 +00:00
|
|
|
- `RDF.Serialization.Decoder`
|
|
|
|
- `RDF.Serialization.Encoder`
|
2017-08-20 20:35:14 +00:00
|
|
|
- and the implementation of various RDF serialization formats
|
2017-06-18 19:12:51 +00:00
|
|
|
- `RDF.NTriples`
|
|
|
|
- `RDF.NQuads`
|
2017-08-20 20:35:14 +00:00
|
|
|
- `RDF.Turtle`
|
2017-06-18 19:12:51 +00:00
|
|
|
|
|
|
|
This top-level module provides shortcut functions for the construction of the
|
|
|
|
basic elements and structures of RDF and some general helper functions.
|
|
|
|
|
|
|
|
For a general introduction you may refer to the [README](readme.html).
|
|
|
|
"""
|
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
alias RDF.{IRI, Namespace, Literal, BlankNode, Triple, Quad,
|
2017-06-16 22:44:11 +00:00
|
|
|
Description, Graph, Dataset}
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2018-03-09 20:15:43 +00:00
|
|
|
defdelegate read_string(content, opts), to: RDF.Serialization
|
|
|
|
defdelegate read_string!(content, opts), to: RDF.Serialization
|
|
|
|
defdelegate read_file(filename, opts \\ []), to: RDF.Serialization
|
|
|
|
defdelegate read_file!(filename, opts \\ []), to: RDF.Serialization
|
|
|
|
defdelegate write_string(content, opts), to: RDF.Serialization
|
|
|
|
defdelegate write_string!(content, opts), to: RDF.Serialization
|
|
|
|
defdelegate write_file(filename, opts \\ []), to: RDF.Serialization
|
|
|
|
defdelegate write_file!(filename, opts \\ []), to: RDF.Serialization
|
|
|
|
|
|
|
|
|
2016-10-15 16:26:56 +00:00
|
|
|
@doc """
|
2017-06-16 22:44:11 +00:00
|
|
|
Checks if the given value is a RDF resource.
|
2017-04-10 01:06:20 +00:00
|
|
|
|
2016-10-15 16:26:56 +00:00
|
|
|
## Examples
|
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
iex> RDF.resource?(RDF.iri("http://example.com/resource"))
|
2017-06-16 22:44:11 +00:00
|
|
|
true
|
|
|
|
iex> RDF.resource?(EX.resource)
|
|
|
|
true
|
|
|
|
iex> RDF.resource?(RDF.bnode)
|
|
|
|
true
|
|
|
|
iex> RDF.resource?(42)
|
|
|
|
false
|
2016-10-15 16:26:56 +00:00
|
|
|
"""
|
2017-06-16 22:44:11 +00:00
|
|
|
def resource?(value)
|
2017-08-20 20:35:14 +00:00
|
|
|
def resource?(%IRI{}), do: true
|
|
|
|
def resource?(%BlankNode{}), do: true
|
2017-06-16 22:44:11 +00:00
|
|
|
def resource?(atom) when is_atom(atom), do: resource?(Namespace.resolve_term(atom))
|
2017-08-20 20:35:14 +00:00
|
|
|
def resource?(_), do: false
|
2017-03-12 13:27:52 +00:00
|
|
|
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
defdelegate uri?(value), to: IRI, as: :valid?
|
|
|
|
defdelegate iri?(value), to: IRI, as: :valid?
|
|
|
|
defdelegate uri(value), to: IRI, as: :new
|
|
|
|
defdelegate iri(value), to: IRI, as: :new
|
|
|
|
defdelegate uri!(value), to: IRI, as: :new!
|
|
|
|
defdelegate iri!(value), to: IRI, as: :new!
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-07-21 22:21:28 +00:00
|
|
|
@doc """
|
|
|
|
Checks if the given value is a blank node.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> RDF.bnode?(RDF.bnode)
|
|
|
|
true
|
2017-08-20 20:35:14 +00:00
|
|
|
iex> RDF.bnode?(RDF.iri("http://example.com/resource"))
|
2017-07-21 22:21:28 +00:00
|
|
|
false
|
|
|
|
iex> RDF.bnode?(42)
|
|
|
|
false
|
|
|
|
"""
|
|
|
|
def bnode?(%BlankNode{}), do: true
|
|
|
|
def bnode?(_), do: false
|
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate bnode(), to: BlankNode, as: :new
|
|
|
|
defdelegate bnode(id), to: BlankNode, as: :new
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate literal(value), to: Literal, as: :new
|
|
|
|
defdelegate literal(value, opts), to: Literal, as: :new
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate triple(s, p, o), to: Triple, as: :new
|
|
|
|
defdelegate triple(tuple), to: Triple, as: :new
|
2016-10-30 18:36:46 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate quad(s, p, o, g), to: Quad, as: :new
|
|
|
|
defdelegate quad(tuple), to: Quad, as: :new
|
2016-10-30 18:36:46 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate description(arg), to: Description, as: :new
|
|
|
|
defdelegate description(arg1, arg2), to: Description, as: :new
|
|
|
|
defdelegate description(arg1, arg2, arg3), to: Description, as: :new
|
2016-11-02 02:19:19 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate graph(), to: Graph, as: :new
|
|
|
|
defdelegate graph(arg), to: Graph, as: :new
|
|
|
|
defdelegate graph(arg1, arg2), to: Graph, as: :new
|
|
|
|
defdelegate graph(arg1, arg2, arg3), to: Graph, as: :new
|
|
|
|
defdelegate graph(arg1, arg2, arg3, arg4), to: Graph, as: :new
|
2016-11-02 02:19:19 +00:00
|
|
|
|
2017-06-16 22:44:11 +00:00
|
|
|
defdelegate dataset(), to: Dataset, as: :new
|
|
|
|
defdelegate dataset(arg), to: Dataset, as: :new
|
|
|
|
defdelegate dataset(arg1, arg2), to: Dataset, as: :new
|
2016-11-02 02:19:19 +00:00
|
|
|
|
2017-07-27 19:49:35 +00:00
|
|
|
defdelegate list?(resource, graph), to: RDF.List, as: :node?
|
|
|
|
defdelegate list?(description), to: RDF.List, as: :node?
|
|
|
|
|
2018-04-07 20:59:03 +00:00
|
|
|
def list(native_list), do: RDF.List.from(native_list)
|
|
|
|
def list(head, %Graph{} = graph), do: RDF.List.new(head, graph)
|
|
|
|
def list(native_list, opts), do: RDF.List.from(native_list, opts)
|
|
|
|
|
|
|
|
defdelegate string(value), to: RDF.String, as: :new
|
|
|
|
defdelegate string(value, opts), to: RDF.String, as: :new
|
|
|
|
defdelegate lang_string(value), to: RDF.LangString, as: :new
|
|
|
|
defdelegate lang_string(value, opts), to: RDF.LangString, as: :new
|
|
|
|
defdelegate boolean(value), to: RDF.Boolean, as: :new
|
|
|
|
defdelegate boolean(value, opts), to: RDF.Boolean, as: :new
|
|
|
|
defdelegate integer(value), to: RDF.Integer, as: :new
|
|
|
|
defdelegate integer(value, opts), to: RDF.Integer, as: :new
|
|
|
|
defdelegate double(value), to: RDF.Double, as: :new
|
|
|
|
defdelegate double(value, opts), to: RDF.Double, as: :new
|
2018-06-15 19:19:22 +00:00
|
|
|
defdelegate decimal(value), to: RDF.Decimal, as: :new
|
|
|
|
defdelegate decimal(value, opts), to: RDF.Decimal, as: :new
|
2018-04-07 20:59:03 +00:00
|
|
|
defdelegate date(value), to: RDF.Date, as: :new
|
|
|
|
defdelegate date(value, opts), to: RDF.Date, as: :new
|
|
|
|
defdelegate time(value), to: RDF.Time, as: :new
|
|
|
|
defdelegate time(value, opts), to: RDF.Time, as: :new
|
|
|
|
defdelegate date_time(value), to: RDF.DateTime, as: :new
|
|
|
|
defdelegate date_time(value, opts), to: RDF.DateTime, as: :new
|
2016-11-02 02:19:19 +00:00
|
|
|
|
2017-06-10 21:08:49 +00:00
|
|
|
for term <- ~w[type subject predicate object first rest value]a do
|
|
|
|
defdelegate unquote(term)(), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(term)(s, o), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(term)(s, o1, o2), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(term)(s, o1, o2, o3), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(term)(s, o1, o2, o3, o4), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(term)(s, o1, o2, o3, o4, o5), to: RDF.NS.RDF
|
|
|
|
end
|
2017-05-29 21:12:50 +00:00
|
|
|
|
2018-05-26 00:51:28 +00:00
|
|
|
defdelegate unquote(:true)(), to: RDF.Boolean.Value
|
|
|
|
defdelegate unquote(:false)(), to: RDF.Boolean.Value
|
|
|
|
|
2017-06-10 21:08:49 +00:00
|
|
|
defdelegate langString(), to: RDF.NS.RDF
|
|
|
|
defdelegate unquote(nil)(), to: RDF.NS.RDF
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-08-20 20:35:14 +00:00
|
|
|
defdelegate __base_iri__(), to: RDF.NS.RDF
|
2016-10-15 16:26:56 +00:00
|
|
|
end
|