forked from saetre/busstuc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bustermain2.pl
1268 lines (862 loc) · 28.1 KB
/
bustermain2.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode:Prolog; coding:utf-8; -*- */
%% FILE bustermain2.pl
%% SYSTEM BUSTER
%% CREATED TA-930531
%% REVISED TA-090617
%% REVISED RS-140101 modularized
%% Try to use JUST main.pl INSTEAD?
%% COMMON CO-VERSION: BUSS & TELE
% difact/2, %% Dynamic, context dependent %% TA-980301
% fact0/1, %% Semi permanent, in evaluate.pl
% %Compilation predicates?
:-module( bustermain2, [ begin/0, break/1, c/1, check/0, create_taggercall/2, % crash/0, test on undefined predicate
dialog/0, english/0, hei/0, hi/0, ho/0, %% See d_dialogue dialogrun0/0,
indentprintlist/2, listxt/0, logrun/0, norsk/0, plustoatom/2, printparse/1, %% progtrace/2,
quit/0, r/1, readday/0, readscript/0, restart/0, run/0, run/1, %%% readscript/0,
scanfile/2, spyg/1, spyr/1, statistics/1, status/0, %% (sp)/1, %% RS-141026 Use main.pl instead!!!
testgram/0, tuc/0, update_compnames/1, %, value/1, (from declare.pl) trackprog/2,
webrun_english/0, webrun_norsk/0, webrun_tele/0, write_taggercall/1
] ).
%:- meta_predicate track(+,0) .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%:- ensure_loaded( user:'declare.pl' ). %% RS-131228 "new syntax" defs, META-preds: for/2, remember/1, value/2, :=/2, =;/2
:- use_module( declare, [ (:=)/2, (=:)/2, language/1, set/2, track/2, value/2 ] ). %% RS-141105 General (semantic) Operators, %helpers := /2, =: /2, set/2, value/2. set( X, Y ) is X := Y .
:- use_module( sicstus4compatibility, [ out/1 ] ). %% Compatible with sicstus4, get0/1 etc.
%% RS-131227, UNIT: EXTERNAL LIBRARIES
:- use_module( library(system), [ sleep/1 ] ).
:- use_module( library(timeout), [ ] ).
:- use_module( library(process), [ process_id/1 ] ). %% RS-141024
%% RS-131225, UNIT: /utility/
:- use_module('utility/utility', [ append_atomlist/2, append_atoms/3, for/2, makestring/2, pront/1, psl/2, purge/3, set_ops/3, shell_copyfile/2, starttime/0, taketime/0, timeout/3 ] ). %% RS-120816 sequence_member, etc.
:- use_module( 'utility/library', [ reverse/2, shell/1 ] ). %% RS-131225 exec/1 ] ). % RS-131227 Investigate this ;-)
%:-use_module( 'utility/datecalc', [ datetime/6 ]).%% RS-131225 For app/buslog, telelog, etc?
:- use_module( 'utility/ptbwrite', [ ptbwrite/1 ] ). %% RS-140914
:- use_module( 'utility/writeout', [ doubt/2, prettyprint/1, traceprint/2 ]).%% RS-141024 out/1, output/1, track/2,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% RS-131225, UNIT: / %% RS-131225, UNIT: utility/
% backslash( B ) :- user:backslash( B ). % RS-141024 "Imported" from declare.pl
%:-ensure_loaded( version ). %% RS-131227 With version_date/1, used in monobus -> teledat2.pl
:- use_module( busterversion, [ version_date_buster/1 ] ). %% RS-131227 With version_date/1, used in monobus -> teledat2.pl
:- use_module( 'main', [ difact/2, fact0/1, backslash/1 ] ). %(:=)/2, (=:)/2, :- use_module( 'main', [ value/2 ] ). , set/2, value/2 ] ). , language/1
%% RS-131224 calls the for-predicate %% Used in FOR from makeauxtables
:- use_module( getphonedir, [ create_tags/1, hazardous_tagname/1 ]). %% RS-131227 send_taggercall/1, hazardous_tagname/1
:- use_module( interfaceroute, [ reset_period/0 ]). % Interface procedures for handling interface to route modules
:- use_module( sicstus4compatibility ). %, [ get0/1, tab/1 ] ). %% Compatible with sicstus4, get0/1 etc.
:- use_module( sicstuc, [ legal_language/1, readfile_extension/1, script_file/1 ] ). % , language/1, % Common File for tucbus (english) and tucbuss (norwegian)
%% RS-130329 Make sure (gram/lang) modules are available: dcg_module,
%:-ensure_loaded( tucbuses ). % ,[ backslash/1, dcg_module/1, language/1, legal_language/1, readfile_extension/1, script_file/1 ]). %% RS-140211
%:-use_module( tucbuses, [ legal_language/1, readfile_extension/1, script_file/1 ]). %% RS-140211 backslash/1, dcg_module/1,
% RS-111205, UNIT: app/
:- use_module( 'app/buslog' ). % , [ station/1 ] ). %% RS-130210 called in for-predicate bound/1, bus/1,
% RS-111205, UNIT: db/
%:- use_module( 'db/places', [ corr/2, foreign/1, isat/2, placestat/2 ] ).
%:- use_module( 'db/regstr', [ streetstat/5 ] ). %% RS-131225 makeauxtables uses a for-loop with streetstat in it!!
:- use_module( 'db/teledat2', [ teledbrowfile/1 ]). %% File containing TELEDAT %% co-existing with BUSDAT
%:- use_module( 'db/timedat', [ orig_named_date/2 ]). % Called from main! %% Time data for bus routes in general
% RS-111205, UNIT: dialog/
:- use_module( 'dialog/d_dialogue.pl', [ quit_dialog/0, dialog/0 ] ). % etc.
:- use_module( 'dialog/portraycontext.pl', [ pcontext/0 ] ). % RS-141024 corr/2, foreign/1, isat/2, placestat/2
% RS-131227 UNIT: tuc/
:- use_module( 'tuc/anaphors' , [ resolve/2 ] ). %% RS-131227
:- use_module( 'tuc/evaluate', [ evaluateq/1, evaluateq2/1 ] ). %% RS-131224 fact0/1 etc. is DANGEROUS?
:- use_module( 'tuc/fernando', [ ] ). % GRUF == Grammar Utility File %% RS-131117
:- use_module( 'tuc/lex', [ ] ). % lcode1/2 is called in the for-predicate (etc.) %% RS-131225
:- use_module( 'tuc/lex', [ decide_topic/0, lexproc3/3, maxl/1, mix/2, spread/1, unknown_words/2 ] ).
:- use_module( 'tuc/metacomp', [ dcg_module/1 ] ). % genprod is called in the for-predicate (etc.) %% RS-131117
:- use_module( 'tuc/names', [ synname/2 ] ). % genprod is called in the for-predicate (etc.) %% RS-131117
% Read a sentence into a list of symbols
:- use_module( 'tuc/readin', [ ask_file/1, ask_user/1, read_in/1 ]). %% Read a sentence into a list of symbols
% ensure_loaded( 'tuc/torehash' ). % RS-131224 OBSOLETE! Moved to utility/makeauxtables!
:- use_module( 'tuc/translat', [ (=>)/2, transfix1/2 ] ). %% RS-131227 UNIT: tuc/ clausifystm/1, clausifyq/2
%:- dynamic
% ( => )/2, %% See translat.pl
% difact/2, %% Dynamic, context dependent %% TA-980301
% fact0/1. %% Semi permanent, in evaluate.pl
%:-dynamic txt/3, % elementary words %% RS-131225 Moved to lex?
% ctxt/3, % composite words
% maxl/1.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% local copy of META-PREDICATES from utility.pl
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%for(P,Q):-
% P,Q,
% false;true.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ?-prolog_flag(gc_trace,_,verbose).
break(_). %% dummy for breakpoints
% Main program
?-op(1150,fx,spyg). %% spy grammar rule
?-op(1150,fx,spyr). %% spy pragma rule
?-op(1150,fx,sp). %% spy X,X
%% ?-prolog_flag(unknown,_,fail). %% (Don't?) crash on undefined predicates
%crash :- tore_amble_is_a_genious. %% test on undefined predicate
spyg X :- dcg_module(L),
( parsetime_limit := 100000 ), %% ONLY FOR DEBUGGING
spy L:X. %% utility
spyr X :- ( debugrule := X ),
spy spy_me.
% sp X :- functor( X, F, _ ), spy F, X. %% call X with spy on X %% Use main instead!!!
statistics(G) :-
statistics(G,K),
output(K).
% Strategy for switching language
% Presume there is an assumed language from the start
% e.g. the WEB server is for a specific language (bustuc/busstuc)
% Try lexproc in the current language
% If unknown words, try the other language
% If the other language results in fewer unknown words,
% select this language TEMPORARILY (for this question)
% SYSTEM COMMANDS
% Menagerie of Start commands in decreasing order of severity
readscript:-
script_file(X) ->
readscript1(X);
true.
readscript1(X):-
( trace:=0 ),
erase,
readfrom(X),
( skolocon =: SM ), ( skolemax := SM ),
( trace := 1 ).
% Default settings. May be redefined
initiate :- %% called at compiletime !
( trace := 0 ), %% Dialog
( maxdepth:=3 ),
( error_phase:=0 ),
( context_id := 1 ),
( parsetime_limit := 10000 ). %% TA-071026
tuc:-
initiate,
start.
start:-
tuc_version,
erase,
clear1,
run.
restart:-
erase,
clear,
run.
erase:-
retractall( main:fact0(_) ), % Semipermanent facts
( skolemax := 0 ),
reset.
clear:-
nodebug, % somewhat ugly
nospyall, % messages
clear1.
clear1 :-
( dialog := 0 ),
%% Only complete queries, with defaults ( should be true/false ?)
( trace := 0 ), %% Dialog
( traceprog := 1 ),
( traceans := 1 ),
queryflag := true,
textflag := false,
( spellcheck := 1 ), %% restored after debug
closereadfile,
reset.
begin :-
reset,
( permanence := 1 ),
nl.
quit:-
value(dialog,1),
!,
retractall( main:difact(_,_) ), %% Only Dynamic Facts
retractall( main:( _ => _ ) ),
( lemmas_proved := 0 ), %%
( interp := 0 ), %%
( (skolemax =: SZ) -> (skolocon := SZ ) ; (skolocon := 0) ),
( const := 0 ),
quit_dialog. %% <---- without reply
reset:-
retractall( main:difact(_,_) ), %% Only Dynamic Facts
retractall( main:(_ => _) ),
( lemmas_proved := 0 ), %%
( interp := 0 ), %%
( (skolemax =: SZ) -> (skolocon := SZ ) ; (skolocon := 0) ),
( const := 0 ).
norsk :-
( origlanguage := norsk ), % permanently
( language := norsk ).
english :-
( origlanguage := english ), % permanently
( language := english ).
run(L):-
( language := L ),
run.
run :- %% RS-131228 Normal mode
nl,
(seen), %% evt. read-files
dialog:=0,
go.
run :-
dialog. %% RS-131228 Dialog mode?
logrun :-
nl,
(seen),
golog.
webrun_english :-
( language:= english ),
( dialog := 0 ),
webrun.
webrun_norsk :-
( language :=norsk ),
( dialog := 0 ),
webrun.
webrun_tele :-
( language :=norsk ),
( dialog := 0 ),
writepid,
set_prolog_flag(fileerrors,off),
%%% TA-060426 %% remember(lastday(-1,noday)),
repeat,
( world := real ),
getfromport(L),
processorwait(L),
fail,
! ; true. %% RS-141026 Should never get here because of the repeat, ..., fail, !
/***
webrun_dialog :- --> d_main.pl %% TA-050722
***/
webrun :-
writepid,
set_prolog_flag(fileerrors,off),
%%% TA-060426 %% remember(lastday(-1,noday)),
( busflag:= true ), %% Bustuc Application Program
( queryflag := true ), %% Statements are implicit queries
( warningflag := false ), %% if applicable
repeat,
( world := real ),
%%% resetsmsflag, %% TA-081218
reset_period, %% ---> topreg.pl
getfromport(L),
processorwait(L),
fail,
! ; true . %% RS-141026 Should never get here because of the repeat, ..., fail, !
/* %% TA-081218
resetsmsflag :-
(value(smspermanentflag,true) ->
smsflag := true;
smsflag := false).
*/
%dialog :- %% RS-131228
% nl,
% (seen),
% ( permanence := 0 ),
% ( dialog := 1 ),
% queryflag := true, %% (Statements are implicit queries)
% closereadfile,
% %%% TA-060426 %% remember(lastday(-1,noday)),
% dialogrun0.
hi :-% language := english, %% RS-131228 See dialog/d_dialogue
debug,
go.
hei:-% language:= norsk,
debug,
go.
ho:-
clear,
go.
go :-
bad_language, % exit if undefined LANGUAGE
!.
go:-
( permanence := 0 ),
restoreworld,
closereadfile,
%%% TA-060426 %% remember(lastday(-1,noday)),
repeat,
nl,
reset_period,
doask_user(L),
process(L).
restoreworld :-
( world =: _W_ ) -> true;
( world := real ).
golog:-
closereadfile,
%%% TA-060426 %% remember(lastday(-1,noday)),
repeat,
nl,
reset_period,
doask_user(L),
writelog(L),
process(L).
end :-
(seen),
( permanence:=0 ),
( world := real ).
bad_language :-
\+ language(_),
!,
nl,out(' *** No defined language! Remember: compile(buster).'),output(' ***').
bad_language :-
language(L),
\+ legal_language(L),
!,
nl,out(' *** Undefined language: '),out(L),output(' ***').
%%%%%%%%%%%%%%% Other Commands
tuc_version:-
%version_date(V), %% version.pl
version_date_buster(V), %% version.pl
nl,nl, %%
output(V).
check:- % Check consistency
evaluateq(explain:::false).
status:-
nl,output('Rules:'),nl,
for( A => B , prettyprint( A => B)),
nl,output('Facts:'),nl,
for( fact0(X), prettyprint(X)),
for( difact(UID,X), prettyprint(UID:X)),
track(2,(nl,output('Flags:'),listing(value/2))).
testgram:-
dcg_module(DCG),
spy(DCG:sentence/6),
spy(DCG:st/9),
spy(DCG:do_phrase/9),
spy(qev/1),
( trace := 3 ),
( spellcheck :=0 ), %% debug makes it slow
( parsetime_limit := 100000 ). %% ONLY DEBUGGING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
writepid :-
process_id(Pid),
open('.serverpid',write,Port),
write(Port,Pid),
close(Port).
writepid.
writelog(L) :-
open('tuclog.txt',append,Stream) ->
writets(L,Stream) ;
writeiofail.
writets(Tokens,Stream) :-
writets1(Tokens,Stream),
close(Stream).
writets1([],Stream) :-
write(Stream,'\n').
writets1([Token|Rest],Stream) :-
write(Stream,Token),
write(Stream,' '),
writets1(Rest,Stream).
writeiofail :-
write('Warning: Could not write to logfile tuclog.txt'),nl.
getfromport(L) :-
open('.port',read,Port),
( read(Port,query(L)) ; L = [] ),
close(Port),
!.
getfromport([]). % Else.
processorwait([]) :-
sleep(1),
!.
processorwait(S) :-
psl(S,L),
splitlang(L,L1),
redirecttoans,
(process(L1);true), % Process always fails...
redirectfromans,
clearport,
!.
redirecttoans:-
value(teleflag,true),
!. %% Not Yet
redirecttoans:-
trytellans.
redirectfromans:-
value(teleflag,true),
!,
teledbrowfile(Rowsample0),
shell_copyfile(Rowsample0,'.ans').
redirectfromans:-
told,
!.
% From Web
% Perl script will always add a language prefix
splitlang(L,Netto):- %% If not prefix nor,eng assume no prefix
L= [eng|Netto] -> ( language :=english );
L= [nor|Netto] -> ( language :=norsk );
L= [sms|Netto] -> ( language :=norsk );
( Netto=L, ( language := norsk ) ).
trytellans :-
%%tell('.ans') %% RS-121121
open( '.ans', write, Stream, [encoding('UTF-8')] ),
set_output(Stream).
trytellans :-
sleep(1),
trytellans. % Redo above instance until it succeeds
clearport :-
open('.port',write,Port),
write(Port,'query([]).'),
close(Port).
clearport :-
sleep(1),
clearport. % Redo above instance until it succeeds
readday:-
write('weekday ='),nl,
read(Today),
( today := Today ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c(F):-consult(F).
r(F):-readfrom(F).
closereadfile :- % if interrupted
( ( readfile =: OLD ) -> closefile(OLD);true),
(seen).
closefile(F):-
absolute_file_name(F,FS),
current_stream(FS,_,X),close(X),!;true.
% Flags may not be reset if readfrom is interrupted !
readfrom(F):-
closereadfile,
( end_of_file := false ),
readfile_extension(X),
append_atoms(F,X,FE),
( permanence := 1 ),
% textflag := true, % Read from text, don't skip to new Line
% % destroys kl. 1720 in batch queries
queryflag =: Oldqueryflag,% destroys setting in startupfile
queryflag := false, % Statements are not implicit queries
( readfile := FE ),
see(FE),
repeat,
reset_period,
ask_file(L), % readin.pl
process(L),
!,
(seen),
( permanence := 0 ),
(textflag := false), % Read from text, don't skip to new Line
queryflag := Oldqueryflag. % destroys setting in startupfile
scanfile(F,L):-
see(F),
read_in(L),
(seen).
doask_user(L):-
( interp := 0 ),
pcontext,
ask_user(L). %% readin.pl
process(_):-
bad_language,
!.
process(L):- %% Process is under a repeat loop
( error_phase := 0 ),
( language =: O1 ),
( origlanguage := O1 ),
translate2(L,TQL),
nl,
exetuc(TQL), %% Always succeed (command may change origlanguage)
( origlanguage =: O2 ),
( language := O2 ), %
(TQL=end;
TQL=stop). %% Succeeds and exit when stop command.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% translate2
%% Produces a TQL expression from a List
%% If a stop command appears, TQL = stop
%% If an end command appears, TQL = end
%% If an error occured, TQL = error
%% Otherwise, TQL = command(P).
translate2(L,TQL):-
track(1,nl),
dotline(DOTS),
traceprint(1,DOTS),
analyse2(L,TQL),
traceprint(1,DOTS),
track(1,nl),
track(2,taketime).
dotline(''):-value(smsflag,true),!.
dotline('........................................................................').
analyse2(L,Stop):-
stopcommand(L,Stop),
!.
analyse2(L,command(Rosenborg)):-
othercommand(L,Rosenborg),
!.
analyse2(L1,TQL):-
value(telebusterflag,true),
!,
set(busflag,true), %% Dynamic
set(teleflag,true), %% TA-060208
create_tags(L1), %% , _TAGS) , %% TA-060613
!,
lexproc3(L1,AssumedLanguage,L2),
( language := AssumedLanguage ),
track(3,pront(L2)), %% TA-060420
( error_phase:= 0 ),
starttime,
layout2(L2,TQL),
present(1,TQL),
!.
analyse2(L1,TQL):-
value(teleflag,true),
value(busflag,true),
!,
create_tags(L1), %%% , _TAGS) , %% TA-060613
!,
lexproc3(L1,AssumedLanguage,L2),
( language := AssumedLanguage ),
track(3,pront(L2)), %% TA-060420
( error_phase:= 0 ),
starttime,
layout2(L2,TQL),
present(1,TQL),
!.
analyse2(L1,TQL):-
value(busflag,true),
\+ value(teleflag,true),
!,
lexproc3(L1,AssumedLanguage,L2),
( language := AssumedLanguage ),
track(3,pront(L2)),
( error_phase:= 0 ),
starttime,
layout2(L2,TQL),
writeTQL(TQL), %% TA-051104
present(1,TQL),
!.
analyse2(L1,TQL):-
value(teleflag,true),
\+ value(busflag,true), %% TA-060107
!,
create_tags(L1), %%% , _TAGS) , %% TA-060613
!,
lexproc3(L1,AssumedLanguage,L2),
( language := AssumedLanguage ),
( error_phase:= 0 ),
starttime,
layout2(L2,TQL),
present(1,TQL),
!.
analyse2(_,error).
writeTQL(TQL):-
present(1,TQL).
layout2(L,TQL):-
spread(L),
decide_topic, %% TA-060107 tuc/lex.pl
manipulate_teleflag, %% until after gram %% TA-060208
track(2,listing(txt)),
track(2,nl),
( cursor := 0 ),
grammar2(L,FOL), %% let teleflag be on %% TA-060208
transfix(FOL,TQL).
% AD HOC
manipulate_teleflag :-
value(telebusterflag,true),
!,
(
value(topic,bus) ->
(set(busflag,true), %% TA-061107
set(teleflag,false));
value(topic,tele)->
(set(teleflag,true),
set(busflag,false)); %% TA-061107
value(topic,nil) ->
(set(busflag,false), %% TA-061107
set(teleflag,false)), %% <--- or teleflag=true default?
true).
manipulate_teleflag.
listxt :- listing(txt). %% TA-051101
startteleerror :-
value(teleflag,true),
!,
teledbrowfile(TDBR),
%%tell(TDBR) %% RS-121121
open( TDBR, write, Stream, [encoding('UTF-8')] ),
set_output(Stream).
startteleerror :-!.
stopteleerror :-
value(teleflag,true),
!,
told.
stopteleerror :-!.
grammar2(L,error):-
value(notimeoutflag,true),
length(L,M),M > 21,
!,
startteleerror,
nl,
doubt('- - - Sentence is too long and complicated ',
'- - - Setningen er for lang og vanskelig '),
stopteleerror.
grammar2(L,error):- % Failed with type check,
\+ value(teleflag,true), %% TA-051116 ?
unknown_words(L,Z),
\+ (Z == []),
!, % => Incomprehensible (therefore)
%% startteleerror, %% TA-051116
nl,
doubt('- - - Incomprehensible words: ', %% '-' means No Pay
'- - - Uforståelige ord: '),
nl, %% TA-050810
writeq(Z),nl, nl.
%%% stopteleerror. %% TA-051116
grammar2(_,FOL):-
( cursor := 0 ),
maxl(N),
parse_sentence(P,N,Success),
(Success == success -> true;
( startteleerror,
nl,
doubt('- - - Sentence is too difficult - - -', %% vague on
'- - - Setningen er for vanskelig - - -'), %% purpose
nl,
stopteleerror)
),
!, %% <------- One solution
present(3,P),
resolve(P,Q), %% (Short Circuit Scopes)
!,
present(2,Q),
Q = FOL.
grammar2(L,error):-
value(semantest,true),
( error_phase := 1 ), % Reset Type check
value(cursor,Attempt1),
maxl(N),
( cursor := 0 ), % Failed with type check, but
parse_sentence(_,N,success),
!, % => Meaningless (semantically)
startteleerror,
nl,
doubt('- - - Meaningless at * - - -',
'- - - Meningsløst ved * - - -'),
mix(Attempt1,L),
stopteleerror.
grammar2(L,error):- % Incomplete sentence
\+ value(teleflag,true), % not actual for tele
no_verb(L), % no verbs
!,
startteleerror,
nl,
doubt('- - - Please use a complete sentence - - -',
'- - - Vennligst bruk en fullstendig setning - - -'),
nl,
stopteleerror.
grammar2(L,error):- % Failed also with type check
value(cursor,Attempt2), % => Ungrammatical (according to gram),
nl,
startteleerror,
doubt('- - - Incomprehensible at * - - -',
'- - - Uforståelig ved * - - -'),
mix(Attempt2,L),
stopteleerror.
% % % % % %
parse_sentence(P,N,Success):- %% Parse With TimeLimit
dcg_module(G),
value(parsetime_limit,Limit),
%% output('trace1'),
timeout(
G:sentence(P,Parse,[],[],0,N),
Limit,
Success),
%% output('trace2'),
( Success == success -> Parse1=Parse;Parse1=time_out),
track(3,printparse(Parse1)), %% print proper parsetree
% TA-090617
track(2, output('*** Simplified parse tree ***')), %% TA-060906
track(2, ptbwrite(Parse1)),
track(2, (output('*****************************'),nl)).
% TA-090617
no_verb(L) :- \+ verbed_sentence(L).
verbed_sentence(L):-
member(W,L),
W = w(R,ListV),
R \== når, % = nå = now (doesn' count)
R \== nå,
R \== så,
(member(verb(_,_,_),ListV);
member([skal],ListV);
member([vil],ListV);
member([må],ListV)),
!.
present(_,nil):-!. % code printed by side effect
present(_,[nil]):-!. % code printed by side effect
present(_,[nil|_]):-!. % code printed by side effect