Add RDF.Graph.base_iri/1 and RDF.Graph.prefixes/1

This commit is contained in:
Marcel Otto 2020-09-28 11:22:46 +02:00
parent c306700991
commit 69fbdd60b3
3 changed files with 32 additions and 2 deletions

View file

@ -9,8 +9,14 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
### Added
- `RDF.Description.subject/1` and `RDF.Description.change_subject/2`
- `RDF.Graph.name/1` and `RDF.Graph.change_name/2`
- to `RDF.Description`
- `RDF.Description.subject/1`
- `RDF.Description.change_subject/2`
- to `RDF.Graph`
- `RDF.Graph.name/1`
- `RDF.Graph.change_name/2`
- `RDF.Graph.base_iri/1`
- `RDF.Graph.prefixes/1`
### Changed

View file

@ -901,6 +901,12 @@ defmodule RDF.Graph do
def equal?(_, _), do: false
@doc """
Returns the prefixes of the given `graph` as a `RDF.PrefixMap`.
"""
@spec prefixes(t) :: PrefixMap.t() | nil
def prefixes(%__MODULE__{} = graph), do: graph.prefixes
@doc """
Adds `prefixes` to the given `graph`.
@ -955,6 +961,12 @@ defmodule RDF.Graph do
%__MODULE__{graph | prefixes: nil}
end
@doc """
Returns the base IRI of the given `graph`.
"""
@spec base_iri(t) :: IRI.t() | nil
def base_iri(%__MODULE__{} = graph), do: graph.base_iri
@doc """
Sets the base IRI of the given `graph`.

View file

@ -810,6 +810,11 @@ defmodule RDF.GraphTest do
|> Graph.equal?(Graph.new({EX.S, EX.p(), EX.O}, name: EX.Graph2))
end
test "prefixes/1" do
assert Graph.prefixes(graph()) == nil
assert %Graph{prefixes: PrefixMap.new()} |> Graph.prefixes() == PrefixMap.new()
end
describe "add_prefixes/2" do
test "when prefixes already exist" do
graph = Graph.new(prefixes: %{xsd: XSD}) |> Graph.add_prefixes(ex: EX)
@ -857,6 +862,13 @@ defmodule RDF.GraphTest do
assert Graph.clear_prefixes(Graph.new(prefixes: %{ex: EX})) == Graph.new()
end
test "base_iri/1" do
assert Graph.base_iri(graph()) == nil
assert %Graph{base_iri: ~I<http://example.com/>} |> Graph.base_iri() ==
~I<http://example.com/>
end
describe "set_base_iri/1" do
test "when given an IRI" do
graph = Graph.new() |> Graph.set_base_iri(~I<http://example.com/>)