-
Notifications
You must be signed in to change notification settings - Fork 1
/
parsing_tests.pl
executable file
·44 lines (36 loc) · 1.05 KB
/
parsing_tests.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/swipl -q -s
:- module(test_suite,[run/0,tokenise_and_parse/1,failure/1,success/1]).
/**
* Some N3 parsing tests
* (it is clearly not exhaustive though,
* so there may still be some bugs)
*/
:- use_module(n3_dcg).
% point it to your local SWAP installation
n3_dir('test/data').
:- dynamic failure/1,success/1.
run :-
forall(n3_dir(Dir),
(
nl,
format(' - Parsing N3 files available in ~w\n',[Dir]),
atom_concat(Dir,'/*.n3',Wildcard),
expand_file_name(Wildcard,Files),
forall(member(File,Files),
(
nl,format(' - Parsing ~w\n',[File]),
tokenise_and_parse(File) -> (writeln(' - Success'),assert(success(File))); (writeln(' - Failure'),assert(failure(File)))
))
)),
results.
results :-
bagof(F,failure(F),Failures),length(Failures,NF),
bagof(S,success(S),Success),length(Success,NS),
nl,
format(' - ~w files successfully parsed\n',[NS]),
format(' - ~w files not parsed\n',[NF]).
tokenise_and_parse(File) :-
tokenise(File,Tokens),
phrase(n3_dcg:document('',_Document),Tokens).
% And we run the tests
:- run, halt.