core: creating a new graph from another graph
This commit is contained in:
parent
f49828b76b
commit
fd3a20116b
2 changed files with 32 additions and 0 deletions
|
@ -38,6 +38,12 @@ defmodule RDF.Graph do
|
|||
def new(%RDF.Description{} = description),
|
||||
do: new() |> add(description)
|
||||
|
||||
@doc """
|
||||
Creates an unnamed `RDF.Graph` from another `RDF.Graph`.
|
||||
"""
|
||||
def new(%RDF.Graph{descriptions: descriptions}),
|
||||
do: %RDF.Graph{descriptions: descriptions}
|
||||
|
||||
@doc """
|
||||
Creates an empty unnamed `RDF.Graph`.
|
||||
"""
|
||||
|
@ -68,6 +74,12 @@ defmodule RDF.Graph do
|
|||
def new(name, %RDF.Description{} = description),
|
||||
do: new(name) |> add(description)
|
||||
|
||||
@doc """
|
||||
Creates a named `RDF.Graph` from another `RDF.Graph`.
|
||||
"""
|
||||
def new(name, %RDF.Graph{descriptions: descriptions}),
|
||||
do: %RDF.Graph{new(name) | descriptions: descriptions}
|
||||
|
||||
@doc """
|
||||
Creates an unnamed `RDF.Graph` with initial triples.
|
||||
"""
|
||||
|
|
|
@ -77,6 +77,26 @@ defmodule RDF.GraphTest do
|
|||
assert unnamed_graph?(g)
|
||||
assert graph_includes_statement?(g, {EX.Subject, EX.predicate, EX.Object})
|
||||
end
|
||||
|
||||
test "creating a named graph from another graph" do
|
||||
g = Graph.new(EX.GraphName, Graph.new({EX.Subject, EX.predicate, EX.Object}))
|
||||
assert named_graph?(g, uri(EX.GraphName))
|
||||
assert graph_includes_statement?(g, {EX.Subject, EX.predicate, EX.Object})
|
||||
|
||||
g = Graph.new(EX.GraphName, Graph.new(EX.OtherGraphName, {EX.Subject, EX.predicate, EX.Object}))
|
||||
assert named_graph?(g, uri(EX.GraphName))
|
||||
assert graph_includes_statement?(g, {EX.Subject, EX.predicate, EX.Object})
|
||||
end
|
||||
|
||||
test "creating an unnamed graph from another graph" do
|
||||
g = Graph.new(Graph.new({EX.Subject, EX.predicate, EX.Object}))
|
||||
assert unnamed_graph?(g)
|
||||
assert graph_includes_statement?(g, {EX.Subject, EX.predicate, EX.Object})
|
||||
|
||||
g = Graph.new(Graph.new(EX.OtherGraphName, {EX.Subject, EX.predicate, EX.Object}))
|
||||
assert unnamed_graph?(g)
|
||||
assert graph_includes_statement?(g, {EX.Subject, EX.predicate, EX.Object})
|
||||
end
|
||||
end
|
||||
|
||||
describe "adding triples" do
|
||||
|
|
Loading…
Reference in a new issue