I am testing a ��natural language processing program for text mining. Tagging is performed through the Common Lisp tagger library. An auxiliary Lisp program uses the result of the tagger library to generate a Prolog grammar, that does the syntactic analysis. Then the Prolog grammar is compiled to Lisp, and executed. I selected a small grammar, adapted it for yap prolog and ciao prolog, ��and tried to execute it in loop as a kind of benchmark. However the ciao prolog version works only for a small number of interactions. Here is the ciao Prolog version:
:- use_module(library(atom2term)).
%% Automatically generated code
% Modify it at your own risk
n --> [cat].
n --> [mice].
det --> [the].
vbz --> [chases].
vp --> vbz, np.
np --> n.
np --> det, n.
sentence --> np, vp.
%% End of automatically generated code
parse(_Text, 0, S, S) :- !.
parse(Text, I, S, Res) :-
�� sentence(Text, Remains),
�� length(Remains, L),
�� S1 is S+L,
�� I1 is I-1,
�� parse(Text, I1, S1, Res).
main(Argv) :-
�� �� [A|_] = Argv,
�� �� atom2term(A, N),
�� �� parse([the, cat, chases, mice, sentence], N, 0, F),
�� �� write(iterations= F), nl.
The yap version and the lisp prolog version do not have the main predicate, since one can run them from the REPL. Here is the output of yap:
~/wrk/prolog/dmn$ yap -l bench.yap
YAP 6.3.4 (i386-darwin12.2.1): Sun Jan 20 22:04:05 WET 2013
MYDDAS version MYDDAS-0.9.1
��?- time(parse([the, cat, chases, mice, sentence], 1000000, 0, Res)).
% 0.972 CPU in 0.976 seconds ( 99% CPU)
Res = 1000000
��?-
The lisp prolog version also works flawlessly:
CL-USER(16): (time (lisp-prolog (toplevel ?R) (parse '(the cat chases mice sentence) 1000000 0 ?R)))
Evaluation took:
�� 0.319 seconds of real time
�� 0.318266 seconds of total run time (0.306515 user, 0.011751 system)
�� [ Run times consist of 0.026 seconds GC time, and 0.293 seconds non-GC time. ]
�� 99.69% CPU
�� 795,066,893 processor cycles
�� 287,991,664 bytes consed
����
?R=1000000
It works even with larger numbers:
CL-USER(17): (time (lisp-prolog (toplevel ?R) (parse '(the cat chases mice sentence) 2000000 0 ?R)))
Evaluation took:
�� 0.615 seconds of real time
�� 0.613961 seconds of total run time (0.589101 user, 0.024860 system)
�� [ Run times consist of 0.054 seconds GC time, and 0.560 seconds non-GC time. ]
�� 99.84% CPU
�� 1,533,921,953 processor cycles
�� 575,995,840 bytes consed
����
?R=2000000
CL-USER(18): (time (lisp-prolog (toplevel ?R) (parse '(the cat chases mice sentence) 800000 0 ?R)))
Evaluation took:
�� 0.240 seconds of real time
�� 0.240055 seconds of total run time (0.230311 user, 0.009744 system)
�� [ Run times consist of 0.025 seconds GC time, and 0.216 seconds non-GC time. ]
�� 100.00% CPU
�� 599,822,906 processor cycles
�� 230,393,376 bytes consed
����
?R=800000
Now, ciao Prolog:
~/wrk/prolog$ ls -lia bench
12802106 -rwxr-xr-x ��1 edu500ac ��staff ��3826421 Jul 18 10:08 bench
~/wrk/prolog$ time ./bench 1000000
{ERROR: Memory allocation failed [in Realloc()]}
real 0m0.839s
user 0m0.763s
sys 0m0.073s
~/wrk/prolog$ time ./bench 800000
iterations=800000
real 0m0.777s
user 0m0.701s
sys 0m0.071s
Any suggestions? I like ciao prolog because it generates small code, compared to sbcl Lisp, or clozure Lisp. It would be great if I could increase its heap.