core: RDF.Vocabulary.Namespaces can be constructed from NQuad files

This commit is contained in:
Marcel Otto 2017-06-10 18:02:51 +02:00
parent fd45a9ed6c
commit 7904476321
4 changed files with 31 additions and 8 deletions

View file

@ -462,7 +462,14 @@ defmodule RDF.Vocabulary.Namespace do
end
defp load_file(file) do
RDF.NTriples.read_file!(file) # TODO: support other formats
# TODO: support other formats
cond do
String.ends_with?(file, ".nt") -> RDF.NTriples.read_file!(file)
String.ends_with?(file, ".nq") -> RDF.NQuads.read_file!(file)
true ->
raise ArgumentError,
"unsupported file type for #{file}: vocabulary namespaces can currently be created from NTriple and NQuad files"
end
end
defp rdf_data_env do

View file

@ -0,0 +1,2 @@
<http://example.com/from_nquads/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
<http://example.com/from_nquads/Bar> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> <http://example.com/from_nquads/Graph>.

View file

@ -35,7 +35,11 @@ defmodule RDF.Vocabulary.NamespaceTest do
defvocab ExampleFromNTriplesFile,
base_uri: "http://example.com/from_ntriples/",
file: "test/data/vocab_ns_example2.nt"
file: "test/data/vocab_ns_example.nt"
defvocab ExampleFromNQuadsFile,
base_uri: "http://example.com/from_nquads/",
file: "test/data/vocab_ns_example.nq"
defvocab StrictExampleFromTerms,
base_uri: "http://example.com/strict_from_terms#",
@ -351,12 +355,22 @@ defmodule RDF.Vocabulary.NamespaceTest do
assert RDF.uri(Example1.foo) in Example1.__uris__
assert RDF.uri(Example1.Bar) in Example1.__uris__
alias TestNS.StrictExampleFromAliasedTerms, as: Example2
assert length(Example2.__uris__) == 4
assert RDF.uri(Example2.Term1) in Example2.__uris__
assert RDF.uri(Example2.term2) in Example2.__uris__
assert RDF.uri(Example2.Term3) in Example2.__uris__
assert RDF.uri(Example2.term4) in Example2.__uris__
alias TestNS.ExampleFromNTriplesFile, as: Example2
assert length(Example2.__uris__) == 2
assert RDF.uri(Example2.foo) in Example2.__uris__
assert RDF.uri(Example2.Bar) in Example2.__uris__
alias TestNS.ExampleFromNQuadsFile, as: Example3
assert length(Example3.__uris__) == 2
assert RDF.uri(Example3.foo) in Example3.__uris__
assert RDF.uri(Example3.Bar) in Example3.__uris__
alias TestNS.StrictExampleFromAliasedTerms, as: Example4
assert length(Example4.__uris__) == 4
assert RDF.uri(Example4.Term1) in Example4.__uris__
assert RDF.uri(Example4.term2) in Example4.__uris__
assert RDF.uri(Example4.Term3) in Example4.__uris__
assert RDF.uri(Example4.term4) in Example4.__uris__
end