# `RDF`
[🔗](https://github.com/rdf-elixir/rdf-ex/blob/v3.0.0/lib/rdf.ex#L1)

The top-level module of RDF.ex.

RDF.ex consists of:

- structs for the nodes of an RDF graph
  - `RDF.IRI`
  - `RDF.BlankNode`
  - `RDF.Literal`
- various modules making working with the nodes of an RDF graph easier
  - `RDF.Term`
  - `RDF.Sigils`
  - `RDF.Guards`
- the `RDF.Literal.Datatype` system
- a facility for the mapping of URIs of a vocabulary to Elixir modules and
  functions: `RDF.Vocabulary.Namespace`
- a facility for the automatic generation of resource identifiers: `RDF.Resource.Generator`
- modules for the construction of statements
  - `RDF.Triple`
  - `RDF.Quad`
  - `RDF.Statement`
- structs for collections of statements
  - `RDF.Description`
  - `RDF.Graph`
  - `RDF.Dataset`
  - `RDF.List`
  - `RDF.Diff`
- a polymorphic API for working with all of the above RDF data structures
  uniformly: `RDF.Data` (built on the `RDF.Data.Source` protocol)
- functions to construct and execute basic graph pattern queries: `RDF.Query`
- functions for working with RDF serializations: `RDF.Serialization`
- behaviours for the definition of RDF serialization formats
  - `RDF.Serialization.Format`
  - `RDF.Serialization.Decoder`
  - `RDF.Serialization.Encoder`
- and the implementation of various RDF serialization formats
  - `RDF.NTriples`
  - `RDF.NQuads`
  - `RDF.Turtle`
  - `RDF.TriG`

This top-level module provides shortcut functions for the construction of the
basic elements and structures of RDF and some general helper functions.

It also can be `use`'ed to add basic imports and aliases for working with RDF.ex
on any module. See `__using__/1` for details.

For a general introduction you may refer to the guides on the [homepage](https://rdf-elixir.dev).

# ``

# `__using__`
*macro* 

Adds basic imports and aliases for working with RDF.ex.

This allows to write

    use RDF

instead of the following

    import RDF.Sigils
    import RDF.Guards
    import RDF.Namespace.IRI
  
    require RDF.Graph

    alias RDF.{XSD, NTriples, NQuads, Turtle}

# `bnode`

# `bnode`

# `bnode?`

Checks if the given value is a blank node.

## Examples

    iex> RDF.bnode?(RDF.bnode)
    true
    iex> RDF.bnode?(RDF.iri("http://example.com/resource"))
    false
    iex> RDF.bnode?(42)
    false

# `coerce_graph_name`

# `coerce_object`

# `coerce_predicate`

# `coerce_predicate`

# `coerce_subject`

# `dataset`

# `dataset`

# `dataset`

# `default_base_iri`

# `default_prefixes`

A user-defined `RDF.PrefixMap` of prefixes to IRI namespaces.

This prefix map will be used implicitly wherever a prefix map is expected, but
not provided. For example, when you don't pass a prefix map to the Turtle serializer,
this prefix map will be used.

By default, the `standard_prefixes/0` are part of this prefix map, but you can
define additional default prefixes via the `default_prefixes` compile-time
configuration.

For example:

    config :rdf,
      default_prefixes: %{
        ex: "http://example.com/"
      }

You can also set `:default_prefixes` to a module-function tuple `{mod, fun}`
with a function which should be called to determine the default prefixes.

If you don't want the `standard_prefixes/0` to be part of the default prefixes,
or you want to map the standard prefixes to different namespaces (strongly discouraged!),
you can set the `use_standard_prefixes` compile-time configuration flag to `false`.

    config :rdf,
      use_standard_prefixes: false

# `default_prefixes`

Returns the `default_prefixes/0` with additional prefix mappings.

The `prefix_mappings` can be given in any format accepted by `RDF.PrefixMap.new/1`.

# `description`

# `diff`

# `dir_lang_string`

# `direction`

# `dirLangString`

# `first`

# `graph`

# `graph`

# `graph`

# `iri`

# `iri!`

# `iri?`

# `json`

# `lang_string`

# `lang_string`

# `langString`

# `langString`

# `language`

# `list`

# `list`

# `list?`

# `list?`

# `literal`

# `literal`

# `literal?`

Checks if the given value is an RDF literal.

# `object`

# `predicate`

# `prefix_map`

# `prefixes`

# `property_map`

# `quad`

# `quad`

# `read_file`

# `read_file!`

# `read_stream`

# `read_stream!`

# `read_string`

# `read_string!`

# `reifies`

# `resource?`

Checks if the given value is a `RDF.Resource`, i.e. a `RDF.IRI` or `RDF.BlankNode`.

## Examples

Supposed `EX` is a `RDF.Vocabulary.Namespace` and `Foo` is not.

    iex> RDF.resource?(RDF.iri("http://example.com/resource"))
    true
    iex> RDF.resource?(EX.resource)
    true
    iex> RDF.resource?(EX.Resource)
    true
    iex> RDF.resource?(Foo.Resource)
    false
    iex> RDF.resource?(RDF.bnode)
    true
    iex> RDF.resource?(RDF.XSD.integer(42))
    false
    iex> RDF.resource?(42)
    false

# `rest`

# `sparql_prefixes`

Returns a SPARQL encoded list of prefixes.

The `prefix_mappings` can be given in any format accepted by `RDF.PrefixMap.new/1`.

### Examples

    iex> RDF.sparql_prefixes(
    ...>  rdf: RDF,
    ...>  rdfs: RDF.NS.RDFS,
    ...>  xsd: RDF.NS.XSD,
    ...>  ex1: EX,
    ...>  ex2: "http://example.com/ns2/")
    """
    PREFIX ex1: <http://example.com/>
    PREFIX ex2: <http://example.com/ns2/>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    """

# `standard_prefixes`

A fixed set prefixes that will always be part of the `default_prefixes/0`.

```elixir
RDF.PrefixMap.new(%{
  :rdf => ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
  :rdfs => ~I<http://www.w3.org/2000/01/rdf-schema#>,
  :xsd => ~I<http://www.w3.org/2001/XMLSchema#>
})
```

See `default_prefixes/0`, if you don't want these standard prefixes to be part
of the default prefixes.

# `star?`

Returns whether RDF-star support is enabled.

# `statement`

# `statement`

# `statement`

# `subject`

# `term?`

Checks if the given value is a `RDF.Term`, i.e. a `RDF.IRI`, `RDF.BlankNode` or `RDF.Literal`.

## Examples

Supposed `EX` is a `RDF.Vocabulary.Namespace` and `Foo` is not.

    iex> RDF.term?(RDF.iri("http://example.com/resource"))
    true
    iex> RDF.term?(EX.resource)
    true
    iex> RDF.term?(EX.Resource)
    true
    iex> RDF.term?(Foo.Resource)
    false
    iex> RDF.term?(RDF.bnode)
    true
    iex> RDF.term?(RDF.XSD.integer(42))
    true
    iex> RDF.term?(42)
    false

# `triple`

# `triple`

# `turtle_prefixes`

Returns a Turtle encoded list of prefixes.

The `prefix_mappings` can be given in any format accepted by `RDF.PrefixMap.new/1`.

### Examples

    iex> RDF.turtle_prefixes(
    ...>  rdf: RDF,
    ...>  rdfs: RDF.NS.RDFS,
    ...>  xsd: RDF.NS.XSD,
    ...>  ex1: EX,
    ...>  ex2: "http://example.com/ns2/")
    """
    @prefix ex1: <http://example.com/> .
    @prefix ex2: <http://example.com/ns2/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
    """

# `type`

# `uri`

# `uri!`

# `uri?`

# `value`

# `write_file`

# `write_file!`

# `write_stream`

# `write_string`

# `write_string!`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
