core: N-Quads serialization decoder

This commit is contained in:
Marcel Otto 2017-04-11 02:09:35 +02:00
parent 08f276ee41
commit fdead7a90f
95 changed files with 1824 additions and 1 deletions

View file

@ -0,0 +1,24 @@
defmodule RDF.NQuads do
@moduledoc """
`RDF.NQuads` provides support for reading the N-Quads serialization
format.
N-Quads is a line-based plain-text format for encoding an RDF dataset, i.e. a
collection of RDF graphs.
An example of an RDF statement in N-Quads format:
<https://hex.pm/> <http://purl.org/dc/terms/title> "Hex" <http://example.org/graphs/example> .
see <https://www.w3.org/TR/n-quads/>
"""
use RDF.Serialization
import RDF.Sigils
@id ~I<http://www.w3.org/ns/formats/N-Quads>
@extension "nq"
@content_type "application/n-quads"
end

View file

@ -0,0 +1,26 @@
defmodule RDF.NQuads.Decoder do
use RDF.Serialization.Decoder
def decode(content, _opts \\ []) do
with {:ok, tokens, _} <- tokenize(content),
{:ok, ast} <- parse(tokens) do
{:ok, build_dataset(ast)}
else
{:error, {error_line, :ntriples_lexer, error_descriptor}, _error_line_again} ->
{:error, "N-Quad scanner error on line #{error_line}: #{inspect error_descriptor}"}
{:error, {error_line, :nquads_parser, error_descriptor}} ->
{:error, "N-Quad parser error on line #{error_line}: #{inspect error_descriptor}"}
end
end
defp tokenize(content), do: content |> to_charlist |> :ntriples_lexer.string
defp parse(tokens), do: tokens |> :nquads_parser.parse
defp build_dataset(ast) do
Enum.reduce ast, RDF.Dataset.new, fn(quad, dataset) ->
RDF.Dataset.add(dataset, quad)
end
end
end

632
src/nquads_parser.erl Normal file
View file

