diff --git a/lib/rdf/serializations/ntriples_encoder.ex b/lib/rdf/serializations/ntriples_encoder.ex index a7bc4f1..0ae3f6f 100644 --- a/lib/rdf/serializations/ntriples_encoder.ex +++ b/lib/rdf/serializations/ntriples_encoder.ex @@ -57,6 +57,10 @@ defmodule RDF.NTriples.Encoder do to_string(bnode) end + def term({s, p, o}) do + "<< #{term(s)} #{term(p)} #{term(o)} >>" + end + @spec iolist_statement(Triple.t()) :: iolist def iolist_statement({subject, predicate, object}) do [iolist_term(subject), " ", iolist_term(predicate), " ", iolist_term(object), " .\n"] diff --git a/test/unit/ntriples_star_encoder_test.exs b/test/unit/ntriples_star_encoder_test.exs new file mode 100644 index 0000000..0599ceb --- /dev/null +++ b/test/unit/ntriples_star_encoder_test.exs @@ -0,0 +1,25 @@ +defmodule RDF.Star.NTriples.EncoderTest do + use RDF.Test.Case + + alias RDF.NTriples + + test "annotations of triples on subject position" do + assert NTriples.Encoder.encode!(graph_with_annotation()) == + """ + << "Foo" >> . + """ + end + + test "annotations of triples on object position" do + assert NTriples.Encoder.encode!( + Graph.new([ + statement(), + {EX.AS, EX.ap(), statement()}, + ]) + ) == + """ + << "Foo" >> . + "Foo" . + """ + end +end