Skip to content

Commit

Permalink
Use uuid bnode generator on Turtle/TriG decoders by default
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotto committed Jul 13, 2024
1 parent f1b5e08 commit 5cc0728
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/rdf/serializations/turtle_trig/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule RDF.TurtleTriG.Decoder do
## Blank Node Generation
When interpreting blank node descriptions, the decoder generates blank node
identifiers. By default, it uses `RDF.BlankNode.Generator.Random` to create
identifiers. By default, it uses `RDF.BlankNode.Generator.UUID` to create
random identifiers, ensuring uniqueness across multiple parsing operations.
This behavior prevents unintended merging of unrelated blank nodes,
which could occur with deterministic identifiers, e.g. from
Expand All @@ -14,17 +14,19 @@ defmodule RDF.TurtleTriG.Decoder do
You can customize blank node generation using the `bnode_gen` option and
providing either a module implementing `RDF.BlankNode.Generator.Algorithm`
or an instantiated `RDF.BlankNode.Generator.Algorithm` struct in case you
want to start with a non-default state. See the respective
want to customize the generator. See the respective
`RDF.BlankNode.Generator.Algorithm` implementation on what fields can be set.
You can also use `:random` or `:increment` as short values for the respective
`RDF.BlankNode.Generator.Algorithm` implementations.
You can also use `:uuid`, `:random` or `:increment` as short values for the
respective `RDF.BlankNode.Generator.Algorithm` implementations.
Example usage:
RDF.Turtle.Decoder.decode!(turtle_string,
bnode_gen: RDF.BlankNode.Generator.Increment.new(prefix: "x", counter: 42))
To set a global default, use the `turtle_trig_decoder_bnode_gen` application config:
To set a global or environment-specific default, use the `turtle_trig_decoder_bnode_gen`
application config (e.g. the `RDF.BlankNode.Generator.Increment` implementation,
generating deterministic blank nodes, can make testing easier):
config :rdf,
turtle_trig_decoder_bnode_gen: :increment
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/serializations/turtle_trig/decoder/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule RDF.TurtleTriG.Decoder.State do

alias RDF.BlankNode

@default_turtle_trig_decoder_bnode_gen :random
@default_turtle_trig_decoder_bnode_gen if Code.ensure_loaded?(UUID), do: :uuid, else: :random

def default_bnode_gen do
Application.get_env(
Expand Down

0 comments on commit 5cc0728

Please sign in to comment.