@ -0,0 +1,632 @@
-module(nquads_parser).
-export([parse/1, parse_and_scan/1, format_error/1]).
-file("src/nquads_parser.yrl", 40).
to_uri(IRIREF) ->
case 'Elixir.RDF.Serialization.ParseHelper':to_uri(IRIREF) of
{ok, URI} -> URI;
{error, ErrorLine, Message} -> return_error(ErrorLine, Message)
end.
to_bnode(BLANK_NODE_LABEL) -> 'Elixir.RDF.Serialization.ParseHelper':to_bnode(BLANK_NODE_LABEL).
to_literal(STRING_LITERAL_QUOTE) -> 'Elixir.RDF.Serialization.ParseHelper':to_literal(STRING_LITERAL_QUOTE).
to_literal(STRING_LITERAL_QUOTE, Type) -> 'Elixir.RDF.Serialization.ParseHelper':to_literal(STRING_LITERAL_QUOTE, Type).
to_langtag(LANGTAG) -> 'Elixir.RDF.Serialization.ParseHelper':to_langtag(LANGTAG).
-file("/usr/local/Cellar/erlang/19.2/lib/erlang/lib/parsetools-2.1.4/include/yeccpre.hrl", 0).
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2015. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The parser generator will insert appropriate declarations before this line.%
-type yecc_ret() :: {'error', _} | {'ok', _}.
-spec parse(Tokens :: list()) -> yecc_ret().
parse(Tokens) ->
yeccpars0(Tokens, {no_func, no_line}, 0, [], []).
-spec parse_and_scan({function() | {atom(), atom()}, [_]}
| {atom(), atom(), [_]}) -> yecc_ret().
parse_and_scan({F, A}) ->
yeccpars0([], {{F, A}, no_line}, 0, [], []);
parse_and_scan({M, F, A}) ->
Arity = length(A),
yeccpars0([], {{fun M:F/Arity, A}, no_line}, 0, [], []).
-spec format_error(any()) -> [char() | list()].
format_error(Message) ->
case io_lib:deep_char_list(Message) of
true ->
Message;
_ ->
io_lib:write(Message)
end.
%% To be used in grammar files to throw an error message to the parser
%% toplevel. Doesn't have to be exported!
-compile({nowarn_unused_function, return_error/2}).
-spec return_error(integer(), any()) -> no_return().
return_error(Line, Message) ->
throw({error, {Line, ?MODULE, Message}}).
-define(CODE_VERSION, "1.4").
yeccpars0(Tokens, Tzr, State, States, Vstack) ->
try yeccpars1(Tokens, Tzr, State, States, Vstack)
catch
error: Error ->
Stacktrace = erlang:get_stacktrace(),
try yecc_error_type(Error, Stacktrace) of
Desc ->
erlang:raise(error, {yecc_bug, ?CODE_VERSION, Desc},
Stacktrace)
catch _:_ -> erlang:raise(error, Error, Stacktrace)
end;
%% Probably thrown from return_error/2:
throw: {error, {_Line, ?MODULE, _M}} = Error ->
Error
end.
yecc_error_type(function_clause, [{?MODULE,F,ArityOrArgs,_} | _]) ->
case atom_to_list(F) of
"yeccgoto_" ++ SymbolL ->
{ok,[{atom,_,Symbol}],_} = erl_scan:string(SymbolL),
State = case ArityOrArgs of
[S,_,_,_,_,_,_] -> S;
_ -> state_is_unknown
end,
{Symbol, State, missing_in_goto_table}
end.
yeccpars1([Token | Tokens], Tzr, State, States, Vstack) ->
yeccpars2(State, element(1, Token), States, Vstack, Token, Tokens, Tzr);
yeccpars1([], {{F, A},_Line}, State, States, Vstack) ->
case apply(F, A) of
{ok, Tokens, Endline} ->
yeccpars1(Tokens, {{F, A}, Endline}, State, States, Vstack);
{eof, Endline} ->
yeccpars1([], {no_func, Endline}, State, States, Vstack);
{error, Descriptor, _Endline} ->
{error, Descriptor}
end;
yeccpars1([], {no_func, no_line}, State, States, Vstack) ->
Line = 999999,
yeccpars2(State, '$end', States, Vstack, yecc_end(Line), [],
{no_func, Line});
yeccpars1([], {no_func, Endline}, State, States, Vstack) ->
yeccpars2(State, '$end', States, Vstack, yecc_end(Endline), [],
{no_func, Endline}).
%% yeccpars1/7 is called from generated code.
%%
%% When using the {includefile, Includefile} option, make sure that
%% yeccpars1/7 can be found by parsing the file without following
%% include directives. yecc will otherwise assume that an old
%% yeccpre.hrl is included (one which defines yeccpars1/5).
yeccpars1(State1, State, States, Vstack, Token0, [Token | Tokens], Tzr) ->
yeccpars2(State, element(1, Token), [State1 | States],
[Token0 | Vstack], Token, Tokens, Tzr);
yeccpars1(State1, State, States, Vstack, Token0, [], {{_F,_A}, _Line}=Tzr) ->
yeccpars1([], Tzr, State, [State1 | States], [Token0 | Vstack]);
yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, no_line}) ->
Line = yecctoken_end_location(Token0),
yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack],
yecc_end(Line), [], {no_func, Line});
yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, Line}) ->
yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack],
yecc_end(Line), [], {no_func, Line}).
%% For internal use only.
yecc_end({Line,_Column}) ->
{'$end', Line};
yecc_end(Line) ->
{'$end', Line}.
yecctoken_end_location(Token) ->
try erl_anno:end_location(element(2, Token)) of
undefined -> yecctoken_location(Token);
Loc -> Loc
catch _:_ -> yecctoken_location(Token)
end.
-compile({nowarn_unused_function, yeccerror/1}).
yeccerror(Token) ->
Text = yecctoken_to_string(Token),
Location = yecctoken_location(Token),
{error, {Location, ?MODULE, ["syntax error before: ", Text]}}.
-compile({nowarn_unused_function, yecctoken_to_string/1}).
yecctoken_to_string(Token) ->
try erl_scan:text(Token) of
undefined -> yecctoken2string(Token);
Txt -> Txt
catch _:_ -> yecctoken2string(Token)
end.
yecctoken_location(Token) ->
try erl_scan:location(Token)
catch _:_ -> element(2, Token)
end.
-compile({nowarn_unused_function, yecctoken2string/1}).
yecctoken2string({atom, _, A}) -> io_lib:write(A);
yecctoken2string({integer,_,N}) -> io_lib:write(N);
yecctoken2string({float,_,F}) -> io_lib:write(F);
yecctoken2string({char,_,C}) -> io_lib:write_char(C);
yecctoken2string({var,_,V}) -> io_lib:format("~s", [V]);
yecctoken2string({string,_,S}) -> io_lib:write_string(S);
yecctoken2string({reserved_symbol, _, A}) -> io_lib:write(A);
yecctoken2string({_Cat, _, Val}) -> io_lib:format("~p",[Val]);
yecctoken2string({dot, _}) -> "'.'";
yecctoken2string({'$end', _}) ->
[];
yecctoken2string({Other, _}) when is_atom(Other) ->
io_lib:write(Other);
yecctoken2string(Other) ->
io_lib:write(Other).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-file("src/nquads_parser.erl", 189).
-dialyzer({nowarn_function, yeccpars2/7}).
yeccpars2(0=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_0(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(1=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_1(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(2=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_2(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(3=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_3(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(4=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_4(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(5=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_5(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(6=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_6(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(7=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_7(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(8=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_8(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(9=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_9(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(10=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_10(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(11=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_11(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(12=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_12(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(13=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_13(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(14=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_14(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(15=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_15(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(16=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_16(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(17=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_17(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(18=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_18(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(19=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_19(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(20=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_20(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(21=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_21(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(22=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_22(S, Cat, Ss, Stack, T, Ts, Tzr);
%% yeccpars2(23=S, Cat, Ss, Stack, T, Ts, Tzr) ->
%% yeccpars2_23(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(24=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_24(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(25=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_25(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(26=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_26(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(27=S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_27(S, Cat, Ss, Stack, T, Ts, Tzr);
yeccpars2(Other, _, _, _, _, _, _) ->
erlang:error({yecc_bug,"1.4",{missing_state_in_action_table, Other}}).
yeccpars2_0(S, blank_node_label, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr);
yeccpars2_0(S, eol, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 7, Ss, Stack, T, Ts, Tzr);
yeccpars2_0(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr);
yeccpars2_0(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_0_(Stack),
yeccpars2_3(3, Cat, [0 | Ss], NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_1/7}).
yeccpars2_1(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 14, Ss, Stack, T, Ts, Tzr);
yeccpars2_1(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_2(S, eol, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 7, Ss, Stack, T, Ts, Tzr);
yeccpars2_2(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_2_(Stack),
yeccgoto_nonEmptyNquadsDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_3/7}).
yeccpars2_3(_S, '$end', _Ss, Stack, _T, _Ts, _Tzr) ->
{ok, hd(Stack)};
yeccpars2_3(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_4(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_4_(Stack),
yeccgoto_nquadsDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_5(S, blank_node_label, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr);
yeccpars2_5(S, eol, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 10, Ss, Stack, T, Ts, Tzr);
yeccpars2_5(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr);
yeccpars2_5(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_5_(Stack),
yeccgoto_nquadsDoc(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_6(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_6_(Stack),
yeccgoto_subject(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_7(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_7_(Stack),
yeccgoto_eols(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_8(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_8_(Stack),
yeccgoto_subject(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_9(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_|Nss] = Ss,
NewStack = yeccpars2_9_(Stack),
yeccgoto_nquadsDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
yeccpars2_10(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_|Nss] = Ss,
NewStack = yeccpars2_10_(Stack),
yeccgoto_eols(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
yeccpars2_11(S, blank_node_label, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 6, Ss, Stack, T, Ts, Tzr);
yeccpars2_11(S, eol, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 10, Ss, Stack, T, Ts, Tzr);
yeccpars2_11(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr);
yeccpars2_11(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_|Nss] = Ss,
NewStack = yeccpars2_11_(Stack),
yeccgoto_nonEmptyNquadsDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
yeccpars2_12(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_,_|Nss] = Ss,
NewStack = yeccpars2_12_(Stack),
yeccgoto_nonEmptyNquadsDoc(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_13/7}).
yeccpars2_13(S, blank_node_label, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 17, Ss, Stack, T, Ts, Tzr);
yeccpars2_13(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 18, Ss, Stack, T, Ts, Tzr);
yeccpars2_13(S, string_literal_quote, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 19, Ss, Stack, T, Ts, Tzr);
yeccpars2_13(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_14(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_14_(Stack),
yeccgoto_predicate(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_15/7}).
yeccpars2_15(S, '.', Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 24, Ss, Stack, T, Ts, Tzr);
yeccpars2_15(S, blank_node_label, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 25, Ss, Stack, T, Ts, Tzr);
yeccpars2_15(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 26, Ss, Stack, T, Ts, Tzr);
yeccpars2_15(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_16(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccgoto_object(hd(Ss), Cat, Ss, Stack, T, Ts, Tzr).
yeccpars2_17(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_17_(Stack),
yeccgoto_object(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_18(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_18_(Stack),
yeccgoto_object(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_19(S, '^^', Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 20, Ss, Stack, T, Ts, Tzr);
yeccpars2_19(S, langtag, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 21, Ss, Stack, T, Ts, Tzr);
yeccpars2_19(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_19_(Stack),
yeccgoto_literal(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_20/7}).
yeccpars2_20(S, iriref, Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 22, Ss, Stack, T, Ts, Tzr);
yeccpars2_20(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_21(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_|Nss] = Ss,
NewStack = yeccpars2_21_(Stack),
yeccgoto_literal(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
yeccpars2_22(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_,_|Nss] = Ss,
NewStack = yeccpars2_22_(Stack),
yeccgoto_literal(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccpars2_23/7}).
yeccpars2_23(S, '.', Ss, Stack, T, Ts, Tzr) ->
yeccpars1(S, 27, Ss, Stack, T, Ts, Tzr);
yeccpars2_23(_, _, _, _, T, _, _) ->
yeccerror(T).
yeccpars2_24(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_,_,_|Nss] = Ss,
NewStack = yeccpars2_24_(Stack),
yeccgoto_statement(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
yeccpars2_25(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_25_(Stack),
yeccgoto_graphLabel(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_26(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
NewStack = yeccpars2_26_(Stack),
yeccgoto_graphLabel(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr).
yeccpars2_27(_S, Cat, Ss, Stack, T, Ts, Tzr) ->
[_,_,_,_|Nss] = Ss,
NewStack = yeccpars2_27_(Stack),
yeccgoto_statement(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_eols/7}).
yeccgoto_eols(0, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_5(5, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_eols(2, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_11(11, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_graphLabel/7}).
yeccgoto_graphLabel(15, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_23(23, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_literal/7}).
yeccgoto_literal(13=_S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_16(_S, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_nonEmptyNquadsDoc/7}).
yeccgoto_nonEmptyNquadsDoc(0=_S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_4(_S, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_nonEmptyNquadsDoc(5=_S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_9(_S, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_nonEmptyNquadsDoc(11=_S, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_12(_S, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_nquadsDoc/7}).
yeccgoto_nquadsDoc(0, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_3(3, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_object/7}).
yeccgoto_object(13, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_15(15, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_predicate/7}).
yeccgoto_predicate(1, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_13(13, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_statement/7}).
yeccgoto_statement(0, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_statement(5, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_statement(11, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr).
-dialyzer({nowarn_function, yeccgoto_subject/7}).
yeccgoto_subject(0, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_subject(5, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr);
yeccgoto_subject(11, Cat, Ss, Stack, T, Ts, Tzr) ->
yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr).
-compile({inline,yeccpars2_0_/1}).
-file("src/nquads_parser.yrl", 9).
yeccpars2_0_(__Stack0) ->
[begin
[ ]
end | __Stack0].
-compile({inline,yeccpars2_2_/1}).
-file("src/nquads_parser.yrl", 17).
yeccpars2_2_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
[ __1 ]
end | __Stack].
-compile({inline,yeccpars2_4_/1}).
-file("src/nquads_parser.yrl", 6).
yeccpars2_4_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
[ __1 ]
end | __Stack].
-compile({inline,yeccpars2_5_/1}).
-file("src/nquads_parser.yrl", 8).
yeccpars2_5_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
[ ]
end | __Stack].
-compile({inline,yeccpars2_6_/1}).
-file("src/nquads_parser.yrl", 23).
yeccpars2_6_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_bnode ( __1 )
end | __Stack].
-compile({inline,yeccpars2_7_/1}).
-file("src/nquads_parser.yrl", 0).
yeccpars2_7_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
'$undefined'
end | __Stack].
-compile({inline,yeccpars2_8_/1}).
-file("src/nquads_parser.yrl", 22).
yeccpars2_8_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_uri ( __1 )
end | __Stack].
-compile({inline,yeccpars2_9_/1}).
-file("src/nquads_parser.yrl", 7).
yeccpars2_9_(__Stack0) ->
[__2,__1 | __Stack] = __Stack0,
[begin
[ __2 ]
end | __Stack].
-compile({inline,yeccpars2_10_/1}).
-file("src/nquads_parser.yrl", 0).
yeccpars2_10_(__Stack0) ->
[__2,__1 | __Stack] = __Stack0,
[begin
'$undefined'
end | __Stack].
-compile({inline,yeccpars2_11_/1}).
-file("src/nquads_parser.yrl", 16).
yeccpars2_11_(__Stack0) ->
[__2,__1 | __Stack] = __Stack0,
[begin
[ __1 ]
end | __Stack].
-compile({inline,yeccpars2_12_/1}).
-file("src/nquads_parser.yrl", 15).
yeccpars2_12_(__Stack0) ->
[__3,__2,__1 | __Stack] = __Stack0,
[begin
[ __1 | __3 ]
end | __Stack].
-compile({inline,yeccpars2_14_/1}).
-file("src/nquads_parser.yrl", 24).
yeccpars2_14_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_uri ( __1 )
end | __Stack].
-compile({inline,yeccpars2_17_/1}).
-file("src/nquads_parser.yrl", 26).
yeccpars2_17_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_bnode ( __1 )
end | __Stack].
-compile({inline,yeccpars2_18_/1}).
-file("src/nquads_parser.yrl", 25).
yeccpars2_18_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_uri ( __1 )
end | __Stack].
-compile({inline,yeccpars2_19_/1}).
-file("src/nquads_parser.yrl", 33).
yeccpars2_19_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_literal ( __1 )
end | __Stack].
-compile({inline,yeccpars2_21_/1}).
-file("src/nquads_parser.yrl", 32).
yeccpars2_21_(__Stack0) ->
[__2,__1 | __Stack] = __Stack0,
[begin
to_literal ( __1 , { language , to_langtag ( __2 ) } )
end | __Stack].
-compile({inline,yeccpars2_22_/1}).
-file("src/nquads_parser.yrl", 31).
yeccpars2_22_(__Stack0) ->
[__3,__2,__1 | __Stack] = __Stack0,
[begin
to_literal ( __1 , { datatype , to_uri ( __3 ) } )
end | __Stack].
-compile({inline,yeccpars2_24_/1}).
-file("src/nquads_parser.yrl", 20).
yeccpars2_24_(__Stack0) ->
[__4,__3,__2,__1 | __Stack] = __Stack0,
[begin
{ __1 , __2 , __3 }
end | __Stack].
-compile({inline,yeccpars2_25_/1}).
-file("src/nquads_parser.yrl", 29).
yeccpars2_25_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_bnode ( __1 )
end | __Stack].
-compile({inline,yeccpars2_26_/1}).
-file("src/nquads_parser.yrl", 28).
yeccpars2_26_(__Stack0) ->
[__1 | __Stack] = __Stack0,
[begin
to_uri ( __1 )
end | __Stack].
-compile({inline,yeccpars2_27_/1}).
-file("src/nquads_parser.yrl", 19).
yeccpars2_27_(__Stack0) ->
[__5,__4,__3,__2,__1 | __Stack] = __Stack0,
[begin
{ __1 , __2 , __3 , __4 }
end | __Stack].
-file("src/nquads_parser.yrl", 51).

50
src/nquads_parser.yrl Normal file
View file

@ -0,0 +1,50 @@
%% Grammar for N-Quads as specified in http://www.w3.org/TR/2014/REC-n-quads-20140225/
Nonterminals nquadsDoc nonEmptyNquadsDoc statement subject predicate object graphLabel literal eols.
Terminals iriref blank_node_label string_literal_quote langtag '^^' '.' eol.
Rootsymbol nquadsDoc.
eols -> eols eol.
eols -> eol.
nquadsDoc -> nonEmptyNquadsDoc : [ '$1'].
nquadsDoc -> eols nonEmptyNquadsDoc : [ '$2'].
nquadsDoc -> eols : [].
nquadsDoc -> '$empty' : [].
%nonEmptyNquadsDoc -> statement eol nonEmptyNquadsDoc : [ '$1' | '$3' ].
%nonEmptyNquadsDoc -> statement eol : [ '$1' ].
%nonEmptyNquadsDoc -> statement : [ '$1' ].
nonEmptyNquadsDoc -> statement eols nonEmptyNquadsDoc : [ '$1' | '$3' ].
nonEmptyNquadsDoc -> statement eols : [ '$1' ].
nonEmptyNquadsDoc -> statement : [ '$1' ].
statement -> subject predicate object graphLabel '.' : { '$1', '$2', '$3', '$4'}.
statement -> subject predicate object '.' : { '$1', '$2', '$3' }.
subject -> iriref : to_uri('$1').
subject -> blank_node_label : to_bnode('$1').
predicate -> iriref : to_uri('$1').
object -> iriref : to_uri('$1').
object -> blank_node_label : to_bnode('$1').
object -> literal : '$1'.
graphLabel -> iriref : to_uri('$1').
graphLabel -> blank_node_label : to_bnode('$1').
literal -> string_literal_quote '^^' iriref : to_literal('$1', {datatype, to_uri('$3')}).
literal -> string_literal_quote langtag : to_literal('$1', {language, to_langtag('$2')}).
literal -> string_literal_quote : to_literal('$1').
Erlang code.
to_uri(IRIREF) ->
case 'Elixir.RDF.Serialization.ParseHelper':to_uri(IRIREF) of
{ok, URI} -> URI;
{error, ErrorLine, Message} -> return_error(ErrorLine, Message)
end.
to_bnode(BLANK_NODE_LABEL) -> 'Elixir.RDF.Serialization.ParseHelper':to_bnode(BLANK_NODE_LABEL).
to_literal(STRING_LITERAL_QUOTE) -> 'Elixir.RDF.Serialization.ParseHelper':to_literal(STRING_LITERAL_QUOTE).
to_literal(STRING_LITERAL_QUOTE, Type) -> 'Elixir.RDF.Serialization.ParseHelper':to_literal(STRING_LITERAL_QUOTE, Type).
to_langtag(LANGTAG) -> 'Elixir.RDF.Serialization.ParseHelper':to_langtag(LANGTAG).

View file

@ -0,0 +1,25 @@
This README is for the W3C RDF Working Group's N-Quads test suite.
This test suite contains two kinds of tests:
Positive syntax (rdft:TestNQuadsPositiveSyntax) - an input N-Quads
file with no syntax errors.
Negative syntax (rdft:TestNQuadsNegativeSyntax) - an input N-Quads
file with at least one syntax error.
The manifest.ttl file in this directory lists tests in the
RDF WG's N-Quads test suite. All
tests have a name (mf:name) and an input (mf:action).
• An implementation passes a positive syntax test if it parses the
input.
• An implementation passes a negative syntax test if it fails to parse
the input.
The home of the test suite is <http://www.w3.org/2013/NQuadsTests/>.
See http://www.w3.org/2011/rdf-wg/wiki/RDF_Test_Suites for more details.
Eric Prud'hommeaux <eric+turtle@w3.org> - 11 June 2013.
Gregg Kellogg <gregg@greggkellogg.net> - 26 June 2013.

View file

@ -0,0 +1,5 @@
<http://example/s> <http://example/p> <http://example/o> . # comment
<http://example/s> <http://example/p> _:o . # comment
<http://example/s> <http://example/p> "o" . # comment
<http://example/s> <http://example/p> "o"^^<http://example/dt> . # comment
<http://example/s> <http://example/p> "o"@en . # comment

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "chat"@en .

View file

@ -0,0 +1 @@
<http://example.org/ex#a> <http://example.org/ex#b> "Cheers"@en-UK .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "x" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\t\u000B\u000C\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> " !\"#$%&():;<=>?@[]^_`{|}~" .

Binary file not shown.

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "x\"\"y" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "x''y" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\b" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\r" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\t" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\f" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\n" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\\" .

View file

@ -0,0 +1 @@
<http://example.org/ns#s> <http://example.org/ns#p1> "test-\\" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "€߿ࠀ࿿က쿿퀀퟿<ED9FBF>𐀀𿿽񀀀󿿽􀀀􏿽" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "x\"y" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\u006F" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "\U0000006F" .

View file

@ -0,0 +1 @@
<http://a.example/s> <http://a.example/p> "x'y" .

View file

@ -0,0 +1,695 @@
# N-Quads Syntax tests
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix qt: <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
@prefix rdft: <http://www.w3.org/ns/rdftest#> .
<> a mf:Manifest ;
mf:name "N-Quads tests" ;
mf:entries
(
<#nq-syntax-uri-01>
<#nq-syntax-uri-02>
<#nq-syntax-uri-03>
<#nq-syntax-uri-04>
<#nq-syntax-uri-05>
<#nq-syntax-uri-06>
<#nq-syntax-bnode-01>
<#nq-syntax-bnode-02>
<#nq-syntax-bnode-03>
<#nq-syntax-bnode-04>
<#nq-syntax-bnode-05>
<#nq-syntax-bnode-06>
<#nq-syntax-bad-literal-01>
<#nq-syntax-bad-literal-02>
<#nq-syntax-bad-literal-03>
<#nq-syntax-bad-uri-01>
<#nq-syntax-bad-quint-01>
<#nt-syntax-file-01>
<#nt-syntax-file-02>
<#nt-syntax-file-03>
<#nt-syntax-uri-01>
<#nt-syntax-uri-02>
<#nt-syntax-uri-03>
<#nt-syntax-uri-04>
<#nt-syntax-string-01>
<#nt-syntax-string-02>
<#nt-syntax-string-03>
<#nt-syntax-str-esc-01>
<#nt-syntax-str-esc-02>
<#nt-syntax-str-esc-03>
<#nt-syntax-bnode-01>
<#nt-syntax-bnode-02>
<#nt-syntax-bnode-03>
<#nt-syntax-datatypes-01>
<#nt-syntax-datatypes-02>
<#nt-syntax-bad-uri-01>
<#nt-syntax-bad-uri-02>
<#nt-syntax-bad-uri-03>
<#nt-syntax-bad-uri-04>
<#nt-syntax-bad-uri-05>
<#nt-syntax-bad-uri-06>
<#nt-syntax-bad-uri-07>
<#nt-syntax-bad-uri-08>
<#nt-syntax-bad-uri-09>
<#nt-syntax-bad-prefix-01>
<#nt-syntax-bad-base-01>
<#nt-syntax-bad-struct-01>
<#nt-syntax-bad-struct-02>
<#nt-syntax-bad-lang-01>
<#nt-syntax-bad-esc-01>
<#nt-syntax-bad-esc-02>
<#nt-syntax-bad-esc-03>
<#nt-syntax-bad-string-01>
<#nt-syntax-bad-string-02>
<#nt-syntax-bad-string-03>
<#nt-syntax-bad-string-04>
<#nt-syntax-bad-string-05>
<#nt-syntax-bad-string-06>
<#nt-syntax-bad-string-07>
<#nt-syntax-bad-num-01>
<#nt-syntax-bad-num-02>
<#nt-syntax-bad-num-03>
<#nt-syntax-subm-01>
<#comment_following_triple>
<#literal>
<#literal_all_controls>
<#literal_all_punctuation>
<#literal_ascii_boundaries>
<#literal_with_2_dquotes>
<#literal_with_2_squotes>
<#literal_with_BACKSPACE>
<#literal_with_CARRIAGE_RETURN>
<#literal_with_CHARACTER_TABULATION>
<#literal_with_dquote>
<#literal_with_FORM_FEED>
<#literal_with_LINE_FEED>
<#literal_with_numeric_escape4>
<#literal_with_numeric_escape8>
<#literal_with_REVERSE_SOLIDUS>
<#literal_with_REVERSE_SOLIDUS2>
<#literal_with_squote>
<#literal_with_UTF8_boundaries>
<#langtagged_string>
<#lantag_with_subtag>
<#minimal_whitespace>
) .
<#nq-syntax-uri-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-01" ;
rdfs:comment "URI graph with URI triple" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-01.nq> ;
.
<#nq-syntax-uri-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-02" ;
rdfs:comment "URI graph with BNode subject" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-02.nq> ;
.
<#nq-syntax-uri-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-03" ;
rdfs:comment "URI graph with BNode object" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-03.nq> ;
.
<#nq-syntax-uri-04> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-04" ;
rdfs:comment "URI graph with simple literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-04.nq> ;
.
<#nq-syntax-uri-05> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-05" ;
rdfs:comment "URI graph with language tagged literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-05.nq> ;
.
<#nq-syntax-uri-06> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-uri-06" ;
rdfs:comment "URI graph with datatyped literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-uri-06.nq> ;
.
<#nq-syntax-bnode-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-01" ;
rdfs:comment "BNode graph with URI triple" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-01.nq> ;
.
<#nq-syntax-bnode-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-02" ;
rdfs:comment "BNode graph with BNode subject" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-02.nq> ;
.
<#nq-syntax-bnode-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-03" ;
rdfs:comment "BNode graph with BNode object" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-03.nq> ;
.
<#nq-syntax-bnode-04> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-04" ;
rdfs:comment "BNode graph with simple literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-04.nq> ;
.
<#nq-syntax-bnode-05> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-05" ;
rdfs:comment "BNode graph with language tagged literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-05.nq> ;
.
<#nq-syntax-bnode-06> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nq-syntax-bnode-06" ;
rdfs:comment "BNode graph with datatyped literal" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bnode-06.nq> ;
.
<#nq-syntax-bad-literal-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nq-syntax-bad-literal-01" ;
rdfs:comment "Graph name may not be a simple literal (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bad-literal-01.nq> ;
.
<#nq-syntax-bad-literal-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nq-syntax-bad-literal-02" ;
rdfs:comment "Graph name may not be a language tagged literal (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bad-literal-02.nq> ;
.
<#nq-syntax-bad-literal-03> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nq-syntax-bad-literal-03" ;
rdfs:comment "Graph name may not be a datatyped literal (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bad-literal-03.nq> ;
.
<#nq-syntax-bad-uri-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nq-syntax-bad-uri-01" ;
rdfs:comment "Graph name URI must be absolute (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bad-uri-01.nq> ;
.
<#nq-syntax-bad-quint-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nq-syntax-bad-quint-01" ;
rdfs:comment "N-Quads does not have a fifth element (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nq-syntax-bad-quint-01.nq> ;
.
<#nt-syntax-file-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-file-01" ;
rdfs:comment "Empty file" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-file-01.nq> ;
.
<#nt-syntax-file-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-file-02" ;
rdfs:comment "Only comment" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-file-02.nq> ;
.
<#nt-syntax-file-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-file-03" ;
rdfs:comment "One comment, one empty line" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-file-03.nq> ;
.
<#nt-syntax-uri-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-uri-01" ;
rdfs:comment "Only IRIs" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-uri-01.nq> ;
.
<#nt-syntax-uri-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-uri-02" ;
rdfs:comment "IRIs with Unicode escape" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-uri-02.nq> ;
.
<#nt-syntax-uri-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-uri-03" ;
rdfs:comment "IRIs with long Unicode escape" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-uri-03.nq> ;
.
<#nt-syntax-uri-04> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-uri-04" ;
rdfs:comment "Legal IRIs" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-uri-04.nq> ;
.
<#nt-syntax-string-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-string-01" ;
rdfs:comment "string literal" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-string-01.nq> ;
.
<#nt-syntax-string-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-string-02" ;
rdfs:comment "langString literal" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-string-02.nq> ;
.
<#nt-syntax-string-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-string-03" ;
rdfs:comment "langString literal with region" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-string-03.nq> ;
.
<#nt-syntax-str-esc-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-str-esc-01" ;
rdfs:comment "string literal with escaped newline" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-str-esc-01.nq> ;
.
<#nt-syntax-str-esc-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-str-esc-02" ;
rdfs:comment "string literal with Unicode escape" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-str-esc-02.nq> ;
.
<#nt-syntax-str-esc-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-str-esc-03" ;
rdfs:comment "string literal with long Unicode escape" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-str-esc-03.nq> ;
.
<#nt-syntax-bnode-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-bnode-01" ;
rdfs:comment "bnode subject" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bnode-01.nq> ;
.
<#nt-syntax-bnode-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-bnode-02" ;
rdfs:comment "bnode object" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bnode-02.nq> ;
.
<#nt-syntax-bnode-03> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-bnode-03" ;
rdfs:comment "Blank node labels may start with a digit" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bnode-03.nq> ;
.
<#nt-syntax-datatypes-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-datatypes-01" ;
rdfs:comment "xsd:byte literal" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-datatypes-01.nq> ;
.
<#nt-syntax-datatypes-02> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-datatypes-02" ;
rdfs:comment "integer as xsd:string" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-datatypes-02.nq> ;
.
<#nt-syntax-bad-uri-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-01" ;
rdfs:comment "Bad IRI : space (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-01.nq> ;
.
<#nt-syntax-bad-uri-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-02" ;
rdfs:comment "Bad IRI : bad escape (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-02.nq> ;
.
<#nt-syntax-bad-uri-03> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-03" ;
rdfs:comment "Bad IRI : bad long escape (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-03.nq> ;
.
<#nt-syntax-bad-uri-04> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-04" ;
rdfs:comment "Bad IRI : character escapes not allowed (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-04.nq> ;
.
<#nt-syntax-bad-uri-05> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-05" ;
rdfs:comment "Bad IRI : character escapes not allowed (2) (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-05.nq> ;
.
<#nt-syntax-bad-uri-06> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-06" ;
rdfs:comment "Bad IRI : relative IRI not allowed in subject (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-06.nq> ;
.
<#nt-syntax-bad-uri-07> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-07" ;
rdfs:comment "Bad IRI : relative IRI not allowed in predicate (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-07.nq> ;
.
<#nt-syntax-bad-uri-08> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-08" ;
rdfs:comment "Bad IRI : relative IRI not allowed in object (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-08.nq> ;
.
<#nt-syntax-bad-uri-09> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-uri-09" ;
rdfs:comment "Bad IRI : relative IRI not allowed in datatype (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-uri-09.nq> ;
.
<#nt-syntax-bad-prefix-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-prefix-01" ;
rdfs:comment "@prefix not allowed in n-triples (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-prefix-01.nq> ;
.
<#nt-syntax-bad-base-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-base-01" ;
rdfs:comment "@base not allowed in N-Triples (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-base-01.nq> ;
.
<#nt-syntax-bad-struct-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-struct-01" ;
rdfs:comment "N-Triples does not have objectList (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-struct-01.nq> ;
.
<#nt-syntax-bad-struct-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-struct-02" ;
rdfs:comment "N-Triples does not have predicateObjectList (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-struct-02.nq> ;
.
<#nt-syntax-bad-lang-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-lang-01" ;
rdfs:comment "langString with bad lang (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-lang-01.nq> ;
.
<#nt-syntax-bad-esc-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-esc-01" ;
rdfs:comment "Bad string escape (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-esc-01.nq> ;
.
<#nt-syntax-bad-esc-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-esc-02" ;
rdfs:comment "Bad string escape (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-esc-02.nq> ;
.
<#nt-syntax-bad-esc-03> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-esc-03" ;
rdfs:comment "Bad string escape (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-esc-03.nq> ;
.
<#nt-syntax-bad-string-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-01" ;
rdfs:comment "mismatching string literal open/close (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-01.nq> ;
.
<#nt-syntax-bad-string-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-02" ;
rdfs:comment "mismatching string literal open/close (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-02.nq> ;
.
<#nt-syntax-bad-string-03> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-03" ;
rdfs:comment "single quotes (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-03.nq> ;
.
<#nt-syntax-bad-string-04> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-04" ;
rdfs:comment "long single string literal (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-04.nq> ;
.
<#nt-syntax-bad-string-05> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-05" ;
rdfs:comment "long double string literal (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-05.nq> ;
.
<#nt-syntax-bad-string-06> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-06" ;
rdfs:comment "string literal with no end (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-06.nq> ;
.
<#nt-syntax-bad-string-07> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-string-07" ;
rdfs:comment "string literal with no start (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-string-07.nq> ;
.
<#nt-syntax-bad-num-01> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-num-01" ;
rdfs:comment "no numbers in N-Triples (integer) (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-num-01.nq> ;
.
<#nt-syntax-bad-num-02> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-num-02" ;
rdfs:comment "no numbers in N-Triples (decimal) (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-num-02.nq> ;
.
<#nt-syntax-bad-num-03> a rdft:TestNQuadsNegativeSyntax ;
mf:name "nt-syntax-bad-num-03" ;
rdfs:comment "no numbers in N-Triples (float) (negative test)" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-bad-num-03.nq> ;
.
<#nt-syntax-subm-01> a rdft:TestNQuadsPositiveSyntax ;
mf:name "nt-syntax-subm-01" ;
rdfs:comment "Submission test from Original RDF Test Cases" ;
rdft:approval rdft:Approved ;
mf:action <nt-syntax-subm-01.nq> ;
.
<#comment_following_triple> a rdft:TestNQuadsPositiveSyntax ;
mf:name "comment_following_triple" ;
rdfs:comment "Tests comments after a triple" ;
rdft:approval rdft:Approved ;
mf:action <comment_following_triple.nq> ;
.
<#literal_ascii_boundaries> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_ascii_boundaries" ;
rdfs:comment "literal_ascii_boundaries '\\x00\\x26\\x28...'" ;
rdft:approval rdft:Approved ;
mf:action <literal_ascii_boundaries.nq> ;
.
<#literal_with_UTF8_boundaries> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_UTF8_boundaries" ;
rdfs:comment "literal_with_UTF8_boundaries '\\x80\\x7ff\\x800\\xfff...'" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_UTF8_boundaries.nq> ;
.
<#literal_all_controls> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_all_controls" ;
rdfs:comment "literal_all_controls '\\x00\\x01\\x02\\x03\\x04...'" ;
rdft:approval rdft:Approved ;
rdft:approval rdft:Approved ;
mf:action <literal_all_controls.nq> ;
.
<#literal_all_punctuation> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_all_punctuation" ;
rdfs:comment "literal_all_punctuation '!\"#$%&()...'" ;
rdft:approval rdft:Approved ;
rdft:approval rdft:Approved ;
mf:action <literal_all_punctuation.nq> ;
.
<#literal_with_squote> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_squote" ;
rdfs:comment "literal with squote \"x'y\"" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_squote.nq> ;
.
<#literal_with_2_squotes> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_2_squotes" ;
rdfs:comment "literal with 2 squotes \"x''y\"" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_2_squotes.nq> ;
.
<#literal> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal" ;
rdfs:comment "literal \"\"\"x\"\"\"" ;
rdft:approval rdft:Approved ;
mf:action <literal.nq> ;
.
<#literal_with_dquote> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_dquote" ;
rdfs:comment 'literal with dquote "x\"y"' ;
rdft:approval rdft:Approved ;
mf:action <literal_with_dquote.nq> ;
.
<#literal_with_2_dquotes> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_2_dquotes" ;
rdfs:comment "literal with 2 squotes \"\"\"a\"\"b\"\"\"" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_2_dquotes.nq> ;
.
<#literal_with_REVERSE_SOLIDUS2> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_REVERSE_SOLIDUS2" ;
rdfs:comment "REVERSE SOLIDUS at end of literal" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_REVERSE_SOLIDUS2.nq> ;
.
<#literal_with_CHARACTER_TABULATION> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_CHARACTER_TABULATION" ;
rdfs:comment "literal with CHARACTER TABULATION" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_CHARACTER_TABULATION.nq> ;
.
<#literal_with_BACKSPACE> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_BACKSPACE" ;
rdfs:comment "literal with BACKSPACE" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_BACKSPACE.nq> ;
.
<#literal_with_LINE_FEED> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_LINE_FEED" ;
rdfs:comment "literal with LINE FEED" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_LINE_FEED.nq> ;
.
<#literal_with_CARRIAGE_RETURN> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_CARRIAGE_RETURN" ;
rdfs:comment "literal with CARRIAGE RETURN" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_CARRIAGE_RETURN.nq> ;
.
<#literal_with_FORM_FEED> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_FORM_FEED" ;
rdfs:comment "literal with FORM FEED" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_FORM_FEED.nq> ;
.
<#literal_with_REVERSE_SOLIDUS> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_REVERSE_SOLIDUS" ;
rdfs:comment "literal with REVERSE SOLIDUS" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_REVERSE_SOLIDUS.nq> ;
.
<#literal_with_numeric_escape4> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_numeric_escape4" ;
rdfs:comment "literal with numeric escape4 \\u" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_numeric_escape4.nq> ;
.
<#literal_with_numeric_escape8> a rdft:TestNQuadsPositiveSyntax ;
mf:name "literal_with_numeric_escape8" ;
rdfs:comment "literal with numeric escape8 \\U" ;
rdft:approval rdft:Approved ;
mf:action <literal_with_numeric_escape8.nq> ;
.
<#langtagged_string> a rdft:TestNQuadsPositiveSyntax ;
mf:name "langtagged_string" ;
rdfs:comment "langtagged string \"x\"@en" ;
rdft:approval rdft:Approved ;
mf:action <langtagged_string.nq> ;
.
<#lantag_with_subtag> a rdft:TestNQuadsPositiveSyntax ;
mf:name "lantag_with_subtag" ;
rdfs:comment "lantag with subtag \"x\"@en-us" ;
rdft:approval rdft:Approved ;
mf:action <lantag_with_subtag.nq> ;
.
<#minimal_whitespace> a rdft:TestNQuadsPositiveSyntax ;
mf:name "minimal_whitespace" ;
rdfs:comment "tests absense of whitespace between subject, predicate, object and end-of-statement" ;
rdft:approval rdft:Approved ;
mf:action <minimal_whitespace.nq> ;
.

View file

@ -0,0 +1,6 @@
<http://example/s><http://example/p><http://example/o>.
<http://example/s><http://example/p>"Alice".
<http://example/s><http://example/p>_:o.
_:s<http://example/p><http://example/o>.
_:s<http://example/p>"Alice".
_:s<http://example/p>_:bnode1.

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> "o" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> "o"@en .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> "o"^^<http://www.w3.org/2001/XMLSchema#string> .

View file

@ -0,0 +1,2 @@
# N-Quads rejects a quint
<http://example/s> <http://example/p> <http://example/o> <http://example/g> <http://example/n> .

View file

@ -0,0 +1,2 @@
# No relative IRIs in N-Quads
<http://example/s> <http://example/p> <http://example/o> <g>.

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> _:g .

View file

@ -0,0 +1 @@
_:s <http://example/p> <http://example/o> _:g .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> _:o _:g .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o" _:g .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o"@en _:g .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o"^^<http://www.w3.org/2001/XMLSchema#string> _:g .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> <http://example/g> .

View file

@ -0,0 +1 @@
_:s <http://example/p> <http://example/o> <http://example/g> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> _:o <http://example/g> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o" <http://example/g> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o"@en <http://example/g> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "o"^^<http://www.w3.org/2001/XMLSchema#string> <http://example/g> .

View file

@ -0,0 +1 @@
@base <http://example/> .

View file

@ -0,0 +1,2 @@
# Bad string escape
<http://example/s> <http://example/p> "a\zb" .

View file

@ -0,0 +1,2 @@
# Bad string escape
<http://example/s> <http://example/p> "\uWXYZ" .

View file

@ -0,0 +1,2 @@
# Bad string escape
<http://example/s> <http://example/p> "\U0000WXYZ" .

View file

@ -0,0 +1,2 @@
# Bad lang tag
<http://example/s> <http://example/p> "string"@1 .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> 1 .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> 1.0 .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> 1.0e0 .

View file

@ -0,0 +1 @@
@prefix : <http://example/> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "abc' .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> 1.0 .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> 1.0e1 .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> '''abc''' .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> """abc""" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "abc .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> abc" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o>, <http://example/o2> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o>; <http://example/p2>, <http://example/o2> .

View file

@ -0,0 +1,2 @@
# Bad IRI : space.
<http://example/ space> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# Bad IRI : bad escape
<http://example/\u00ZZ11> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# Bad IRI : bad escape
<http://example/\U00ZZ1111> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# Bad IRI : character escapes not allowed.
<http://example/\n> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# Bad IRI : character escapes not allowed.
<http://example/\/> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# No relative IRIs in N-Triples
<s> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# No relative IRIs in N-Triples
<http://example/s> <p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# No relative IRIs in N-Triples
<http://example/s> <http://example/p> <o> .

View file

@ -0,0 +1,2 @@
# No relative IRIs in N-Triples
<http://example/s> <http://example/p> "foo"^^<dt> .

View file

@ -0,0 +1 @@
_:a <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
<http://example/s> <http://example/p> _:a .
_:a <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
<http://example/s> <http://example/p> _:1a .
_:1a <http://example/p> <http://example/o> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "123"^^<http://www.w3.org/2001/XMLSchema#byte> .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "123"^^<http://www.w3.org/2001/XMLSchema#string> .

View file

@ -0,0 +1 @@
#Empty file.

View file

@ -0,0 +1,2 @@
#One comment, one empty line.

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "a\n" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "a\u0020b" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "a\U00000020b" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "string" .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "string"@en .

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> "string"@en-uk .

View file

@ -0,0 +1,79 @@
#
# Copyright World Wide Web Consortium, (Massachusetts Institute of
# Technology, Institut National de Recherche en Informatique et en
# Automatique, Keio University).
#
# All Rights Reserved.
#
# Please see the full Copyright clause at
# <http://www.w3.org/Consortium/Legal/copyright-software.html>
#
# Test file with a variety of legal N-Triples
#
# Dave Beckett - http://purl.org/net/dajobe/
#
# $Id: test.nt,v 1.7 2003/10/06 15:52:19 dbeckett2 Exp $
#
#####################################################################
# comment lines
# comment line after whitespace
# empty blank line, then one with spaces and tabs
<http://example.org/resource1> <http://example.org/property> <http://example.org/resource2> .
_:anon <http://example.org/property> <http://example.org/resource2> .
<http://example.org/resource2> <http://example.org/property> _:anon .
# spaces and tabs throughout:
<http://example.org/resource3> <http://example.org/property> <http://example.org/resource2> .
# line ending with CR NL (ASCII 13, ASCII 10)
<http://example.org/resource4> <http://example.org/property> <http://example.org/resource2> .
# 2 statement lines separated by single CR (ASCII 10)
<http://example.org/resource5> <http://example.org/property> <http://example.org/resource2> .
<http://example.org/resource6> <http://example.org/property> <http://example.org/resource2> .
# All literal escapes
<http://example.org/resource7> <http://example.org/property> "simple literal" .
<http://example.org/resource8> <http://example.org/property> "backslash:\\" .
<http://example.org/resource9> <http://example.org/property> "dquote:\"" .
<http://example.org/resource10> <http://example.org/property> "newline:\n" .
<http://example.org/resource11> <http://example.org/property> "return\r" .
<http://example.org/resource12> <http://example.org/property> "tab:\t" .
# Space is optional before final .
<http://example.org/resource13> <http://example.org/property> <http://example.org/resource2>.
<http://example.org/resource14> <http://example.org/property> "x".
<http://example.org/resource15> <http://example.org/property> _:anon.
# \u and \U escapes
# latin small letter e with acute symbol \u00E9 - 3 UTF-8 bytes #xC3 #A9
<http://example.org/resource16> <http://example.org/property> "\u00E9" .
# Euro symbol \u20ac - 3 UTF-8 bytes #xE2 #x82 #xAC
<http://example.org/resource17> <http://example.org/property> "\u20AC" .
# resource18 test removed
# resource19 test removed
# resource20 test removed
# XML Literals as Datatyped Literals
<http://example.org/resource21> <http://example.org/property> ""^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource22> <http://example.org/property> " "^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource23> <http://example.org/property> "x"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource23> <http://example.org/property> "\""^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource24> <http://example.org/property> "<a></a>"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource25> <http://example.org/property> "a <b></b>"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource26> <http://example.org/property> "a <b></b> c"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource26> <http://example.org/property> "a\n<b></b>\nc"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource27> <http://example.org/property> "chat"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
# resource28 test removed 2003-08-03
# resource29 test removed 2003-08-03
# Plain literals with languages
<http://example.org/resource30> <http://example.org/property> "chat"@fr .
<http://example.org/resource31> <http://example.org/property> "chat"@en .
# Typed Literals
<http://example.org/resource32> <http://example.org/property> "abc"^^<http://example.org/datatype1> .
# resource33 test removed 2003-08-03

View file

@ -0,0 +1 @@
<http://example/s> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# x53 is capital S
<http://example/\u0053> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# x53 is capital S
<http://example/\U00000053> <http://example/p> <http://example/o> .

View file

@ -0,0 +1,2 @@
# IRI with all chars in it.
<http://example/s> <http://example/p> <scheme:!$%25&'()*+,-./0123456789:/@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~?#> .

View file

@ -0,0 +1,178 @@
defmodule RDF.NQuads.DecoderTest do
use ExUnit.Case, async: false
doctest RDF.NQuads.Decoder
alias RDF.{Dataset, TestData}
import RDF.Sigils
use RDF.Vocabulary.Namespace
defvocab EX,
base_uri: "http://example.org/#",
terms: [], strict: false
defvocab P,
base_uri: "http://www.perceive.net/schemas/relationship/",
terms: [], strict: false
@w3c_nquads_test_suite Path.join(TestData.dir, "N-QUADS-TESTS")
test "an empty string is deserialized to an empty graph" do
assert RDF.NQuads.Decoder.decode!("") == Dataset.new
assert RDF.NQuads.Decoder.decode!(" \n\r\r\n ") == Dataset.new
end
test "decoding comments" do
assert RDF.NQuads.Decoder.decode!("# just a comment") == Dataset.new
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> _:1 <http://example.org/#G>. # a comment
""") == Dataset.new({EX.S, EX.p, RDF.bnode("1"), EX.G})
assert RDF.NQuads.Decoder.decode!("""
# a comment
<http://example.org/#S> <http://example.org/#p> <http://example.org/#O> <http://example.org/#G>.
""") == Dataset.new({EX.S, EX.p, EX.O, EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> <http://example.org/#O> <http://example.org/#G>.
# a comment
""") == Dataset.new({EX.S, EX.p, EX.O, EX.G})
assert RDF.NQuads.Decoder.decode!("""
# Header line 1
# Header line 2
<http://example.org/#S1> <http://example.org/#p1> <http://example.org/#O1> <http://example.org/#G> .
# 1st comment
<http://example.org/#S1> <http://example.org/#p2> <http://example.org/#O2> . # 2nd comment
# last comment
""") == Dataset.new([
{EX.S1, EX.p1, EX.O1, EX.G},
{EX.S1, EX.p2, EX.O2},
])
end
test "empty lines" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green_goblin> <http://example.org/graphs/spiderman> .
""") == Dataset.new({EX.spiderman, P.enemyOf, EX.green_goblin, ~I<http://example.org/graphs/spiderman>})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green_goblin> <http://example.org/graphs/spiderman> .
""") == Dataset.new({EX.spiderman, P.enemyOf, EX.green_goblin, ~I<http://example.org/graphs/spiderman>})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S1> <http://example.org/#p1> <http://example.org/#O1> .
<http://example.org/#S1> <http://example.org/#p2> <http://example.org/#O2> <http://example.org/#G> .
""") == Dataset.new([
{EX.S1, EX.p1, EX.O1},
{EX.S1, EX.p2, EX.O2, EX.G},
])
end
test "decoding a single statement with uris" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green_goblin> .
""") == Dataset.new({EX.spiderman, P.enemyOf, EX.green_goblin})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green_goblin> <http://example.org/graphs/spiderman>.
""") == Dataset.new({EX.spiderman, P.enemyOf, EX.green_goblin, ~I<http://example.org/graphs/spiderman>})
end
test "decoding a single statement with a blank node" do
assert RDF.NQuads.Decoder.decode!("""
_:foo <http://example.org/#p> <http://example.org/#O> <http://example.org/#G> .
""") == Dataset.new({RDF.bnode("foo"), EX.p, EX.O, EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> _:1 <http://example.org/#G> .
""") == Dataset.new({EX.S, EX.p, RDF.bnode("1"), EX.G})
assert RDF.NQuads.Decoder.decode!("""
_:foo <http://example.org/#p> _:bar <http://example.org/#G> .
""") == Dataset.new({RDF.bnode("foo"), EX.p, RDF.bnode("bar"), EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> _:1 _:G .
""") == Dataset.new({EX.S, EX.p, RDF.bnode("1"), RDF.bnode("G")})
end
test "decoding a single statement with an untyped string literal" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> "Peter Parker" <http://example.org/#G> .
""") == Dataset.new({EX.spiderman, P.realname, RDF.literal("Peter Parker"), EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> "Peter Parker" .
""") == Dataset.new({EX.spiderman, P.realname, RDF.literal("Peter Parker")})
end
test "decoding a single statement with a typed literal" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://example.org/#p> "42"^^<http://www.w3.org/2001/XMLSchema#integer> <http://example.org/#G> .
""") == Dataset.new({EX.spiderman, EX.p, RDF.literal(42), EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#spiderman> <http://example.org/#p> "42"^^<http://www.w3.org/2001/XMLSchema#integer> .
""") == Dataset.new({EX.spiderman, EX.p, RDF.literal(42)})
end
test "decoding a single statement with a language tagged literal" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> "foo"@en <http://example.org/#G> .
""") == Dataset.new({EX.S, EX.p, RDF.literal("foo", language: "en"), EX.G})
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S> <http://example.org/#p> "foo"@en .
""") == Dataset.new({EX.S, EX.p, RDF.literal("foo", language: "en")})
end
test "decoding multiple statements" do
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S1> <http://example.org/#p1> <http://example.org/#O1> <http://example.org/#G> .
<http://example.org/#S1> <http://example.org/#p2> <http://example.org/#O2> <http://example.org/#G> .
""") == Dataset.new([
{EX.S1, EX.p1, EX.O1, EX.G},
{EX.S1, EX.p2, EX.O2, EX.G},
])
assert RDF.NQuads.Decoder.decode!("""
<http://example.org/#S1> <http://example.org/#p1> <http://example.org/#O1> <http://example.org/#G> .
<http://example.org/#S1> <http://example.org/#p2> <http://example.org/#O2> <http://example.org/#G> .
<http://example.org/#S2> <http://example.org/#p3> <http://example.org/#O3> <http://example.org/#G> .
<http://example.org/#S2> <http://example.org/#p3> <http://example.org/#O3> .
""") == Dataset.new([
{EX.S1, EX.p1, EX.O1, EX.G},
{EX.S1, EX.p2, EX.O2, EX.G},
{EX.S2, EX.p3, EX.O3, EX.G},
{EX.S2, EX.p3, EX.O3}
])
end
describe "the official W3C RDF 1.1 N-Quads Test Suite" do
# from https://www.w3.org/2013/N-QuadsTests/
ExUnit.Case.register_attribute __ENV__, :nq_test
@w3c_nquads_test_suite
|> File.ls!
|> Enum.filter(fn (file) -> Path.extname(file) == ".nq" end)
|> Enum.each(fn (file) ->
@nq_test file: Path.join(@w3c_nquads_test_suite, file)
if file |> String.contains?("-bad-") do
test "Negative syntax test: #{file}", context do
assert {:error, _} = RDF.NQuads.read_file(context.registered.nq_test[:file])
end
else
test "Positive syntax test: #{file}", context do
assert {:ok, %RDF.Dataset{}} = RDF.NQuads.read_file(context.registered.nq_test[:file])
end
end
end)
end
end

View file

@ -78,7 +78,7 @@ defmodule RDF.NTriples.DecoderTest do
])
end
test "decoding a single triple uris" do
test "decoding a single triple with uris" do
assert RDF.NTriples.Decoder.decode!("""
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green_goblin> .
""") == Graph.new({EX.spiderman, P.enemyOf, EX.green_goblin})