2017-02-18 20:35:27 +00:00
|
|
|
defmodule RDF.DatasetTest do
|
|
|
|
use RDF.Test.Case
|
|
|
|
|
|
|
|
doctest RDF.Dataset
|
|
|
|
|
|
|
|
|
2017-03-31 14:27:34 +00:00
|
|
|
describe "new" do
|
2017-02-18 20:35:27 +00:00
|
|
|
test "creating an empty unnamed dataset" do
|
|
|
|
assert unnamed_dataset?(unnamed_dataset())
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an empty dataset with a proper dataset name" do
|
|
|
|
refute unnamed_dataset?(named_dataset())
|
|
|
|
assert named_dataset?(named_dataset())
|
|
|
|
end
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
test "creating an empty dataset with a coercible dataset name" do
|
2017-02-18 20:35:27 +00:00
|
|
|
assert named_dataset("http://example.com/DatasetName")
|
2017-08-20 20:35:14 +00:00
|
|
|
|> named_dataset?(iri("http://example.com/DatasetName"))
|
|
|
|
assert named_dataset(EX.Foo) |> named_dataset?(iri(EX.Foo))
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an unnamed dataset with an initial triple" do
|
|
|
|
ds = Dataset.new({EX.Subject, EX.predicate, EX.Object})
|
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an unnamed dataset with an initial quad" do
|
|
|
|
ds = Dataset.new({EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert dataset_includes_statement?(ds,
|
|
|
|
{EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating a named dataset with an initial triple" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new({EX.Subject, EX.predicate, EX.Object}, name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating a named dataset with an initial quad" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new({EX.Subject, EX.predicate, EX.Object, EX.GraphName}, name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an unnamed dataset with a list of initial statements" do
|
|
|
|
ds = Dataset.new([
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject2, EX.predicate2, EX.Object2, EX.GraphName},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3, nil}
|
|
|
|
])
|
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject2, EX.predicate2, EX.Object2, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject3, EX.predicate3, EX.Object3, nil})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating a named dataset with a list of initial statements" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new([
|
2017-02-18 20:35:27 +00:00
|
|
|
{EX.Subject, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2, EX.GraphName},
|
|
|
|
{EX.Subject, EX.predicate3, EX.Object3, nil}
|
2019-03-29 00:29:24 +00:00
|
|
|
], name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate2, EX.Object2, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate3, EX.Object3, nil})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating a named dataset with an initial description" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new(Description.new({EX.Subject, EX.predicate, EX.Object}), name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an unnamed dataset with an initial description" do
|
|
|
|
ds = Dataset.new(Description.new({EX.Subject, EX.predicate, EX.Object}))
|
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
2017-03-31 23:55:35 +00:00
|
|
|
|
2019-03-28 23:34:22 +00:00
|
|
|
test "creating a named dataset with an initial graph" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new(Graph.new({EX.Subject, EX.predicate, EX.Object}), name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-03-31 23:55:35 +00:00
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.new(Graph.new({EX.Subject, EX.predicate, EX.Object}, name: EX.GraphName), name: EX.DatasetName)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_dataset?(ds, iri(EX.DatasetName))
|
2017-03-31 23:55:35 +00:00
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.GraphName), iri(EX.GraphName))
|
2017-03-31 23:55:35 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creating an unnamed dataset with an inital graph" do
|
|
|
|
ds = Dataset.new(Graph.new({EX.Subject, EX.predicate, EX.Object}))
|
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.new(Graph.new({EX.Subject, EX.predicate, EX.Object}, name: EX.GraphName))
|
2017-03-31 23:55:35 +00:00
|
|
|
assert unnamed_dataset?(ds)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.GraphName), iri(EX.GraphName))
|
2017-03-31 23:55:35 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
end
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
2017-03-31 14:27:34 +00:00
|
|
|
describe "add" do
|
2017-02-18 20:35:27 +00:00
|
|
|
test "a proper triple is added to the default graph" do
|
2017-08-20 20:35:14 +00:00
|
|
|
assert Dataset.add(dataset(), {iri(EX.Subject), EX.predicate, iri(EX.Object)})
|
2017-02-18 20:35:27 +00:00
|
|
|
|> dataset_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a proper quad is added to the specified graph" do
|
2017-08-20 20:35:14 +00:00
|
|
|
ds = Dataset.add(dataset(), {iri(EX.Subject), EX.predicate, iri(EX.Object), iri(EX.Graph)})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object, iri(EX.Graph)})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a proper quad with nil context is added to the default graph" do
|
2017-08-20 20:35:14 +00:00
|
|
|
ds = Dataset.add(dataset(), {iri(EX.Subject), EX.predicate, iri(EX.Object), nil})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
test "a coercible triple" do
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Dataset.add(dataset(),
|
|
|
|
{"http://example.com/Subject", EX.predicate, EX.Object})
|
|
|
|
|> dataset_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
test "a coercible quad" do
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Dataset.add(dataset(),
|
|
|
|
{"http://example.com/Subject", EX.predicate, EX.Object, "http://example.com/GraphName"})
|
|
|
|
|> dataset_includes_statement?({EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a quad and an overwriting graph context " do
|
|
|
|
assert Dataset.add(dataset(), {EX.Subject, EX.predicate, EX.Object, EX.Graph}, EX.Other)
|
|
|
|
|> dataset_includes_statement?({EX.Subject, EX.predicate, EX.Object, EX.Other})
|
|
|
|
assert Dataset.add(dataset(), {EX.Subject, EX.predicate, EX.Object, EX.Graph}, nil)
|
|
|
|
|> dataset_includes_statement?({EX.Subject, EX.predicate, EX.Object})
|
|
|
|
end
|
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
test "statements with multiple objects" do
|
|
|
|
ds = Dataset.add(dataset(), {EX.Subject1, EX.predicate1, [EX.Object1, EX.Object2]})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object2})
|
|
|
|
|
|
|
|
ds = Dataset.add(dataset(), {EX.Subject1, EX.predicate1, [EX.Object1, EX.Object2], EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object2, EX.GraphName})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a list of triples without specification of the default context" do
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
|
|
|
])
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject3, EX.predicate3, EX.Object3})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a list of triples with specification of the default context" do
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
2017-06-06 22:48:08 +00:00
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
2017-02-18 20:35:27 +00:00
|
|
|
], EX.Graph)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2, EX.Graph})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject3, EX.predicate3, EX.Object3, EX.Graph})
|
|
|
|
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
|
|
|
], nil)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2, nil})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject3, EX.predicate3, EX.Object3, nil})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a list of quads without specification of the default context" do
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph1},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2, nil},
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph2}
|
|
|
|
])
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, EX.Graph1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate2, EX.Object2, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, EX.Graph2})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a list of quads with specification of the default context" do
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph1},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2, nil},
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph2}
|
|
|
|
], EX.Graph)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate2, EX.Object2, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, EX.Graph})
|
|
|
|
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph1},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2, nil},
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1, EX.Graph2}
|
|
|
|
], nil)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate2, EX.Object2, nil})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject, EX.predicate1, EX.Object1, nil})
|
|
|
|
end
|
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
test "a list of mixed triples and quads" do
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1, EX.GraphName},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
|
|
|
])
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject3, EX.predicate3, EX.Object3, nil})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a Description without specification of the default context" do
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.add(dataset(), Description.new(EX.Subject1, [
|
|
|
|
{EX.predicate1, EX.Object1},
|
|
|
|
{EX.predicate2, EX.Object2},
|
|
|
|
]))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a Description with specification of the default context" do
|
|
|
|
ds = Dataset.add(dataset(), Description.new(EX.Subject1, [
|
|
|
|
{EX.predicate1, EX.Object1},
|
|
|
|
{EX.predicate2, EX.Object2},
|
|
|
|
]), nil)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.add(ds, Description.new({EX.Subject1, EX.predicate3, EX.Object3}), EX.Graph)
|
2017-03-31 23:19:54 +00:00
|
|
|
assert Enum.count(ds) == 3
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate3, EX.Object3, EX.Graph})
|
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "an unnamed Graph without specification of the default context" do
|
2017-03-31 23:19:54 +00:00
|
|
|
ds = Dataset.add(dataset(), Graph.new([
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
]))
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}))
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert Enum.count(ds) == 3
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
2017-06-06 22:48:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "an unnamed Graph with specification of the default context" do
|
|
|
|
ds = Dataset.add(dataset(), Graph.new([
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
]), nil)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}), nil)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert Enum.count(ds) == 3
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
2017-03-31 23:19:54 +00:00
|
|
|
|
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}), EX.Graph)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.Graph), iri(EX.Graph))
|
2017-03-31 23:19:54 +00:00
|
|
|
assert Enum.count(ds) == 4
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
2017-03-31 23:19:54 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3, EX.Graph})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a named Graph without specification of the default context" do
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.add(dataset(), Graph.new([
|
2017-03-31 23:19:54 +00:00
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
2019-03-28 23:34:22 +00:00
|
|
|
], name: EX.Graph1))
|
2017-06-06 22:48:08 +00:00
|
|
|
assert Dataset.graph(ds, EX.Graph1)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.Graph1), iri(EX.Graph1))
|
2017-06-06 22:48:08 +00:00
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.Graph1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2, EX.Graph1})
|
|
|
|
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}, name: EX.Graph2))
|
2017-06-06 22:48:08 +00:00
|
|
|
assert Dataset.graph(ds, EX.Graph2)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.Graph2), iri(EX.Graph2))
|
2017-06-06 22:48:08 +00:00
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert Enum.count(ds) == 3
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.Graph1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2, EX.Graph1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3, EX.Graph2})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a named Graph with specification of the default context" do
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.add(dataset(), Graph.new([
|
2017-06-06 22:48:08 +00:00
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
2019-03-28 23:34:22 +00:00
|
|
|
], name: EX.Graph1), nil)
|
2017-03-31 23:19:54 +00:00
|
|
|
refute Dataset.graph(ds, EX.Graph1)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}, name: EX.Graph2), nil)
|
2017-03-31 23:19:54 +00:00
|
|
|
refute Dataset.graph(ds, EX.Graph2)
|
|
|
|
assert unnamed_graph?(Dataset.default_graph(ds))
|
|
|
|
assert Enum.count(ds) == 3
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
|
|
|
|
2019-03-28 23:34:22 +00:00
|
|
|
ds = Dataset.add(ds, Graph.new({EX.Subject1, EX.predicate2, EX.Object3}, name: EX.Graph3), EX.Graph)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert named_graph?(Dataset.graph(ds, EX.Graph), iri(EX.Graph))
|
2017-03-31 23:19:54 +00:00
|
|
|
assert Enum.count(ds) == 4
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3, EX.Graph})
|
2017-06-06 21:35:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "an unnamed Dataset" do
|
|
|
|
ds = Dataset.add(dataset(), Dataset.new([
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
]))
|
|
|
|
assert ds.name == nil
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object3}))
|
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object3, EX.Graph}))
|
2017-06-06 22:48:08 +00:00
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object4}), EX.Graph)
|
2017-06-06 21:35:46 +00:00
|
|
|
assert ds.name == nil
|
2017-06-06 22:48:08 +00:00
|
|
|
assert Enum.count(ds) == 5
|
2017-06-06 21:35:46 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3, EX.Graph})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object4, EX.Graph})
|
2017-06-06 21:35:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a named Dataset" do
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.add(named_dataset(), Dataset.new([
|
2017-06-06 21:35:46 +00:00
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
2019-03-29 00:29:24 +00:00
|
|
|
], name: EX.DS1))
|
2017-08-20 20:35:14 +00:00
|
|
|
assert ds.name == iri(EX.DatasetName)
|
2017-06-06 21:35:46 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
|
2019-03-29 00:29:24 +00:00
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object3}, name: EX.DS2))
|
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object3, EX.Graph}, name: EX.DS2))
|
|
|
|
ds = Dataset.add(ds, Dataset.new({EX.Subject1, EX.predicate2, EX.Object4}, name: EX.DS2), EX.Graph)
|
2017-08-20 20:35:14 +00:00
|
|
|
assert ds.name == iri(EX.DatasetName)
|
2017-06-06 22:48:08 +00:00
|
|
|
assert Enum.count(ds) == 5
|
2017-06-06 21:35:46 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object3, EX.Graph})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate2, EX.Object4, EX.Graph})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a list of Descriptions" do
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
Description.new({EX.Subject1, EX.predicate1, EX.Object1}),
|
|
|
|
Description.new({EX.Subject2, EX.predicate2, EX.Object2}),
|
|
|
|
Description.new({EX.Subject1, EX.predicate3, EX.Object3})
|
|
|
|
])
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject2, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate3, EX.Object3})
|
|
|
|
|
|
|
|
ds = Dataset.add(ds, [
|
|
|
|
Description.new({EX.Subject1, EX.predicate1, EX.Object1}),
|
|
|
|
Description.new({EX.Subject2, EX.predicate2, EX.Object2}),
|
|
|
|
Description.new({EX.Subject1, EX.predicate3, EX.Object3})
|
|
|
|
], EX.Graph)
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject2, EX.predicate2, EX.Object2, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate3, EX.Object3, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate1, EX.Object1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject2, EX.predicate2, EX.Object2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.Subject1, EX.predicate3, EX.Object3})
|
|
|
|
end
|
|
|
|
|
2017-06-16 22:03:15 +00:00
|
|
|
test "a list of Graphs" do
|
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}])
|
|
|
|
|> RDF.Dataset.add([
|
|
|
|
Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S1, EX.P2, bnode(:foo)}]),
|
2019-03-28 23:34:22 +00:00
|
|
|
Graph.new({EX.S1, EX.P2, EX.O3}),
|
|
|
|
Graph.new([{EX.S1, EX.P2, EX.O2}, {EX.S2, EX.P2, EX.O2}], name: EX.Graph)
|
2017-06-16 22:03:15 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
assert Enum.count(ds) == 6
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo)})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, EX.O3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, EX.O2, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2, EX.Graph})
|
|
|
|
end
|
2017-02-18 20:35:27 +00:00
|
|
|
|
|
|
|
test "duplicates are ignored" do
|
|
|
|
ds = Dataset.add(dataset(), {EX.Subject, EX.predicate, EX.Object, EX.GraphName})
|
|
|
|
assert Dataset.add(ds, {EX.Subject, EX.predicate, EX.Object, EX.GraphName}) == ds
|
|
|
|
end
|
|
|
|
|
2017-08-11 20:22:27 +00:00
|
|
|
test "non-coercible statements elements are causing an error" do
|
2017-08-20 20:35:14 +00:00
|
|
|
assert_raise RDF.IRI.InvalidError, fn ->
|
|
|
|
Dataset.add(dataset(), {"not a IRI", EX.predicate, iri(EX.Object), iri(EX.GraphName)})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
2017-08-20 20:35:14 +00:00
|
|
|
assert_raise RDF.Literal.InvalidError, fn ->
|
2017-02-18 20:35:27 +00:00
|
|
|
Dataset.add(dataset(), {EX.Subject, EX.prop, self(), nil})
|
|
|
|
end
|
2017-08-20 20:35:14 +00:00
|
|
|
assert_raise RDF.IRI.InvalidError, fn ->
|
|
|
|
Dataset.add(dataset(), {iri(EX.Subject), EX.predicate, iri(EX.Object), "not a IRI"})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-31 14:27:34 +00:00
|
|
|
describe "put" do
|
2017-06-06 22:48:08 +00:00
|
|
|
test "a list of statements without specification of the default context" do
|
2017-02-18 20:35:27 +00:00
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2, EX.Graph}])
|
|
|
|
|> RDF.Dataset.put([
|
|
|
|
{EX.S1, EX.P2, EX.O3, EX.Graph},
|
|
|
|
{EX.S1, EX.P2, bnode(:foo), nil},
|
|
|
|
{EX.S2, EX.P2, EX.O3, EX.Graph},
|
|
|
|
{EX.S2, EX.P2, EX.O4, EX.Graph}])
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 5
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo)})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, EX.O3, EX.Graph})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O3, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O4, EX.Graph})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a list of statements with specification of the default context" do
|
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2, EX.Graph}])
|
|
|
|
|> RDF.Dataset.put([
|
|
|
|
{EX.S1, EX.P1, EX.O3, EX.Graph},
|
|
|
|
{EX.S1, EX.P2, bnode(:foo), nil},
|
|
|
|
{EX.S2, EX.P2, EX.O3, EX.Graph},
|
|
|
|
{EX.S2, EX.P2, EX.O4}], nil)
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 5
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O3})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo)})
|
2017-06-06 22:48:08 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O3})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O4})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2, EX.Graph})
|
|
|
|
|
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2, EX.Graph}])
|
|
|
|
|> RDF.Dataset.put([
|
|
|
|
{EX.S1, EX.P1, EX.O3},
|
|
|
|
{EX.S1, EX.P1, EX.O4, EX.Graph},
|
|
|
|
{EX.S1, EX.P2, bnode(:foo), nil},
|
|
|
|
{EX.S2, EX.P2, EX.O3, EX.Graph},
|
|
|
|
{EX.S2, EX.P2, EX.O4}], EX.Graph)
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 6
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O3, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O4, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo), EX.Graph})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O3, EX.Graph})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O4, EX.Graph})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a Description" do
|
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}, {EX.S1, EX.P3, EX.O3}])
|
|
|
|
|> RDF.Dataset.put(Description.new(EX.S1, [{EX.P3, EX.O4}, {EX.P2, bnode(:foo)}]))
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 4
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P3, EX.O4})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo)})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "an unnamed Graph" do
|
2017-04-01 00:17:59 +00:00
|
|
|
ds = Dataset.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}, {EX.S1, EX.P3, EX.O3}])
|
|
|
|
|> RDF.Dataset.put(Graph.new([{EX.S1, EX.P3, EX.O4}, {EX.S1, EX.P2, bnode(:foo)}]))
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 4
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P3, EX.O4})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo)})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "a named Graph" do
|
2017-04-01 00:17:59 +00:00
|
|
|
ds = Dataset.new(
|
2019-03-28 23:34:22 +00:00
|
|
|
Graph.new([{EX.S1, EX.P1, EX.O1}, {EX.S2, EX.P2, EX.O2}, {EX.S1, EX.P3, EX.O3}], name: EX.GraphName))
|
2017-04-01 00:17:59 +00:00
|
|
|
|> RDF.Dataset.put(
|
|
|
|
Graph.new([{EX.S1, EX.P3, EX.O4}, {EX.S1, EX.P2, bnode(:foo)}]), EX.GraphName)
|
|
|
|
|
|
|
|
assert Dataset.statement_count(ds) == 4
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P1, EX.O1, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P3, EX.O4, EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S1, EX.P2, bnode(:foo), EX.GraphName})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S2, EX.P2, EX.O2, EX.GraphName})
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "simultaneous use of the different forms to address the default context" do
|
|
|
|
ds = RDF.Dataset.put(dataset(), [
|
|
|
|
{EX.S, EX.P, EX.O1},
|
|
|
|
{EX.S, EX.P, EX.O2, nil}])
|
|
|
|
assert Dataset.statement_count(ds) == 2
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S, EX.P, EX.O1})
|
|
|
|
assert dataset_includes_statement?(ds, {EX.S, EX.P, EX.O2})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-02 21:05:00 +00:00
|
|
|
|
2017-06-04 01:58:30 +00:00
|
|
|
describe "delete" do
|
|
|
|
setup do
|
|
|
|
{:ok,
|
|
|
|
dataset1: Dataset.new({EX.S1, EX.p1, EX.O1}),
|
|
|
|
dataset2: Dataset.new([
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, EX.O2, EX.Graph},
|
|
|
|
]),
|
|
|
|
dataset3: Dataset.new([
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, [EX.O1, EX.O2], EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, [~B<foo>, ~L"bar"], EX.Graph2},
|
|
|
|
]),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a single statement",
|
|
|
|
%{dataset1: dataset1, dataset2: dataset2, dataset3: dataset3} do
|
|
|
|
assert Dataset.delete(Dataset.new, {EX.S, EX.p, EX.O}) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset1, {EX.S1, EX.p1, EX.O1}) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset2, {EX.S2, EX.p2, EX.O2, EX.Graph}) == dataset1
|
|
|
|
assert Dataset.delete(dataset2, {EX.S1, EX.p1, EX.O1}) ==
|
|
|
|
Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
|
|
|
assert Dataset.delete(dataset3, {EX.S2, EX.p2, EX.O1, EX.Graph1}) ==
|
|
|
|
Dataset.new [
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, EX.O2, EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, [~B<foo>, ~L"bar"], EX.Graph2},
|
|
|
|
]
|
|
|
|
assert Dataset.delete(dataset3, {EX.S2, EX.p2, [EX.O1, EX.O2], EX.Graph1}) ==
|
|
|
|
Dataset.new [
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S3, EX.p3, [~B<foo>, ~L"bar"], EX.Graph2},
|
|
|
|
]
|
|
|
|
assert Dataset.delete(dataset3, {EX.S2, EX.p2, [EX.O1, EX.O2]}, EX.Graph1) ==
|
|
|
|
Dataset.new [
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S3, EX.p3, [~B<foo>, ~L"bar"], EX.Graph2},
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multiple statements with a list of triples",
|
|
|
|
%{dataset1: dataset1, dataset2: dataset2, dataset3: dataset3} do
|
|
|
|
assert Dataset.delete(dataset1, [{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S1, EX.p1, EX.O2}]) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset2, [{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, EX.O2, EX.Graph}]) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset3, [
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, [EX.O1, EX.O2, EX.O3], EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, ~B<foo>, EX.Graph2}]) == Dataset.new({EX.S3, EX.p3, ~L"bar", EX.Graph2})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multiple statements with a Description",
|
|
|
|
%{dataset1: dataset1, dataset2: dataset2} do
|
|
|
|
assert Dataset.delete(dataset1, Description.new(EX.S1, EX.p1, EX.O1)) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset1, Description.new(EX.S1, EX.p1, EX.O1), EX.Graph) == dataset1
|
|
|
|
assert Dataset.delete(dataset2, Description.new(EX.S2, EX.p2, EX.O2), EX.Graph) == dataset1
|
|
|
|
assert Dataset.delete(dataset2, Description.new(EX.S1, EX.p1, EX.O1)) ==
|
|
|
|
Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multiple statements with a Graph",
|
|
|
|
%{dataset1: dataset1, dataset2: dataset2, dataset3: dataset3} do
|
|
|
|
assert Dataset.delete(dataset1, Graph.new({EX.S1, EX.p1, EX.O1})) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset2, Graph.new({EX.S1, EX.p1, EX.O1})) ==
|
|
|
|
Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
2019-03-28 23:34:22 +00:00
|
|
|
assert Dataset.delete(dataset2, Graph.new({EX.S2, EX.p2, EX.O2}, name: EX.Graph)) == dataset1
|
|
|
|
assert Dataset.delete(dataset2, Graph.new({EX.S2, EX.p2, EX.O2}, name: EX.Graph)) == dataset1
|
2017-06-04 01:58:30 +00:00
|
|
|
assert Dataset.delete(dataset2, Graph.new({EX.S2, EX.p2, EX.O2}), EX.Graph) == dataset1
|
|
|
|
assert Dataset.delete(dataset2, Graph.new({EX.S2, EX.p2, EX.O2}), EX.Graph) == dataset1
|
|
|
|
assert Dataset.delete(dataset3, Graph.new([
|
|
|
|
{EX.S1, EX.p1, [EX.O1, EX.O2]},
|
|
|
|
{EX.S2, EX.p2, EX.O3},
|
|
|
|
{EX.S3, EX.p3, ~B<foo>},
|
|
|
|
])) == Dataset.new([
|
|
|
|
{EX.S2, EX.p2, [EX.O1, EX.O2], EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, [~B<foo>, ~L"bar"], EX.Graph2},
|
|
|
|
])
|
2019-03-28 23:34:22 +00:00
|
|
|
assert Dataset.delete(dataset3, Graph.new([
|
2017-06-06 22:48:08 +00:00
|
|
|
{EX.S1, EX.p1, [EX.O1, EX.O2]},
|
|
|
|
{EX.S2, EX.p2, EX.O3},
|
|
|
|
{EX.S3, EX.p3, ~B<foo>},
|
2019-03-28 23:34:22 +00:00
|
|
|
], name: EX.Graph2)) == Dataset.new([
|
2017-06-06 22:48:08 +00:00
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, [EX.O1, EX.O2], EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, [~L"bar"], EX.Graph2},
|
|
|
|
])
|
2017-06-04 01:58:30 +00:00
|
|
|
assert Dataset.delete(dataset3, Graph.new({EX.S3, EX.p3, ~B<foo>}), EX.Graph2) ==
|
|
|
|
Dataset.new([
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, [EX.O1, EX.O2], EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, ~L"bar", EX.Graph2},
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multiple statements with a Dataset",
|
|
|
|
%{dataset1: dataset1, dataset2: dataset2} do
|
|
|
|
assert Dataset.delete(dataset1, dataset1) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset1, dataset2) == Dataset.new
|
|
|
|
assert Dataset.delete(dataset2, dataset1) == Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-06-02 21:05:00 +00:00
|
|
|
describe "delete_graph" do
|
|
|
|
setup do
|
|
|
|
{:ok,
|
|
|
|
dataset1: Dataset.new({EX.S1, EX.p1, EX.O1}),
|
|
|
|
dataset2: Dataset.new([
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, EX.O2, EX.Graph},
|
|
|
|
]),
|
|
|
|
dataset3: Dataset.new([
|
|
|
|
{EX.S1, EX.p1, EX.O1},
|
|
|
|
{EX.S2, EX.p2, EX.O2, EX.Graph1},
|
|
|
|
{EX.S3, EX.p3, EX.O3, EX.Graph2},
|
|
|
|
]),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "the default graph", %{dataset1: dataset1, dataset2: dataset2} do
|
|
|
|
assert Dataset.delete_graph(dataset1, nil) == Dataset.new
|
|
|
|
assert Dataset.delete_graph(dataset2, nil) == Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_default_graph", %{dataset1: dataset1, dataset2: dataset2} do
|
|
|
|
assert Dataset.delete_default_graph(dataset1) == Dataset.new
|
|
|
|
assert Dataset.delete_default_graph(dataset2) == Dataset.new({EX.S2, EX.p2, EX.O2, EX.Graph})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a single graph", %{dataset1: dataset1, dataset2: dataset2} do
|
|
|
|
assert Dataset.delete_graph(dataset1, EX.Graph) == dataset1
|
|
|
|
assert Dataset.delete_graph(dataset2, EX.Graph) == dataset1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a list of graphs", %{dataset1: dataset1, dataset3: dataset3} do
|
|
|
|
assert Dataset.delete_graph(dataset3, [EX.Graph1, EX.Graph2]) == dataset1
|
|
|
|
assert Dataset.delete_graph(dataset3, [EX.Graph1, EX.Graph2, EX.Graph3]) == dataset1
|
|
|
|
assert Dataset.delete_graph(dataset3, [EX.Graph1, EX.Graph2, nil]) == Dataset.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-03-31 14:27:34 +00:00
|
|
|
test "pop" do
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Dataset.pop(Dataset.new) == {nil, Dataset.new}
|
|
|
|
|
|
|
|
{quad, dataset} = Dataset.new({EX.S, EX.p, EX.O, EX.Graph}) |> Dataset.pop
|
2017-08-20 20:35:14 +00:00
|
|
|
assert quad == {iri(EX.S), iri(EX.p), iri(EX.O), iri(EX.Graph)}
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Enum.count(dataset.graphs) == 0
|
|
|
|
|
|
|
|
{{subject, predicate, object, _}, dataset} =
|
|
|
|
Dataset.new([{EX.S, EX.p, EX.O, EX.Graph}, {EX.S, EX.p, EX.O}])
|
|
|
|
|> Dataset.pop
|
2017-08-20 20:35:14 +00:00
|
|
|
assert {subject, predicate, object} == {iri(EX.S), iri(EX.p), iri(EX.O)}
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Enum.count(dataset.graphs) == 1
|
|
|
|
|
|
|
|
{{subject, _, _, graph_context}, dataset} =
|
|
|
|
Dataset.new([{EX.S, EX.p, EX.O1, EX.Graph}, {EX.S, EX.p, EX.O2, EX.Graph}])
|
|
|
|
|> Dataset.pop
|
2017-08-20 20:35:14 +00:00
|
|
|
assert subject == iri(EX.S)
|
|
|
|
assert graph_context == iri(EX.Graph)
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Enum.count(dataset.graphs) == 1
|
|
|
|
end
|
|
|
|
|
2017-06-02 21:05:00 +00:00
|
|
|
|
2018-10-27 14:30:19 +00:00
|
|
|
test "values/1" do
|
|
|
|
assert Dataset.new() |> Dataset.values() == %{}
|
|
|
|
assert Dataset.new([{EX.s1, EX.p, EX.o1}, {EX.s2, EX.p, EX.o2, EX.graph}])
|
|
|
|
|> Dataset.values() ==
|
|
|
|
%{
|
|
|
|
nil => %{
|
|
|
|
RDF.Term.value(EX.s1) => %{RDF.Term.value(EX.p) => [RDF.Term.value(EX.o1)]}
|
|
|
|
},
|
|
|
|
RDF.Term.value(EX.graph) => %{
|
|
|
|
RDF.Term.value(EX.s2) => %{RDF.Term.value(EX.p) => [RDF.Term.value(EX.o2)]},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-04 21:27:25 +00:00
|
|
|
test "values/2" do
|
|
|
|
mapping = fn
|
|
|
|
{:graph_name, graph_name} ->
|
|
|
|
graph_name
|
|
|
|
{:predicate, predicate} ->
|
|
|
|
predicate |> to_string() |> String.split("/") |> List.last() |> String.to_atom()
|
|
|
|
{_, term} ->
|
|
|
|
RDF.Term.value(term)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert Dataset.new() |> Dataset.values(mapping) == %{}
|
|
|
|
assert Dataset.new([{EX.s1, EX.p, EX.o1}, {EX.s2, EX.p, EX.o2, EX.graph}])
|
|
|
|
|> Dataset.values(mapping) ==
|
|
|
|
%{
|
|
|
|
nil => %{
|
|
|
|
RDF.Term.value(EX.s1) => %{p: [RDF.Term.value(EX.o1)]}
|
|
|
|
},
|
|
|
|
EX.graph => %{
|
|
|
|
RDF.Term.value(EX.s2) => %{p: [RDF.Term.value(EX.o2)]},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-10-27 14:30:19 +00:00
|
|
|
|
2019-04-02 22:12:42 +00:00
|
|
|
test "equal/2" do
|
2019-04-04 19:19:33 +00:00
|
|
|
triple = {EX.S, EX.p, EX.O}
|
|
|
|
assert Dataset.equal?(Dataset.new(triple), Dataset.new(triple))
|
|
|
|
assert Dataset.equal?(Dataset.new(triple, name: EX.Dataset1),
|
|
|
|
Dataset.new(triple, name: EX.Dataset1))
|
|
|
|
assert Dataset.equal?(
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph1, prefixes: %{ex: EX})),
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph1, prefixes: %{ex: RDF}))
|
|
|
|
)
|
2019-08-02 22:10:47 +00:00
|
|
|
assert Dataset.equal?(
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph1, base_iri: EX.base)),
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph1, base_iri: EX.other_base))
|
|
|
|
)
|
2019-04-04 19:19:33 +00:00
|
|
|
refute Dataset.equal?(Dataset.new(triple), Dataset.new({EX.S, EX.p, EX.O2}))
|
|
|
|
refute Dataset.equal?(Dataset.new(triple, name: EX.Dataset1),
|
|
|
|
Dataset.new(triple, name: EX.Dataset2))
|
|
|
|
refute Dataset.equal?(
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph1)),
|
|
|
|
Dataset.new(Graph.new(triple, name: EX.Graph2))
|
|
|
|
)
|
2019-04-02 22:12:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
describe "Enumerable protocol" do
|
|
|
|
test "Enum.count" do
|
2019-03-29 00:29:24 +00:00
|
|
|
assert Enum.count(Dataset.new(name: EX.foo)) == 0
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Enum.count(Dataset.new {EX.S, EX.p, EX.O, EX.Graph}) == 1
|
|
|
|
assert Enum.count(Dataset.new [{EX.S, EX.p, EX.O1, EX.Graph}, {EX.S, EX.p, EX.O2}]) == 2
|
|
|
|
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1, EX.Graph},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2, EX.Graph},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
|
|
|
])
|
|
|
|
assert Enum.count(ds) == 3
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Enum.member?" do
|
2017-08-20 20:35:14 +00:00
|
|
|
refute Enum.member?(Dataset.new, {iri(EX.S), EX.p, iri(EX.O), iri(EX.Graph)})
|
2017-02-18 20:35:27 +00:00
|
|
|
assert Enum.member?(Dataset.new({EX.S, EX.p, EX.O, EX.Graph}),
|
|
|
|
{EX.S, EX.p, EX.O, EX.Graph})
|
|
|
|
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1, EX.Graph},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2, EX.Graph},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3}
|
|
|
|
])
|
|
|
|
assert Enum.member?(ds, {EX.Subject1, EX.predicate1, EX.Object1, EX.Graph})
|
|
|
|
assert Enum.member?(ds, {EX.Subject1, EX.predicate2, EX.Object2, EX.Graph})
|
|
|
|
assert Enum.member?(ds, {EX.Subject3, EX.predicate3, EX.Object3})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Enum.reduce" do
|
|
|
|
ds = Dataset.add(dataset(), [
|
|
|
|
{EX.Subject1, EX.predicate1, EX.Object1, EX.Graph},
|
|
|
|
{EX.Subject1, EX.predicate2, EX.Object2},
|
|
|
|
{EX.Subject3, EX.predicate3, EX.Object3, EX.Graph}
|
|
|
|
])
|
|
|
|
|
|
|
|
assert ds == Enum.reduce(ds, dataset(),
|
|
|
|
fn(statement, acc) -> acc |> Dataset.add(statement) end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-30 10:40:44 +00:00
|
|
|
describe "Collectable protocol" do
|
|
|
|
test "with a list of triples" do
|
|
|
|
triples = [
|
|
|
|
{EX.Subject, EX.predicate1, EX.Object1},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2},
|
|
|
|
{EX.Subject, EX.predicate2, EX.Object2, EX.Graph}
|
|
|
|
]
|
|
|
|
assert Enum.into(triples, Dataset.new()) == Dataset.new(triples)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with a list of lists" do
|
|
|
|
lists = [
|
|
|
|
[EX.Subject, EX.predicate1, EX.Object1],
|
|
|
|
[EX.Subject, EX.predicate2, EX.Object2],
|
|
|
|
[EX.Subject, EX.predicate2, EX.Object2, EX.Graph]
|
|
|
|
]
|
|
|
|
assert Enum.into(lists, Dataset.new()) ==
|
|
|
|
Dataset.new(Enum.map(lists, &List.to_tuple/1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
describe "Access behaviour" do
|
|
|
|
test "access with the [] operator" do
|
|
|
|
assert Dataset.new[EX.Graph] == nil
|
|
|
|
assert Dataset.new({EX.S, EX.p, EX.O, EX.Graph})[EX.Graph] ==
|
2019-03-28 23:34:22 +00:00
|
|
|
Graph.new({EX.S, EX.p, EX.O}, name: EX.Graph)
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|