• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rdf-elixir / rdf-ex / e13c6dddfa3dcff42f19061d70f6a1c7c0caafb8-PR-17

pending completion
e13c6dddfa3dcff42f19061d70f6a1c7c0caafb8-PR-17

Pull #17

github

marcelotto
Pull Request #17: Add implementation of the RDF Dataset canonicalization algorithm

166 of 166 new or added lines in 9 files covered. (100.0%)

5349 of 7224 relevant lines covered (74.04%)

567.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/lib/rdf/canonicalization/identifier_issuer.ex
1
defmodule RDF.Canonicalization.IdentifierIssuer do
2
  @moduledoc """
3
  An identifier issuer is used to issue new blank node identifier.
4
  """
5

6
  defstruct id: nil,
7
            issued_identifiers: %{},
8
            issue_order: [],
9
            identifier_counter: 0,
10
            identifier_prefix: nil
11

12
  def new(prefix) do
13
    %__MODULE__{id: create_id(), identifier_prefix: prefix}
98✔
14
  end
15

16
  def canonical, do: new("_:c14n")
×
17

18
  def copy(issuer), do: %__MODULE__{issuer | id: create_id()}
9,022✔
19

20
  defp create_id, do: :erlang.unique_integer()
9,120✔
21

22
  @doc """
23
  Issues a new blank node identifier for a given existing blank node identifier.
24

25
  See <https://www.w3.org/community/reports/credentials/CG-FINAL-rdf-dataset-canonicalization-20221009/#issue-identifier>
26
  """
27
  def issue_identifier(issuer, existing_identifier) do
28
    if issued_identifier = issuer.issued_identifiers[existing_identifier] do
3,438✔
29
      {issued_identifier, issuer}
30
    else
31
      issued_identifier = issuer.identifier_prefix <> Integer.to_string(issuer.identifier_counter)
1,749✔
32

33
      {issued_identifier,
34
       %{
35
         issuer
36
         | issued_identifiers:
37
             Map.put(issuer.issued_identifiers, existing_identifier, issued_identifier),
1,749✔
38
           issue_order: [existing_identifier | issuer.issue_order],
1,749✔
39
           identifier_counter: issuer.identifier_counter + 1
1,749✔
40
       }}
41
    end
42
  end
43

44
  def identifier(issuer, identifier) do
45
    Map.get(issuer.issued_identifiers, identifier)
39,022✔
46
  end
47

48
  def issued?(issuer, identifier) do
49
    Map.has_key?(issuer.issued_identifiers, identifier)
147✔
50
  end
51

52
  def issued_identifiers(state) do
53
    Enum.reverse(state.issue_order)
98✔
54
  end
55
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc