-
Notifications
You must be signed in to change notification settings - Fork 28
/
runape.pl
190 lines (161 loc) · 4.76 KB
/
runape.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
% This file is part of the Attempto Parsing Engine (APE).
% Copyright 2008-2013, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
%
% The Attempto Parsing Engine (APE) is free software: you can redistribute it and/or modify it
% under the terms of the GNU Lesser General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option) any later version.
%
% The Attempto Parsing Engine (APE) is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public License along with the Attempto
% Parsing Engine (APE). If not, see http://www.gnu.org/licenses/.
:- use_module(prolog/utils/drs_to_drslist).
:- use_module(prolog/parser/ace_to_drs).
:- use_module(prolog/parser/ape_utils).
:- use_module(prolog/parser/tokenizer).
:- use_module(prolog/utils/morphgen, [
acesentencelist_pp/2
]).
:- use_module(prolog/utils/is_wellformed, [
is_wellformed/1
]).
:- use_module(prolog/utils/drs_to_ascii).
:- use_module(prolog/utils/trees_to_ascii).
:- use_module(prolog/utils/drs_to_ace, [
drs_to_ace/2
]).
:- use_module(prolog/logger/error_logger, [
clear_messages/0,
get_messages/1,
is_error_message/4
]).
:- set_prolog_flag(float_format, '%.11g').
% Import the lexicons
:- style_check(-singleton).
:- style_check(-discontiguous).
:- use_module(prolog/lexicon/clex).
:- use_module(prolog/lexicon/ulex).
:- style_check(+discontiguous).
:- style_check(+singleton).
%% ape is det.
%
%
ape :-
format('
Attempto Parsing Engine for ACE 6.7~nCopyright 2008-2013, Attempto Group, University of Zurich
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions.
Please visit http://attempto.ifi.uzh.ch for details.
For help, enter "help".~n~n', []),
ape_input.
%% ape_input is det.
%
%
ape_input :-
prompt(Old, 'APE> '),
clear_messages,
ape_utils:read_text_from_commandline(Text),
prompt(_, Old),
tokenizer:tokenize(Text, TokenList),
!,
call_parser(Text, TokenList).
%% call_parser(Text:atom, Tokens:list) is det.
%
% @param Text is an ACE text or a commandline command
% @param Tokens is a list of tokens (either of the ACE text or the command)
%
call_parser(_, [Quit]) :-
(
Quit = quit
;
Quit = q
),
!,
nl, write('*** APE has been quit. ***'), nl.
call_parser(_, [help]) :-
nl, write('APE Prolog-commandline client\'s commands:'),
nl, write(' spy X - spy predicate X'),
nl, write(' gr - (re)compile grammar and contentwords'),
nl, write(' trace - switch Prolog trace-mode on'),
nl, write(' notrace - switch Prolog trace-mode off'),
nl, write(' help - show this help'),
nl, write(' quit/q - quit APE interface (relaunch with "ape.")'),
nl, nl,
!,
ape_input.
call_parser(_, [gr]) :-
style_check(-discontiguous),
style_check(-singleton),
compile('prolog/parser/grammar.plp'),
compile('prolog/parser/grammar_functionwords.plp'),
compile('prolog/parser/grammar_contentwords.plp'),
style_check(+discontiguous),
style_check(+singleton),
!,
ape_input.
call_parser(_, [trace]) :-
trace,
!,
ape_input.
call_parser(_, [notrace]) :-
notrace,
!,
ape_input.
call_parser(_, [spy, X]) :-
spy(X),
!,
ape_input.
call_parser(AceTextCodes, _) :-
atom_codes(AceText, AceTextCodes),
parse_and_format(AceText),
!,
ape_input.
call_parser(_, _) :-
ape_input.
parse_and_format(AceText) :-
ace_to_drs:aceparagraph_to_drs(AceText, Sentences, Syntaxtrees, UnresolvedDrs, Drs, Messages),
format('~w~n~n', [Sentences]),
format('Unresolved DRS:~n~n'),
drs_to_ascii(UnresolvedDrs, UnresolvedDrsAscii),
format('~w~n~n', [UnresolvedDrsAscii]),
format('DRS:~n~n'),
drs_to_ascii(Drs, DrsAscii),
format('~w~n~n', [DrsAscii]),
format('DRS List:~n~n'),
drs_to_drslist:drs_to_drslist(Drs, DrsList),
maplist(drs_to_ascii, DrsList, DrsAsciiList),
maplist(writeln, DrsAsciiList),
trees_to_ascii(Syntaxtrees, SyntaxtreesAscii),
format('~w~n~n', [SyntaxtreesAscii]),
(
is_wellformed(Drs)
->
true
;
format("WARNING: The DRS is not well-formed!!!~n~n", [])
),
drs_to_ace(Drs, AceSentenceList),
acesentencelist_pp(AceSentenceList, Paraphrase),
format('~w~n~n', [Paraphrase]),
print_messages(Messages).
%% print_messages(+MessageList:list) is det.
%
% @param MessageList is a list of messages
%
print_messages([]) :- nl.
print_messages([H | T]) :-
format('~w~n~n', [H]),
print_messages(T).
%%
%
%
%
make_ape :-
working_directory(Old, 'prolog/parser'),
compile(fit_to_plp),
working_directory(_, Old),
make.
% Note: we load the interface at startup
:- ape.