Skip to content

Commit

Permalink
Require rdfstar option to read directional language-tagged strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jul 26, 2023
1 parent 770861e commit 5ff4507
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/rdf/ntriples/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def read_literal
literal = case
when lang_dir = match(LANG_DIR)
language, direction = lang_dir.split('--')
raise ArgumentError if direction && !@options[:rdfstar]
RDF::Literal.new(literal_str, language: language, direction: direction)
when datatype = match(/^(\^\^)/) # FIXME
RDF::Literal.new(literal_str, datatype: read_uriref || fail_object)
Expand Down
33 changes: 22 additions & 11 deletions spec/ntriples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,27 @@
end
end

context 'parse language/direction' do
{
"language" => '<http://subj> <http://pred> "Hello"@en .',
"direction" => '<http://subj> <http://pred> "Hello"@en--ltr .',
}.each_pair do |name, triple|
specify "test #{name}" do
stmt = reader.new(triple).first
if name.include?('dir')
expect(stmt.object.datatype).to eql RDF.dirLangString
else
expect(stmt.object.datatype).to eql RDF.langString
context "base direction" do
context "without rdfstar option" do
it "Raises an error" do
expect do
expect {parse('<http://subj> <http://pred> "Hello"@en--ltr .')}.to raise_error(RDF::ReaderError)
end.to write(:something).to(:error)
end
end

context 'parse language/direction' do
{
"language" => '<http://subj> <http://pred> "Hello"@en .',
"direction" => '<http://subj> <http://pred> "Hello"@en--ltr .',
}.each_pair do |name, triple|
specify "test #{name}" do
stmt = reader.new(triple, rdfstar: true).first
if name.include?('dir')
expect(stmt.object.datatype).to eql RDF.dirLangString
else
expect(stmt.object.datatype).to eql RDF.langString
end
end
end
end
Expand Down Expand Up @@ -370,6 +380,7 @@

"Literals with languages (1)" => '<http://example.org/resource30> <http://example.org/property> "chat"@fr .',
"Literals with languages (2)" => '<http://example.org/resource31> <http://example.org/property> "chat"@en .',
# FIXME: once rdfstar option is no longer used
#"Literals with language and direction" => '<http://example.org/resource31> <http://example.org/property> "chat"@en--ltr .',
"Typed Literals" => '<http://example.org/resource32> <http://example.org/property> "abc"^^<http://example.org/datatype1> .',
"Plain lieral with embedded quote" => %q(<http://example.org/resource33> <http://example.org/property> "From \\"Voyage dans l’intérieur de l’Amérique du Nord, executé pendant les années 1832, 1833 et 1834, par le prince Maximilien de Wied-Neuwied\\" (Paris & Coblenz, 1839-1843)" .),
Expand Down

0 comments on commit 5ff4507

Please sign in to comment.