Attempto Parser APE

  1. Go to GitHub and clone the repo.
  2. In your terminal run
    ​​​ make install` in your terminal.
    ​​​ `./ape.exe -text "John waits." -cdrsxml
    

Also, following the other instruction of the readme all worked out of the box (I had swipl already installed).

Running the Parser in Prolog

We can also run the uncompiled version of ape.pl:

swipl ape.pl -text "John waits." -cdrsxml
?- ape.

To get a better idea of how ape.pl works, we can follow the execution in trace mode. [1]

swipl ape.pl -text "John waits." -cdrsxml
?- trace.
?- ape.

This allows us to enter a computation using the return-key or to skip a computation using the s-key.

If we only want to see when a predicates is called (call) and succeeds (exit) but prefer ignore the backtracking (fail and redo), we run (still in trace mode)

?- visible(-all).
?- visible(+call).
?- visible(+exit).
?- ape.

While this gives us some idea of how ape.pl works, it does not yet give us easy access to the points in the computation where the rules of the Attempto grammar are applied.

The Grammar

The Attempto grammar is in grammar.fit and was translated into a prolog file grammar.plp when we called make install. It may be instructive to compare the two files (see Appendix A). For now, we just note that, while the grammar is specified in grammar.fit, the prolog file that is actually executed is grammar.plp.

In line 47 of grammar.fit we find the Prolog predicate acetext. We can define it as a spy point and use the l-key to leap to the next call of that predicate.

?- spy(acetext).
?- ape.

Since we are not interested in actually debugging the parser, but rather in using its trace to understand the grammar, it is helpful to output the trace into a file [2] and then filter the lines that are of interest to us:

swipl ape.pl -text "John waits." -cdrsxml
?- set_prolog_flag(color_term,false).
?- leash(-all).
?- visible(-all).
?- visible(+call).
?- visible(+exit).
?- protocol("./trace.txt").
?- trace.
?- ape.
?- nodebug.
?- noprotocol.
?- halt.
less trace.txt

Appendix A: The Meaning of the Grammar Rules

For example rule 23 in grammar.fit

%-23---------------------------------------------------------------------------
% ExistentialQuestionTopic -->
%	NP[+NOM,+Q] ExistentialGlobalQuestionQuantor
%
% Example: Which code is there [?]
%------------------------------------------------------------------------------

existential_question_topic(
		display!tree![topic,NP,Quantor] &
		drs!in!DrsIn &
		drs!out!DrsOut &
		drs!id!ID
	) -->
	np(
		display!tree!NP &
		syn!head!case!<nom &
		syn!nonlocal!wh!in!<no_wh &
		syn!nonlocal!wh!out!<q &
		syn!nonlocal!gap!in![] &
		syn!nonlocal!gap!out![] &
		syn!nonlocal!subj!ref!nosubj &
		syn!head!agr!AGR &
		drs!in!DrsIn &
		drs!out!DrsOut &
		drs!scope!in!Scope &
		drs!scope!out!Scope &
		drs!id!ID
	),
	grammar_functionwords:existential_global_question_quantor(
		display!tree!Quantor &
		syn!head!agr!AGR
	).

turns into Prolog

existential_question_topic('$sign'(A,'$display'(B,[topic,C,D],E,F),G,H,I,'$drs'(J,K,L,M,N,O,P,Q),R))
-->
np('$sign'(S,'$display'(T,C,U,V),W,'$syn'(X,'$head'(Y,'$agr'(Z,A1,B1,C1),D1,'$case'(E1,'$nom'),F1,G1,H1,I1,J1,K1,L1),'$nonlocal'(M1,N1,O1,'$inout'(P1,[],[]),Q1,R1,S1,T1,U1,V1,'$whinout'(W1,'$wh'(X1,'$not_r'('$no_wh')),'$wh'(Y1,'$not_r'('$q'))),'$refagr'(Z1,nosubj,A2),B2)),C2,'$drs'(D2,K,E2,M,N,F2,G2,'$inout'(H2,I2,I2)),J2)),
grammar_functionwords:existential_global_question_quantor('$sign'(K2,'$display'(L2,D,M2,N2),O2,'$syn'(P2,'$head'(Q2,'$agr'(Z,A1,B1,C1),R2,S2,T2,U2,V2,W2,X2,Y2,Z2),A3),B3,C3,D3)).

The meaning of --> is similar to Prolog's :- and is explained in the article Definite Clause Grammar which also has generally useful background for example on context-free and context-sensitive languages. See also this tutorial.


  1. Overview of the Debugger. ↩︎

  2. I got this from stackexchange. ↩︎