rdf-ex/test/unit/data_test.exs

614 lines
23 KiB
Elixir
Raw Normal View History

2017-06-04 02:20:08 +00:00
defmodule RDF.DataTest do
use RDF.Test.Case
setup do
description =
EX.S
|> EX.p1(EX.O1, EX.O2)
|> EX.p2(EX.O3)
|> EX.p3(~B<foo>, ~L"bar")
2020-06-29 08:37:42 +00:00
graph =
2020-06-29 08:37:42 +00:00
Graph.new()
|> Graph.add(description)
|> Graph.add(
2020-06-29 08:37:42 +00:00
EX.S2
|> EX.p2(EX.O3, EX.O4)
)
2020-06-29 08:37:42 +00:00
named_graph = %Graph{graph | name: iri(EX.NamedGraph)}
2020-06-29 08:37:42 +00:00
dataset =
2020-06-29 08:37:42 +00:00
Dataset.new()
|> Dataset.add(graph)
2017-06-08 19:50:46 +00:00
|> Dataset.add(
2020-06-29 08:37:42 +00:00
Graph.new(name: EX.NamedGraph)
|> Graph.add(description)
|> Graph.add({EX.S3, EX.p3(), EX.O5})
|> Graph.add({EX.S, EX.p3(), EX.O5})
)
2020-06-29 08:37:42 +00:00
{:ok, description: description, graph: graph, named_graph: named_graph, dataset: dataset}
end
2017-06-04 02:20:08 +00:00
describe "RDF.Data protocol implementation of RDF.Description" do
2017-06-08 19:50:46 +00:00
test "merge of a single triple with different subject", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(description, {EX.Other, EX.p1(), EX.O3}) ==
Graph.new(description) |> Graph.add({EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a single triple with same subject", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(description, {EX.S, EX.p1(), EX.O3}) ==
Description.add(description, {EX.S, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a single quad", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(description, {EX.Other, EX.p1(), EX.O3, EX.Graph}) ==
Dataset.new(description) |> Dataset.add({EX.Other, EX.p1(), EX.O3, EX.Graph})
assert RDF.Data.merge(description, {EX.S, EX.p1(), EX.O3, EX.Graph}) ==
Dataset.new(description) |> Dataset.add({EX.S, EX.p1(), EX.O3, EX.Graph})
2017-06-08 19:50:46 +00:00
end
test "merge of a description with different subject", %{description: description} do
assert RDF.Data.merge(description, Description.new(EX.Other, init: {EX.p1(), EX.O3})) ==
2020-06-29 08:37:42 +00:00
Graph.new(description) |> Graph.add({EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a description with same subject", %{description: description} do
assert RDF.Data.merge(description, Description.new(EX.S, init: {EX.p1(), EX.O3})) ==
2020-06-29 08:37:42 +00:00
Description.add(description, {EX.S, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a graph", %{graph: graph} do
assert RDF.Data.merge(Description.new(EX.Other, init: {EX.p1(), EX.O3}), graph) ==
2020-06-29 08:37:42 +00:00
Graph.add(graph, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a dataset", %{dataset: dataset} do
assert RDF.Data.merge(Description.new(EX.Other, init: {EX.p1(), EX.O3}), dataset) ==
2020-06-29 08:37:42 +00:00
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
2017-06-04 02:20:08 +00:00
test "delete", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(description, {EX.S, EX.p1(), EX.O2}) ==
Description.delete(description, {EX.S, EX.p1(), EX.O2})
2017-06-04 02:20:08 +00:00
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(description, {EX.Other, EX.p1(), EX.O2}) == description
2017-06-04 02:20:08 +00:00
end
2020-06-29 08:37:42 +00:00
test "deleting a Description with a different subject does nothing", %{
description: description
} do
assert RDF.Data.delete(
description,
%Description{description | subject: EX.Other}
) == description
end
2017-06-08 19:50:46 +00:00
2017-06-04 02:20:08 +00:00
test "pop", %{description: description} do
assert RDF.Data.pop(description) == Description.pop(description)
end
test "include?", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.include?(description, {EX.S, EX.p1(), EX.O2})
refute RDF.Data.include?(description, {EX.Other, EX.p1(), EX.O2})
2017-06-04 02:20:08 +00:00
end
test "describes?", %{description: description} do
assert RDF.Data.describes?(description, EX.S)
refute RDF.Data.describes?(description, EX.Other)
2017-06-04 02:20:08 +00:00
end
2017-06-05 00:48:39 +00:00
test "description when the requested subject matches the Description.subject",
2020-06-29 08:37:42 +00:00
%{description: description} do
2017-06-05 00:48:39 +00:00
assert RDF.Data.description(description, description.subject) == description
assert RDF.Data.description(description, to_string(description.subject)) == description
assert RDF.Data.description(description, EX.S) == description
end
test "description when the requested subject does not match the Description.subject",
2020-06-29 08:37:42 +00:00
%{description: description} do
assert RDF.Data.description(description, iri(EX.Other)) == Description.new(EX.Other)
2017-06-05 00:48:39 +00:00
end
2017-07-07 17:03:01 +00:00
test "descriptions", %{description: description} do
assert RDF.Data.descriptions(description) == [description]
end
test "statements", %{description: description} do
assert RDF.Data.statements(description) == Description.statements(description)
end
2017-06-04 02:20:08 +00:00
test "subjects", %{description: description} do
assert RDF.Data.subjects(description) == MapSet.new([iri(EX.S)])
2017-06-04 02:20:08 +00:00
end
test "predicates", %{description: description} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.predicates(description) == MapSet.new([EX.p1(), EX.p2(), EX.p3()])
2017-06-04 02:20:08 +00:00
end
test "objects", %{description: description} do
assert RDF.Data.objects(description) ==
2020-06-29 08:37:42 +00:00
MapSet.new([iri(EX.O1), iri(EX.O2), iri(EX.O3), ~B<foo>])
2017-06-04 02:20:08 +00:00
end
test "resources", %{description: description} do
assert RDF.Data.resources(description) ==
2020-06-29 08:37:42 +00:00
MapSet.new([
iri(EX.S),
EX.p1(),
EX.p2(),
EX.p3(),
iri(EX.O1),
iri(EX.O2),
iri(EX.O3),
~B<foo>
])
2017-06-04 02:20:08 +00:00
end
test "subject_count", %{description: description} do
assert RDF.Data.subject_count(description) == 1
end
test "statement_count", %{description: description} do
assert RDF.Data.statement_count(description) == 5
end
2018-10-28 02:50:48 +00:00
test "values", %{description: description} do
assert RDF.Data.values(description) ==
%{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p1()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [RDF.Term.value(RDF.iri(EX.O3))],
RDF.Term.value(EX.p3()) => ["bar", "_:foo"]
2018-10-28 02:50:48 +00:00
}
end
2019-04-03 23:55:34 +00:00
test "equal/2", %{description: description, graph: graph, dataset: dataset} do
assert RDF.Data.equal?(description, description)
assert RDF.Data.equal?(description, Graph.new(description))
assert RDF.Data.equal?(description, Graph.new(description, name: EX.Graph))
assert RDF.Data.equal?(description, Dataset.new(description))
refute RDF.Data.equal?(description, description |> EX.p4(EX.O4))
refute RDF.Data.equal?(description, graph)
refute RDF.Data.equal?(description, dataset)
end
2017-06-04 02:20:08 +00:00
end
describe "RDF.Data protocol implementation of RDF.Graph" do
2017-06-08 19:50:46 +00:00
test "merge of a single triple", %{graph: graph, named_graph: named_graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(graph, {EX.Other, EX.p(), EX.O}) ==
Graph.add(graph, {EX.Other, EX.p(), EX.O})
assert RDF.Data.merge(named_graph, {EX.Other, EX.p(), EX.O}) ==
Graph.add(named_graph, {EX.Other, EX.p(), EX.O})
2017-06-08 19:50:46 +00:00
end
test "merge of a single quad with the same graph context",
2020-06-29 08:37:42 +00:00
%{graph: graph, named_graph: named_graph} do
assert RDF.Data.merge(graph, {EX.Other, EX.p(), EX.O, nil}) ==
Graph.add(graph, {EX.Other, EX.p(), EX.O})
assert RDF.Data.merge(named_graph, {EX.Other, EX.p(), EX.O, EX.NamedGraph}) ==
Graph.add(named_graph, {EX.Other, EX.p(), EX.O})
2017-06-08 19:50:46 +00:00
end
test "merge of a single quad with a different graph context",
2020-06-29 08:37:42 +00:00
%{graph: graph, named_graph: named_graph} do
assert RDF.Data.merge(graph, {EX.S, EX.p1(), EX.O3, EX.NamedGraph}) ==
Dataset.new(graph) |> Dataset.add({EX.S, EX.p1(), EX.O3, EX.NamedGraph})
assert RDF.Data.merge(named_graph, {EX.S, EX.p1(), EX.O3, nil}) ==
Dataset.new(named_graph) |> Dataset.add({EX.S, EX.p1(), EX.O3, nil})
2017-06-08 19:50:46 +00:00
end
test "merge of a description", %{graph: graph} do
assert RDF.Data.merge(graph, Description.new(EX.Other, init: {EX.p1(), EX.O3})) ==
2020-06-29 08:37:42 +00:00
Graph.add(graph, {EX.Other, EX.p1(), EX.O3})
assert RDF.Data.merge(graph, Description.new(EX.S, init: {EX.p1(), EX.O3})) ==
2020-06-29 08:37:42 +00:00
Graph.add(graph, {EX.S, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a graph with the same name",
2020-06-29 08:37:42 +00:00
%{graph: graph, named_graph: named_graph} do
assert RDF.Data.merge(graph, Graph.add(graph, {EX.Other, EX.p1(), EX.O3})) ==
Graph.add(graph, {EX.Other, EX.p1(), EX.O3})
assert RDF.Data.merge(named_graph, Graph.add(named_graph, {EX.Other, EX.p1(), EX.O3})) ==
Graph.add(named_graph, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a graph with a different name",
2020-06-29 08:37:42 +00:00
%{graph: graph, named_graph: named_graph} do
2017-06-08 19:50:46 +00:00
assert RDF.Data.merge(graph, named_graph) ==
2020-06-29 08:37:42 +00:00
Dataset.new(graph) |> Dataset.add(named_graph)
2017-06-08 19:50:46 +00:00
assert RDF.Data.merge(named_graph, graph) ==
2020-06-29 08:37:42 +00:00
Dataset.new(named_graph) |> Dataset.add(graph)
2017-06-08 19:50:46 +00:00
end
test "merge of a dataset", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(Graph.new({EX.Other, EX.p1(), EX.O3}), dataset) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(Graph.new({EX.Other, EX.p1(), EX.O3}, name: EX.NamedGraph), dataset) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3, EX.NamedGraph})
end
2017-06-08 19:50:46 +00:00
test "delete", %{graph: graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(graph, {EX.S, EX.p1(), EX.O2}) ==
Graph.delete(graph, {EX.S, EX.p1(), EX.O2})
assert RDF.Data.delete(graph, {EX.Other, EX.p1(), EX.O2}) == graph
end
test "deleting a Graph with a different name does nothing", %{graph: graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(
graph,
%Graph{graph | name: EX.OtherGraph}
) == graph
end
test "pop", %{graph: graph} do
assert RDF.Data.pop(graph) == Graph.pop(graph)
end
test "include?", %{graph: graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.include?(graph, {EX.S, EX.p1(), EX.O2})
assert RDF.Data.include?(graph, {EX.S2, EX.p2(), EX.O3})
refute RDF.Data.include?(graph, {EX.Other, EX.p1(), EX.O2})
end
test "describes?", %{graph: graph} do
assert RDF.Data.describes?(graph, EX.S)
assert RDF.Data.describes?(graph, EX.S2)
refute RDF.Data.describes?(graph, EX.Other)
end
2017-06-05 00:48:39 +00:00
test "description when a description is present",
2020-06-29 08:37:42 +00:00
%{graph: graph, description: description} do
assert RDF.Data.description(graph, iri(EX.S)) == description
2017-06-05 00:48:39 +00:00
assert RDF.Data.description(graph, EX.S) == description
end
test "description when a description is not present", %{graph: graph} do
assert RDF.Data.description(graph, iri(EX.Other)) == Description.new(EX.Other)
2017-06-05 00:48:39 +00:00
end
2017-07-07 17:03:01 +00:00
test "descriptions", %{graph: graph, description: description} do
assert RDF.Data.descriptions(graph) ==
2020-06-29 08:37:42 +00:00
[description, EX.S2 |> EX.p2(EX.O3, EX.O4)]
2017-07-07 17:03:01 +00:00
end
test "statements", %{graph: graph} do
assert RDF.Data.statements(graph) == Graph.statements(graph)
end
test "subjects", %{graph: graph} do
assert RDF.Data.subjects(graph) == MapSet.new([iri(EX.S), iri(EX.S2)])
end
test "predicates", %{graph: graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.predicates(graph) == MapSet.new([EX.p1(), EX.p2(), EX.p3()])
end
test "objects", %{graph: graph} do
assert RDF.Data.objects(graph) ==
2020-06-29 08:37:42 +00:00
MapSet.new([iri(EX.O1), iri(EX.O2), iri(EX.O3), iri(EX.O4), ~B<foo>])
end
test "resources", %{graph: graph} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.resources(graph) ==
MapSet.new([
iri(EX.S),
iri(EX.S2),
EX.p1(),
EX.p2(),
EX.p3(),
iri(EX.O1),
iri(EX.O2),
iri(EX.O3),
iri(EX.O4),
~B<foo>
])
end
test "subject_count", %{graph: graph} do
assert RDF.Data.subject_count(graph) == 2
end
test "statement_count", %{graph: graph} do
assert RDF.Data.statement_count(graph) == 7
end
2018-10-28 02:50:48 +00:00
test "values", %{graph: graph} do
assert RDF.Data.values(graph) ==
%{
RDF.Term.value(RDF.iri(EX.S)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p1()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [RDF.Term.value(RDF.iri(EX.O3))],
RDF.Term.value(EX.p3()) => ["bar", "_:foo"]
2018-10-28 02:50:48 +00:00
},
RDF.Term.value(RDF.iri(EX.S2)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O3)),
RDF.Term.value(RDF.iri(EX.O4))
2020-06-29 08:37:42 +00:00
]
}
2018-10-28 02:50:48 +00:00
}
end
2019-04-03 23:55:34 +00:00
test "equal/2", %{graph: graph, description: description, dataset: dataset} do
assert RDF.Data.equal?(graph, graph)
assert RDF.Data.equal?(graph, RDF.Graph.new(graph, name: EX.Graph))
assert RDF.Data.equal?(Graph.new(description), description)
assert RDF.Data.equal?(Graph.new(description, name: EX.Graph), description)
assert RDF.Data.equal?(graph, Dataset.new(graph))
refute RDF.Data.equal?(graph, graph |> Graph.delete_descriptions(EX.S2))
refute RDF.Data.equal?(graph |> Graph.delete_descriptions(EX.S2), graph)
2019-04-03 23:55:34 +00:00
refute RDF.Data.equal?(graph, description)
refute RDF.Data.equal?(graph, dataset)
end
end
describe "RDF.Data protocol implementation of RDF.Dataset" do
2017-06-08 19:50:46 +00:00
test "merge of a single triple", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(dataset, {EX.Other, EX.p(), EX.O}) ==
Dataset.add(dataset, {EX.Other, EX.p(), EX.O})
2017-06-08 19:50:46 +00:00
end
test "merge of a single quad", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(dataset, {EX.Other, EX.p(), EX.O, nil}) ==
Dataset.add(dataset, {EX.Other, EX.p(), EX.O})
assert RDF.Data.merge(dataset, {EX.Other, EX.p(), EX.O, EX.NamedGraph}) ==
Dataset.add(dataset, {EX.Other, EX.p(), EX.O, EX.NamedGraph})
2017-06-08 19:50:46 +00:00
end
test "merge of a description", %{dataset: dataset} do
assert RDF.Data.merge(dataset, Description.new(EX.Other, init: {EX.p1(), EX.O3})) ==
2020-06-29 08:37:42 +00:00
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
end
test "merge of a graph", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(dataset, Graph.new({EX.Other, EX.p1(), EX.O3})) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
assert RDF.Data.merge(dataset, Graph.new({EX.Other, EX.p1(), EX.O3}, name: EX.NamedGraph)) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3, EX.NamedGraph})
2017-06-08 19:50:46 +00:00
end
test "merge of a dataset", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(dataset, Dataset.new({EX.Other, EX.p1(), EX.O3})) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
2017-06-08 19:50:46 +00:00
2020-06-29 08:37:42 +00:00
assert RDF.Data.merge(
dataset,
Dataset.new({EX.Other, EX.p1(), EX.O3}, name: EX.NamedDataset)
) ==
Dataset.add(dataset, {EX.Other, EX.p1(), EX.O3})
end
2017-06-08 19:50:46 +00:00
test "delete", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(dataset, {EX.S, EX.p1(), EX.O2}) ==
Dataset.delete(dataset, {EX.S, EX.p1(), EX.O2})
assert RDF.Data.delete(dataset, {EX.S3, EX.p3(), EX.O5, EX.NamedGraph}) ==
Dataset.delete(dataset, {EX.S3, EX.p3(), EX.O5, EX.NamedGraph})
assert RDF.Data.delete(dataset, {EX.Other, EX.p1(), EX.O2}) == dataset
end
test "deleting a Dataset with a different name does nothing", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.delete(
dataset,
%Dataset{dataset | name: EX.OtherDataset}
) == dataset
end
test "pop", %{dataset: dataset} do
assert RDF.Data.pop(dataset) == Dataset.pop(dataset)
end
test "include?", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.include?(dataset, {EX.S, EX.p1(), EX.O2})
assert RDF.Data.include?(dataset, {EX.S2, EX.p2(), EX.O3})
assert RDF.Data.include?(dataset, {EX.S3, EX.p3(), EX.O5, EX.NamedGraph})
refute RDF.Data.include?(dataset, {EX.Other, EX.p1(), EX.O2})
end
test "describes?", %{dataset: dataset} do
assert RDF.Data.describes?(dataset, EX.S)
assert RDF.Data.describes?(dataset, EX.S2)
assert RDF.Data.describes?(dataset, EX.S3)
refute RDF.Data.describes?(dataset, EX.Other)
end
2017-06-05 00:48:39 +00:00
test "description when a description is present",
2020-06-29 08:37:42 +00:00
%{dataset: dataset, description: description} do
description_aggregate = Description.add(description, {EX.S, EX.p3(), EX.O5})
assert RDF.Data.description(dataset, iri(EX.S)) == description_aggregate
2017-06-05 00:48:39 +00:00
assert RDF.Data.description(dataset, EX.S) == description_aggregate
end
test "description when a description is not present", %{dataset: dataset} do
assert RDF.Data.description(dataset, iri(EX.Other)) == Description.new(EX.Other)
2017-06-05 00:48:39 +00:00
end
2017-07-07 17:03:01 +00:00
test "descriptions", %{dataset: dataset, description: description} do
2020-06-29 08:37:42 +00:00
description_aggregate = Description.add(description, {EX.S, EX.p3(), EX.O5})
2017-07-07 17:03:01 +00:00
assert RDF.Data.descriptions(dataset) == [
2020-06-29 08:37:42 +00:00
description_aggregate,
EX.S2 |> EX.p2(EX.O3, EX.O4),
EX.S3 |> EX.p3(EX.O5)
]
2017-07-07 17:03:01 +00:00
end
test "statements", %{dataset: dataset} do
assert RDF.Data.statements(dataset) == Dataset.statements(dataset)
end
test "subjects", %{dataset: dataset} do
assert RDF.Data.subjects(dataset) == MapSet.new([iri(EX.S), iri(EX.S2), iri(EX.S3)])
end
test "predicates", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.predicates(dataset) == MapSet.new([EX.p1(), EX.p2(), EX.p3()])
end
test "objects", %{dataset: dataset} do
assert RDF.Data.objects(dataset) ==
2020-06-29 08:37:42 +00:00
MapSet.new([iri(EX.O1), iri(EX.O2), iri(EX.O3), iri(EX.O4), iri(EX.O5), ~B<foo>])
end
test "resources", %{dataset: dataset} do
2020-06-29 08:37:42 +00:00
assert RDF.Data.resources(dataset) ==
MapSet.new([
iri(EX.S),
iri(EX.S2),
iri(EX.S3),
EX.p1(),
EX.p2(),
EX.p3(),
iri(EX.O1),
iri(EX.O2),
iri(EX.O3),
iri(EX.O4),
iri(EX.O5),
~B<foo>
])
end
test "subject_count", %{dataset: dataset} do
assert RDF.Data.subject_count(dataset) == 3
end
test "statement_count", %{dataset: dataset} do
2017-06-05 00:48:39 +00:00
assert RDF.Data.statement_count(dataset) == 14
end
2018-10-28 02:50:48 +00:00
test "values/1", %{dataset: dataset} do
2018-10-28 02:50:48 +00:00
assert RDF.Data.values(dataset) ==
%{
nil => %{
RDF.Term.value(RDF.iri(EX.S)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p1()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [RDF.Term.value(RDF.iri(EX.O3))],
RDF.Term.value(EX.p3()) => ["bar", "_:foo"]
2018-10-28 02:50:48 +00:00
},
RDF.Term.value(RDF.iri(EX.S2)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O3)),
RDF.Term.value(RDF.iri(EX.O4))
2020-06-29 08:37:42 +00:00
]
}
2018-10-28 02:50:48 +00:00
},
RDF.Term.value(RDF.iri(EX.NamedGraph)) => %{
RDF.Term.value(RDF.iri(EX.S)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p1()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p2()) => [RDF.Term.value(RDF.iri(EX.O3))],
RDF.Term.value(EX.p3()) => ["bar", "_:foo", RDF.Term.value(RDF.iri(EX.O5))]
2018-10-28 02:50:48 +00:00
},
RDF.Term.value(RDF.iri(EX.S3)) => %{
2020-06-29 08:37:42 +00:00
RDF.Term.value(EX.p3()) => [
2018-10-28 02:50:48 +00:00
RDF.Term.value(RDF.iri(EX.O5))
2020-06-29 08:37:42 +00:00
]
}
2018-10-28 02:50:48 +00:00
}
}
end
test "map/2", %{dataset: dataset} do
mapping = fn
{:graph_name, graph_name} ->
graph_name
2020-06-29 08:37:42 +00:00
{:predicate, predicate} ->
predicate |> to_string() |> String.split("/") |> List.last() |> String.to_atom()
2020-06-29 08:37:42 +00:00
{_, term} ->
RDF.Term.value(term)
end
assert RDF.Data.map(dataset, mapping) ==
%{
nil => %{
RDF.Term.value(RDF.iri(EX.S)) => %{
p1: [
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
p2: [RDF.Term.value(RDF.iri(EX.O3))],
p3: ["bar", "_:foo"]
},
RDF.Term.value(RDF.iri(EX.S2)) => %{
p2: [
RDF.Term.value(RDF.iri(EX.O3)),
RDF.Term.value(RDF.iri(EX.O4))
2020-06-29 08:37:42 +00:00
]
}
},
RDF.iri(EX.NamedGraph) => %{
RDF.Term.value(RDF.iri(EX.S)) => %{
p1: [
RDF.Term.value(RDF.iri(EX.O1)),
RDF.Term.value(RDF.iri(EX.O2))
],
p2: [RDF.Term.value(RDF.iri(EX.O3))],
p3: ["bar", "_:foo", RDF.Term.value(RDF.iri(EX.O5))]
},
RDF.Term.value(RDF.iri(EX.S3)) => %{
p3: [
RDF.Term.value(RDF.iri(EX.O5))
2020-06-29 08:37:42 +00:00
]
}
}
}
end
2019-04-03 23:55:34 +00:00
test "equal/2", %{graph: graph, description: description, dataset: dataset} do
assert RDF.Data.equal?(dataset, dataset)
assert RDF.Data.equal?(dataset, Dataset.new(dataset, name: EX.Dataset))
assert RDF.Data.equal?(Dataset.new(description), description)
assert RDF.Data.equal?(Dataset.new(graph), graph)
assert RDF.Data.equal?(Dataset.new(graph), RDF.Graph.add_prefixes(graph, %{ex: EX}))
2020-06-29 08:37:42 +00:00
assert RDF.Data.equal?(
Dataset.new(graph)
|> Dataset.add(Graph.new(description, name: EX.Graph1, prefixes: %{ex: EX})),
Dataset.new(graph)
|> Dataset.add(Graph.new(description, name: EX.Graph1, prefixes: %{ex: RDF}))
)
2019-04-03 23:55:34 +00:00
refute RDF.Data.equal?(dataset, dataset |> Dataset.delete_graph(EX.NamedGraph))
refute RDF.Data.equal?(dataset |> Dataset.delete_graph(EX.NamedGraph), dataset)
2020-06-29 08:37:42 +00:00
refute RDF.Data.equal?(
Dataset.new(graph)
|> Dataset.add(Graph.new(description, name: EX.Graph1)),
Dataset.new(graph)
|> Dataset.add(Graph.new(description, name: EX.Graph2))
)
2019-04-03 23:55:34 +00:00
refute RDF.Data.equal?(dataset, description)
refute RDF.Data.equal?(dataset, graph)
end
end
2017-06-04 02:20:08 +00:00
end