View Source RDF.TriG.Encoder (RDF.ex v2.0.0)
An encoder for TriG serializations of RDF.ex data structures.
As for all encoders of RDF.Serialization.Format
s, you normally won't use these
functions directly, but via one of the write_
functions on the RDF.TriG
format module or the generic RDF.Serialization
module.
Options
:content
: Allows specifying the content and structure of the Turtle document to be rendered and defining which parts should be generated in which order. This option accepts lists of the values:base
,:prefixes
,:default_graph
and:named_graphs
. You can also use:directives
to specify[:base, :prefixes]
and:graphs
to specify[:default_graph, :named_graphs]
as a group. Additionally, arbitrary strings can be included at desired positions to customize the document.RDF.TriG.write_string(dataset, content: [ "# === HEADER ===\n\n", :directives, "\n# === NAMED GRAPHS ===\n\n", :named_graphs "\n# === DEFAULT GRAPH ===\n\n", :default_graph ])
:prefixes
: Allows to specify the prefixes to be used as aRDF.PrefixMap
or anything from which aRDF.PrefixMap
can be created withRDF.PrefixMap.new/1
. If not specified the prefixes from all the graphs of the given dataset are used or if these are also not present theRDF.default_prefixes/0
.:base
: : Allows to specify the base URI to be used for a@base
directive. If not specified theRDF.default_base_iri/0
is used.:directive_style
: Specifies the style of directives to be used in the document. Possible values are:turtle
and:sparql
(default::turtle
).:implicit_base
: This boolean flag allows to use a base URI to get relative IRIs without embedding it explicitly in the content with a@base
directive, so that the URIs will be resolved according to the remaining strategy specified in section 5.1 of RFC3986 (default:false
).:base_description
: Allows to provide a description of the resource denoted by the base URI. This option is especially useful when the base URI is actually not specified, e.g. in the common use case of wanting to describe the document itself, which should be denoted by the URL where it is hosted as the implicit base URI.:line_prefix
: Allows to specify a function returning prefixes for the encoded lines. When this function is defined, the:single_triple_lines
option is implicitly set, so that each line encodes at most one triple. The function receives three arguments:type
- one of the following values specifying the content of the line::triple
,:description
,:graph
(for named graphs in TriG only),:closing
value
- atype
specific value for the content in this line- for
:triple
: theRDF.Triple
encoded in this line - for
:description
: the subject whose description is started in this line - for
:graph
: the name of the graph, opened in this line - for
:closing
: a value specifying which element is closed in this line
- for
graph_name
- the name of graph (in Turtle this is alwaysnil
)
:single_triple_lines
: When set totrue
each line encodes at most one triple, i.e. no object lists with multiple objects are used and no Turtle list encodings are used. This option is in of itself is not very useful. It is set implicitly when defining a:line_prefix
function which depends on this mode to produce useful results.:indent
: Allows to specify the number of spaces the output should be indented.:indent_width
: Allows to specify the number of spaces that should be used for indentations (default: 4).:pn_local_validation
: This option controls how IRIs are validated the check whether they can encoded as a prefixed name. Available settings are::fast
(default): Provides a quick and efficient validation that covers most common cases. It does not handle every possible valid scenario, focusing instead on typical structures encountered in prefixed names.:none
: Disables validation entirely. Use this mode if you are confident that all your IRIs are already compliant with prefixed name requirements, allowing you to bypass validation checks for increased performance.- Note: Currently, a
:strict
mode, which would provide comprehensive validation conforming strictly to the Turtle specification, is not implemented. Contributions for implementing this mode are welcome.
:rdf_star
: Allows to skip a RDF-star related preprocessing step. This can be used to improve performance a little bit when you know the encoded data doesn't include any RDF-star statements. Defaults to the returned value ofRDF.star?/0
.