Enable Turtle as an input format for vocabulary namespaces
This commit is contained in:
parent
91550909bd
commit
2017718000
4 changed files with 20 additions and 4 deletions
|
@ -183,7 +183,7 @@ defmodule YourApp.NS do
|
|||
end
|
||||
```
|
||||
|
||||
Currently only NTriple and NQuad files are supported at this place.
|
||||
Currently only N-Triples, N-Quads and Turtle files are supported at this place.
|
||||
|
||||
During compilation the terms will be validated and checked for proper capitalisation by analysing the schema description of the resp. resource in the given data.
|
||||
This validation behaviour can be modified with the `case_violations` options, which is by default set to `:warn`. By setting it explicitly to `:fail` errors will be raised during compilation or it can be turned off with `:ignore`.
|
||||
|
|
|
@ -529,11 +529,12 @@ defmodule RDF.Vocabulary.Namespace do
|
|||
defp load_file(file) do
|
||||
# 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)
|
||||
String.ends_with?(file, ".nt") -> RDF.NTriples.read_file!(file)
|
||||
String.ends_with?(file, ".nq") -> RDF.NQuads.read_file!(file)
|
||||
String.ends_with?(file, ".ttl") -> RDF.Turtle.read_file!(file)
|
||||
true ->
|
||||
raise ArgumentError,
|
||||
"unsupported file type for #{file}: vocabulary namespaces can currently be created from NTriple and NQuad files"
|
||||
"unsupported file type for #{file}: vocabulary namespaces can currently be created from NTriple, NQuad and Turtle files"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
6
test/data/vocab_ns_example.ttl
Normal file
6
test/data/vocab_ns_example.ttl
Normal file
|
@ -0,0 +1,6 @@
|
|||
@prefix : <http://example.com/from_turtle/> .
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
|
||||
:foo a rdf:Property .
|
||||
:Bar a rdfs:Resource .
|
|
@ -41,6 +41,10 @@ defmodule RDF.Vocabulary.NamespaceTest do
|
|||
base_uri: "http://example.com/from_nquads/",
|
||||
file: "test/data/vocab_ns_example.nq"
|
||||
|
||||
defvocab ExampleFromTurtleFile,
|
||||
base_uri: "http://example.com/from_turtle/",
|
||||
file: "test/data/vocab_ns_example.ttl"
|
||||
|
||||
defvocab StrictExampleFromTerms,
|
||||
base_uri: "http://example.com/strict_from_terms#",
|
||||
terms: ~w[foo Bar]
|
||||
|
@ -688,6 +692,11 @@ defmodule RDF.Vocabulary.NamespaceTest do
|
|||
assert RDF.uri(Example3.foo) in Example3.__uris__
|
||||
assert RDF.uri(Example3.Bar) in Example3.__uris__
|
||||
|
||||
alias TestNS.ExampleFromTurtleFile, as: Example4
|
||||
assert length(Example4.__uris__) == 2
|
||||
assert RDF.uri(Example4.foo) in Example4.__uris__
|
||||
assert RDF.uri(Example4.Bar) in Example4.__uris__
|
||||
|
||||
alias TestNS.StrictExampleFromAliasedTerms, as: Example4
|
||||
assert length(Example4.__uris__) == 4
|
||||
assert RDF.uri(Example4.Term1) in Example4.__uris__
|
||||
|
|
Loading…
Reference in a new issue