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

A behaviour and generator for modules of terms resolving to `RDF.IRI`s.

Note: A `RDF.Namespace` is NOT a IRI namespace! The terms of a `RDF.Namespace` don't
have to necessarily refer to IRIs from the same IRI namespace. "Namespace" here is
just meant in the sense that an Elixir module is a namespace. Most of the

Most of the time you'll want to use a `RDF.Vocabulary.Namespace`, a special type of
`RDF.Namespace` where all terms indeed resolve to IRIs of a shared base URI namespace.

For an introduction into `RDF.Namespace`s and `RDF.Vocabulary.Namespace`s see
[this guide](https://rdf-elixir.dev/rdf-ex/namespaces.html).

# `t`

```elixir
@type t() :: module()
```

# `__iris__`

```elixir
@callback __iris__() :: [RDF.IRI.t()]
```

All `RDF.IRI`s of a `RDF.Namespace`.

# `__resolve_term__`

```elixir
@callback __resolve_term__(atom()) :: {:ok, RDF.IRI.t()} | {:error, Exception.t()}
```

Resolves a term to a `RDF.IRI`.

# `__terms__`

```elixir
@callback __terms__() :: [atom()]
```

All terms of a `RDF.Namespace`.

# `act_as_namespace`
*macro* 

A macro to let a module act as a specified `RDF.Namespace` or `RDF.Vocabulary.Namespace`.

## Example

    defmodule Example.NS do
      use RDF.Vocabulary.Namespace

      defvocab Example,
        base_iri: "http://www.example.com/ns/",
        terms: [:Foo, :bar]
    end

    defmodule Example do
      import RDF.Namespace

      act_as_namespace Example.NS.Example

      # your application functions
    end

    Example.Foo |> Example.bar(42)

# `create`

Creates a `RDF.Namespace` module with the given name and term mapping dynamically.

The line where the module is defined and its file must be passed as options.

# `create!`

Creates a `RDF.Namespace` module with the given name and term mapping dynamically.

The line where the module is defined and its file must be passed as options.

# `defnamespace`
*macro* 

A macro to define a `RDF.Namespace`.

## Example

    defmodule YourApp.NS do
      import RDF.Namespace

      defnamespace EX, [
                     foo: ~I<http://example1.com/foo>,
                     Bar: "http://example2.com/Bar",
                   ]
    end

> #### Warning {: .warning}
>
> This macro is intended to be used at compile-time, i.e. in the body of a
> `defmodule` definition. If you want to create `RDF.Namespace`s dynamically
> at runtime, please use `create/4`.

# `resolve_term`

```elixir
@spec resolve_term(RDF.IRI.t() | module()) ::
  {:ok, RDF.IRI.t()} | {:error, Exception.t()}
```

Resolves a qualified term to a `RDF.IRI`.

It determines a `RDF.Namespace` from the qualifier of the given term and
delegates to remaining part of the term to `__resolve_term__/1` of this
determined namespace.

# `resolve_term!`

```elixir
@spec resolve_term!(RDF.IRI.t() | module()) :: RDF.IRI.t()
```

Resolves a qualified term to a `RDF.IRI` or raises an error when that's not possible.

See `resolve_term/1` for more.

---

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