RDF.ex v0.7.1 RDF.Serialization View Source

General functions for working with RDF serializations.

Link to this section Summary

Functions

The list of all available RDF.Serialization.Formats in an application.

Returns the RDF.Serialization.Format with the given name, if available.

Returns the proper RDF.Serialization.Format for the given file extension, if available.

Returns the RDF.Serialization.Format with the given media type, if available.

The list of all known RDF.Serialization.Formats in the RDF.ex eco-system.

Reads and decodes a serialized graph or dataset from a file.

Reads and decodes a serialized graph or dataset from a file.

Reads and decodes a serialized graph or dataset from a string.

Reads and decodes a serialized graph or dataset from a string.

Encodes and writes a graph or dataset to a file.

Encodes and writes a graph or dataset to a file.

Encodes and writes a graph or dataset to a string.

Encodes and writes a graph or dataset to a string.

Link to this section Types

Link to this section Functions

Link to this function

available_formats()

View Source
available_formats() :: [format()]

The list of all available RDF.Serialization.Formats in an application.

A known format might not be available in an application, when the format is implemented in an external library and this not specified as a Mix dependency of this application.

Examples

iex> RDF.Serialization.available_formats
[RDF.Turtle, RDF.NTriples, RDF.NQuads]
Link to this function

format(name)

View Source
format(String.t() | atom()) :: format() | nil

Returns the RDF.Serialization.Format with the given name, if available.

Examples

iex> RDF.Serialization.format(:turtle)
RDF.Turtle
iex> RDF.Serialization.format("turtle")
RDF.Turtle
iex> RDF.Serialization.format(:jsonld)
nil  # unless json_ld is defined as a dependency of the application
Link to this function

format_by_extension(extension)

View Source
format_by_extension(String.t()) :: format() | nil

Returns the proper RDF.Serialization.Format for the given file extension, if available.

Examples

iex> RDF.Serialization.format_by_extension("ttl")
RDF.Turtle
iex> RDF.Serialization.format_by_extension(".ttl")
RDF.Turtle
iex> RDF.Serialization.format_by_extension("jsonld")
nil  # unless json_ld is defined as a dependency of the application
Link to this function

format_by_media_type(media_type)

View Source
format_by_media_type(String.t()) :: format() | nil

Returns the RDF.Serialization.Format with the given media type, if available.

Examples

iex> RDF.Serialization.format_by_media_type("text/turtle")
RDF.Turtle
iex> RDF.Serialization.format_by_media_type("application/ld+json")
nil  # unless json_ld is defined as a dependency of the application

The list of all known RDF.Serialization.Formats in the RDF.ex eco-system.

Note: Not all known formats might be available to an application, see available_formats/0.

Examples

iex> RDF.Serialization.formats
[RDF.Turtle, JSON.LD, RDF.NTriples, RDF.NQuads]
Link to this function

read_file(file, opts \\ [])

View Source
read_file(Path.t(), keyword()) ::
  {:ok, RDF.Graph.t() | RDF.Dataset.t()} | {:error, any()}

Reads and decodes a serialized graph or dataset from a file.

The format can be specified with the format option and a format name or the media_type option and the media type of the format. If none of these are given, the format gets inferred from the extension of the given file name.

It returns an {:ok, data} tuple, with data being the deserialized graph or dataset, or {:error, reason} if an error occurs.

Link to this function

read_file!(file, opts \\ [])

View Source
read_file!(Path.t(), keyword()) :: RDF.Graph.t() | RDF.Dataset.t()

Reads and decodes a serialized graph or dataset from a file.

The format can be specified with the format option and a format name or the media_type option and the media type of the format. If none of these are given, the format gets inferred from the extension of the given file name.

As opposed to read_file, it raises an exception if an error occurs.

Link to this function

read_string(content, opts)

View Source
read_string(String.t(), keyword()) ::
  {:ok, RDF.Graph.t() | RDF.Dataset.t()} | {:error, any()}

Reads and decodes a serialized graph or dataset from a string.

The format must be specified with the format option and a format name or the media_type option and the media type of the format.

It returns an {:ok, data} tuple, with data being the deserialized graph or dataset, or {:error, reason} if an error occurs.

Link to this function

read_string!(content, opts)

View Source
read_string!(String.t(), keyword()) :: RDF.Graph.t() | RDF.Dataset.t()

Reads and decodes a serialized graph or dataset from a string.

The format must be specified with the format option and a format name or the media_type option and the media type of the format.

As opposed to read_string, it raises an exception if an error occurs.

Link to this function

write_file(data, path, opts \\ [])

View Source
write_file(RDF.Graph.t() | RDF.Dataset.t(), Path.t(), keyword()) ::
  :ok | {:error, any()}

Encodes and writes a graph or dataset to a file.

The format can be specified with the format option and a format name or the media_type option and the media type of the format. If none of these are given, the format gets inferred from the extension of the given file name.

Other available serialization-independent options:

  • :force - If not set to true, an error is raised when the given file already exists (default: false)
  • :file_mode - A list with the Elixir File.open modes to be used for writing (default: [:utf8, :write])

It returns :ok if successful or {:error, reason} if an error occurs.

Link to this function

write_file!(data, path, opts \\ [])

View Source
write_file!(RDF.Graph.t() | RDF.Dataset.t(), Path.t(), keyword()) :: :ok

Encodes and writes a graph or dataset to a file.

The format can be specified with the format option and a format name or the media_type option and the media type of the format. If none of these are given, the format gets inferred from the extension of the given file name.

See write_file for a list of other available options.

As opposed to write_file, it raises an exception if an error occurs.

Link to this function

write_string(data, opts)

View Source
write_string(RDF.Graph.t() | RDF.Dataset.t(), keyword()) ::
  {:ok, String.t()} | {:error, any()}

Encodes and writes a graph or dataset to a string.

The format must be specified with the format option and a format name or the media_type option and the media type of the format.

It returns an {:ok, string} tuple, with string being the serialized graph or dataset, or {:error, reason} if an error occurs.

Link to this function

write_string!(data, opts)

View Source
write_string!(RDF.Graph.t() | RDF.Dataset.t(), keyword()) :: String.t()

Encodes and writes a graph or dataset to a string.

The format must be specified with the format option and a format name or the media_type option and the media type of the format.

As opposed to write_string, it raises an exception if an error occurs.