core: a RDF.Vocabulary.Namespace can be built from any RDF.Data structure

This commit is contained in:
Marcel Otto 2017-06-05 02:58:49 +02:00
parent 96447ec258
commit b72bf17d9c
3 changed files with 15 additions and 4 deletions

View file

@ -1,13 +1,12 @@
defmodule RDF.Utils.ResourceClassifier do
alias RDF.Graph # TODO: use RDF.Data instead
alias RDF.Description
@doc """
Determines if the given resource is RDF property by
"""
def property?(resource, data) do
with %Description{} = description <- Graph.description(data, resource) do
with %Description{} = description <- RDF.Data.description(data, resource) do
property_by_domain?(description) or
property_by_rdf_type?(Description.get(description, RDF.type))
end

View file

@ -472,7 +472,7 @@ defmodule RDF.Vocabulary.Namespace do
defp rdf_data_vocab_terms(data, base_uri) do
data
|> RDF.Graph.resources # TODO: support also RDF.Datasets ...
|> RDF.Data.resources
# filter URIs
|> Stream.filter(fn
%URI{} -> true

View file

@ -25,6 +25,14 @@ defmodule RDF.Vocabulary.NamespaceTest do
{~I<http://example.com/example1#Bar>, ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, ~I<http://www.w3.org/2000/01/rdf-schema#Resource>}
])
defvocab Example23,
base_uri: "http://example.com/example23#",
data: RDF.Dataset.new([
{~I<http://example.com/example23#foo>, ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>},
{~I<http://example.com/example23#Bar>, ~I<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, ~I<http://www.w3.org/2000/01/rdf-schema#Resource>, ~I<http://example.com/example23#Graph>}
])
defvocab Example2,
base_uri: "http://example.com/example2/",
file: "test/data/vocab_ns_example2.nt"
@ -213,12 +221,16 @@ defmodule RDF.Vocabulary.NamespaceTest do
describe "__terms__" do
alias TestNS.{Example1, Example5}
alias TestNS.{Example1, Example23, Example5}
test "includes all defined terms" do
assert length(Example1.__terms__) == 2
assert :foo in Example1.__terms__
assert :Bar in Example1.__terms__
assert length(Example23.__terms__) == 2
assert :foo in Example23.__terms__
assert :Bar in Example23.__terms__
end
test "includes aliases" do