-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.pl
1368 lines (927 loc) · 33.5 KB
/
main.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 main.pl
%% SYSTEM TUC
%% CREATED TA-930531
%% REVISED TA-110207
%% REVISED RS-131225 Modularized
%% Main program for BussTUC
%%% RS-131225, UNIT: /
%% USAGE?: :- use_module( '../main' , [ traceprint/2, track/2 ] ). %%RS-141025
% c = compile % (::)/2 is used in inger and update2.pl! How does it work? %% RS-140208 %Extra? crash/0 is used a test of SPIDER etc.
%%% RS-131225, UNIT: /
:-module( main, [ abortword/1, backslash/1, begin/0, break/1, c/1, check/0, create_taggercall/2, difact/2, %% dialog/0,
english/0, exetuc/1, fact0/1, haltword/1, idiotpoint/0, logrun/0, norsk/0, ns/1, % listxt/0, gorg/0, %% For debugging... (removed) %% RS-140928
clearport/0, closefile/1, reset_period/0, getfromport/1, % To writeout: indentprint/2 . For Dialog / Buster . %processorwait_d/1
hei/0, hi/0, ho/0, run/0, jettyrun/1, mtrprocess/1, %Remove mtrprocessweb/1, %RUN-predicates, with (very slow debugging!) and without debug. % printparse/1, language/1,
processorwait/1, r/1, readday/0, readscript/0, restart/0, reset/0, run/1,
scanfile/2, (sp)/1, spyg/1, spyr/1, status/0, testgram/0, translate2/2, tuc/0, update_compnames/1,
% to utility/writeout.pl: track/2, statistics/1 (in bustermain2)
value/1, version_date/1,
webrun_english/0, webrun_norsk/0, webrun_tele/0, write_taggercall/1, writepid/0, % verify_empty_origins/0, value/2
%For debugging
listxt/0 %% List all text-fragments currently in the chart-parser, with their indexes
] ).
%% DYNAMIC SECTION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:-volatile
difact/2, %% Dynamic, context dependent %% TA-980301
fact0/1. %% Semi permanent, in evaluate.pl
:-dynamic
difact/2, %% Dynamic, context dependent %% TA-980301
fact0/1. %% Semi permanent, in evaluate.pl
%% META-PREDICATES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%:- meta_predicate for(0,0). % for/2. Stay inside the CALLING module? %% RS-141029
:- meta_predicate sp(0).
%:- meta_predicate track(+,0) . %% RS-141026 Moved to utility/writeout.pl
%:- meta_predicate trackprog(+,0) .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UNIT: / AND /utility/
%% RS-141105 General (semantic) Operators, %helpers := /2, =: /2, set/2, value/2. set( X, Y ) is X := Y .
:- use_module( declare, [ (:=)/2, (=:)/2, set/2, track/2, trackprog/2, value/2 ] ).
:- use_module( sicstus4compatibility, [ out/1, output/1 ] ). %% Compatible with sicstus4, get0/1 etc.
:- use_module( 'utility/gps', [ reset_origins/0, transfix/2 ] ). %% RS-150119. transfix overriding translat:transfix/2
:- use_module( 'utility/utility', [ pront/1 ] ). %% RS-150119. transfix overriding translat:transfix/2
:- use_module( 'utility/writeout', [ doubt/2, prettyprint/1, print_parse_tree/1, printdots/0 ] ).%% RS-140912 %% out/1,
%Utility-functions %RS-141019 Moved to main.pl (To be accessable for the scripts.n)
%set( Key, Value ).
backslash('\\').
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for/2. Stay inside the CALLING module? %% RS-141029
%for( P, Q ) :- %% For all P, do Q (with part of P). Finally succeed
% P, Q, false ; true.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%:- meta_predicate remember(0) . %% RS-140928 Remember the facts IN THE MODULE THAT CALLS REMEMBER! Use : or 0
%remember( Module:F ) :- Module:F, ! ; assert( Module:F ). %% Add F it is does not already exist.
%remember( Setting ) :- out( 'main:remember/1 => Something went wrong with:'), output( Setting ), output( call( Setting ) ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % % % % % % % % %
%% RS-1401019 Import predicates that are used ONLY in the batch test files, to avoid error warnings....
batchfile_predicates( 'utility/utility', [ startbatch/0, starttimebatch/0, stoptimebatch/0 ] ). % pront/1, taketime/0,
:- batchfile_predicates( File, PredList ), use_module( File, PredList ), fail ; true.
%% RS-140210. SAFER to include EVERYTHING, since starttimebatch/0 IS called from \r tests/batch.n for example
% starttimebatch/0, %% RS-131225, reverse/2. Moved to lex.pl interactive: language/1, transfix/2, % for/2,
%% RS-131225, UNIT: utility/
:- use_module( 'utility/utility', [ append_atomlist/2, append_atoms/3, for/2, makestring/2, psl/2, purge/3, shell_copyfile/2, starttime/0, writelist/1 ] ). % pront/1, taketime/0, for/2, remember/1, %% LOOPS! RS-141029
:- use_module( 'utility/library', [ reverse/2, shell/1 ] ).%% RS-131225
:- use_module( 'utility/ptbwrite', [ drucke_baum/1 ] ). %% drucke_baum_list/1, , ptbwrite/1, shrink_tree/2, indentprint/2
%:- use_module( 'utility/writeout', [ track/2, trackprog/2 ] ). %% RS-150104 Move up or down to avoid warnings?
%% UNIT: EXTERNAL LIBRARIES
%:- use_module( library( aggregate ), [ foral/2 ] ). %% RS-141029 for-all/2 Does NOT work like utility:for/2
:- use_module( library( process ), [ process_id/1 ] ).
:- use_module( library( system ), [ sleep/1 ] ).
:- use_module( library( timeout ), [ time_out/3 ] ). %% RS-140210. % :-prolog_flag(gc_trace,_,verbose).
%From BusterMain2, evaluate-modules (Use them instead?)
%% COMMON CO-VERSION: BUSS & TELE difact/2, %% Dynamic,context dependent fact0/1,Semi permanent, in evaluate.pl %% TA-980301
% quit/0,% receive_tags/1,% send_taggercall/1, %% From getphonedir!
%% RS-131227 UNIT: /
:- ensure_loaded( version ). %% RS-131227 With version_date/1
:- use_module( getphonedir, [ create_tags/1 ]). %% RS-131227 send_taggercall/1, etc.
:- use_module( interfaceroute, [ reset_period/0 ] ). % Interface procedures for handling interface to route modules
%:- use_module( sicstus4compatibility, [ tab/1 ] ). %% Compatible with sicstus4, get0/1 etc.
%:- use_module( tucbuses, [ legal_language/1, readfile_extension/1, script_file/1 ] ). % , language/1, % Common File for tucbus (english) and tucbuss (norwegian)
:- use_module( sicstuc, [ language/1, legal_language/1, readfile_extension/1, script_file/1 ] ). % , language/1, % Common File for tucbus (english) and tucbuss (norwegian)
% Moved back to sicstuc
%:-use_module( xmlparser, [ xmltaggerparse/2 ] ). %% RS-140102 For getphonedir.pl etc...
%% RS-131227 UNIT: db/
%% File containing TELEDAT %% co-existing with BUSDAT
:- use_module( 'db/teledat2', [ teledbrowfile/1 ] ). %% RS-131231 , teledbtagfile/1
%% Time data for bus routes in general
:- use_module( 'db/timedat', [ create_named_dates/0 ]).
%% RS-131227 UNIT: dialog/
%:- use_module( 'dialog/checkitem2', [ trackprog/2 ] ). %% RS-130329 dialogrun0/0
%:- use_module( 'dialog/d_dialogue', [ dialog/0 ] ). %% RS-130329 dialogrun0/0
%% RS-131227 UNIT: tuc/ dcg_module %% RS-141122
%% RS-130329 Make sure (gram/lang) modules are available: 1: gram_n -> ( 2: metacomp ) -> 3: dcg_n (The same for English)
:- use_module( 'tuc/metacomp' ,[ dcg_module/1, sentence/7 ]). % makegram/0, language/1 % Common File for tucbus (english) and tucbuss ("norwegian"/norsk)
:- use_module( 'tuc/anaphors' , [ resolve/2 ] ). %% RS-131227
:- use_module( 'tuc/evaluate', [ evaluateq/1, evaluateq2/1 ] ). %% RS-131224 fact0/1 and difact/2 are is DANGEROUS? Dynimic in user:declare...
%% Moved to lex? ctxt/3, txt/3, maxl/1 %% RS-131225
%% Semi-tagger (quasi multitagger)
:-use_module( 'tuc/lex', [ decide_domain/0, lexproc3/3, maxl/1, mix/2, no_unprotected_verb/0, spread/1, unknown_words/2 ] ).
:-use_module( 'tuc/readin' ). %%, [ ask_file/1, ask_user/1, read_in/1, words/3 ]). %% Read a sentence into a list of symbols
:-use_module( 'tuc/translat', [ (=>)/2 ] ). %% RS-131227 -141026 clausifyq/2, clausifystm/1 , transfix1/2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Main program
% webstat/3. % webstat(date(2009,04,21),#sms,#tot). %% Where is this counted?
% (::)/2, %% RS-131228 For inger.pl , %% How does it work?
:-op( 1150, fx, spyg). %% spy grammar rule
:-op( 1150, fx, spyr). %% spy pragma rule
:-op( 1150, fx, sp). %% spy X,X
:-op( 1150, fx, c). %% consult file %% TA-110106
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
break(_). %% dummy for breakpoints
% c(File) :- consult(File). %% TA-110106 %% Moved down
%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 ),
parsetime_limit := 100000, %% ONLY FOR DEBUGGING
spy pragma:spy_me.
sp Module:X :- functor(X,F,_), spy F, Module:X. %% call X with spy on X
%% 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)
% even if there are unknown (but fewer) words
%% SYSTEM COMMANDS
%% Menagerie of Start commands in decreasing order of severity
readscript:-
script_file(X) ->
readscript1(X);
true.
readscript1(X):-
%%%%%%%%%%%%%%%%%%%% assert(lastday(-1,noday)),
trace := 0,
erase,
readfrom(X),
trace := 1.
% Default settings. May be redefined
initiate :- %% called at compiletime ! RS-131227
trace := 1,
maxdepth := 3,
error_phase := 0,
context_id := 1.
%%% parsetime_limit := 10000. %% Max 10 seconds for parsing
%% 45/ MegaLIPS is appropriate
tuc:-
initiate,
start.
start:-
tuc_version,
erase,
clear1,
run.
restart:-
erase,
clear,
run.
erase:-
retractall( fact0(_) ), % Semipermanent facts
skolemax := 0,
skolocon := 0,
reset.
clear:-
nodebug, % somewhat ugly
nospyall, % messages
clear1.
clear1 :-
dialog := 0,
%% Only complete queries, with defaults ( should be true/false ?)
trace :=1,
traceprog :=1,
traceans := 1,
%% queryflag := true,
%% textflag := false,
spellcheck := 1, %% restored after debug
closereadfile,
parsetime_limit := 10000, %%% <--- Same as initially// Slower server
reset.
begin :-
reset,
permanence := 1,
nl.
reset:-
dialog := 0, % moved up
% textflag := false,
retractall( difact(_,_) ), %% Only Dynamic (DIscourse) Facts
retractall( (_ => _) ),
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 :-
nl,
(seen), %% evt. read-files
dialog:=0,
reset_period,
create_named_dates, %% TA-100105
go.
logrun :-
nl,
(seen),
golog.
webrun_english :-
language:= english,
dialog := 0,
webrun ; true . % (Never gets to this point from endless loop in webrun)
webrun_norsk :-
language :=norsk,
dialog := 0,
traceprog := 3, %% EXPERIMENT DEBUG
webrun ; true . % (Never gets to this point from endless loop in webrun)
webrun_tele :-
language :=norsk,
dialog := 0,
writepid,
set_prolog_flag(fileerrors,off),
repeat,
world := real,
getfromport(L),
processorwait(L),
fail,
! ; true. %% Never reaches this point!
webrun :-
writepid,
%%write("Executing webrun"),
set_prolog_flag(fileerrors,off),
busflag:= true, %% Bustuc Application Program
queryflag := true, %% Statements are implicit queries
create_named_dates, %% TA-110615
repeat,
world := real,
reset_period, %% ---> topreg.pl
%%% reset_origins, %% reset GPS origins %% TA-110206
getfromport(L),
processorwait(L),
fail, % Never succeed, endless loop
! ; true. %% Never reaches this point!
%dialog :-
% nl,
% (seen),
% permanence := 0,
% dialog := 1,
%% queryflag := true, %% (Statements are implicit queries)
% closereadfile,
% dialogrun0. % dialog/d_dialogue.pl
%
%
hi :- % language := english,
create_named_dates,
debug,
% trace,
go.
hei :- % language:= norsk,
reset_period,
create_named_dates,
debug,
% trace,
go.
ho:-
create_named_dates,
clear,
go.
go :-
bad_language, % exit if undefined LANGUAGE
!.
go:-
permanence := 0,
restoreworld,
closereadfile,
repeat,
nl,
reset_period, %% interface_route.pl necessary here for restarts
%% reset_origins, %% reset GPS origins
origlanguage =: Lang,
doask_user(L),
language := Lang,
process(L).
% Added by MTR 2004-08-04. This predicate is called (repeatedly) from
% the TUC Transfer Protocol Daemon (TTPD).
mtrprocess(S) :-
smsflag := true,
permanence := 0,
create_named_dates, %% TA-110408 ad hoc
restoreworld,
closereadfile,
reset_period,
origlanguage =: Lang,
language := Lang,
words(L, S, []), %% RS-130331
process(L). %% NB: process ALWAYS FAILS!
%mtrprocessweb(S) :-
% smsflag := false,
% permanence := 0,
% restoreworld,
% create_named_dates, %% TA-110408 ad hoc
% closereadfile,
% reset_period,
% origlanguage =: Lang,
% language := Lang,
% words(L, S, []), %% RS-130331 "String" to tokens, straight
% process(L).
jettyrun(S) :- %% This was gone so I reimplemented it. %% TE-120207
%% psl(S,L), %% RS-130331 String to tokens, via file, calls words.
%% OR "String" to Words directly
words(L, S, []), %% RS-130331 String to tokens, straight?
L = [File|L1], %% RS-130331 Get (optional) Filename
open(File,write,Stream,[encoding('UTF-8')]), %% RS-130504
%% open(File,write,Stream,[encoding('ISO-8859-1')]), %% RS-121121
%%RS-130621 Make a separate isorun for this, to avoid conflicts between atb and busstuc.idi
set_output(Stream),
permanence := 0,
restoreworld,
create_named_dates, %% TA-110408 ad hoc
closereadfile,
reset_period,
origlanguage =: Lang,
language := Lang,
%%words(L, S, []), %% RS-130331 "String" to tokens, straight
smsflag := false, %% RS-130401, possibly re-set in the next line!
splitlang(L1,L2), %% RS-130504, handle " nor / eng " (followed by) " sms "
(process(L2);true), % Process always fails...
%% flush_output, %% RS-130401 Called from the client-side! TTPD
told.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Added by MTR 2004-08-04. This predicate is called (repeatedly) from
% the TUC Transfer Protocol Daemon (TTPD).
%mtrprocess(S) :-
% smsflag := true,
% permanence := 0,
% create_named_dates, %% TA-110408 ad hoc
% restoreworld,
% closereadfile,
% reset_period,
% origlanguage =: Lang,
% language := Lang,
% words(L, S, []),
% !,
% process(L). %% NB: process ALWAYS FAILS!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% language(L) :- value( language, L ). %% value(language,X) should have been set dynamically by now! In tucbuses?
restoreworld :-
(world =: _W_) -> true;
world := real.
golog:-
closereadfile,
repeat,
nl,
reset_period,
%% reset_origins, %% reset GPS origins %% TA-110204
doask_user(L),
writelog(L),
process(L).
end :-
(seen),
permanence:=0,
world := real.
bad_language :-
\+ language(_),
!,
nl,out(' *** No defined language! REMEMBER: compile(busstuc).'),output(' ***').
bad_language :-
language(L),
\+ legal_language(L),
!,
nl,out(' *** Undefined language: '),out(L),output(' ***').
%%%%%%%%%%%%%%%%% Other Commands
tuc_version:-
version_date(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:'), nl, listing(value/2) ) ).
testgram :-
dcg_module(DCG),
spy(DCG:sentence/6),
spy(DCG:statreal/6),
spy(DCG:do_phrase/10),
% spy(sentence/6),
% spy(statreal/6),
% spy(do_phrase/10),
spy(evaluate:qev/1),
trace := 3,
%% spellcheck :=0, %% debug makes it slow // not any longer
parsetime_limit := 100000. %% ONLY DEBUGGING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
writepid :-
process_id(Pid), %sicstus4
%sicstus4 pid(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), \+value(busflag,true),
!. %% Not Yet
redirecttoans:-
trytellans.
redirectfromans:-
value(teleflag,true), \+value(busflag,true),
!,
teledbrowfile(Rowsample0),
shell_copyfile(Rowsample0,'.ans').
redirectfromans:-
told,
!.
%% From Web
% Perl script will always add a language prefix
% SMSFLAG is set dynamically !
splitlang(L,Netto2):- %% If not prefix nor,eng assume no prefix
( L= [eng|Netto] -> ( language := english);
L= [nor|Netto] -> (language := norsk);
( Netto=L, language := norsk )
),
splitsms(Netto, Netto2) .
%%RS-130627 Separate LANG and SMS codes! Inclusive OR
%%( ENG -> english ;
%% OR NOR -> norwegian
%% OR just norwegian (default)
%% Same check for SMS -> sms OR default NO sms
splitsms(S,Netto):- %% If not prefix sms assume no sms
S= [sms|Netto] -> ( smsflag := true ) ; ( Netto=S , smsflag := false ).
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).
ns(F) :- readfrom(F). %% TA-110207 %% RS-141019 What is NorSource ?
norsource(F) :- %% TA-110207
set( norsource, true ),
readfrom(F),
set( norsource, false ).
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,
trace =: OldTrace, %% NB =:
trace := 0,
% 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),
trace := OldTrace, %% TA-090203
permanence := 0.
%% textflag := false, % Read from text, don't skip to new Line
%% queryflag := Oldqueryflag. % destroys setting in startupfile
scanfile(F,L):- %% DESTROYS web writing
see(F),
read_in(L),
(seen).
doask_user(L):-
interp := 0,
ask_user(L). %% readin.pl
process(_):-
bad_language,
!.
/************************************
process([GWB|_]):- %% Provoked Abortion
abortword(GWB),
!,
abort.
process([GWB|_]):- %% Provoked Halt
haltword(GWB),
!,
halt.
*******************************/
%¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
%% NEW %% OMNITUC !
%process_forel(FOL):-
% transfix(FOL,TQL),
% prettyprint(TQL),
%
% exetuc(TQL).
%¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
process(L):- %% Process is under a repeat loop
error_phase := 0,
language =: O1,
origlanguage := O1,
printdots, %% TA-110204
translate2(L,TQL),
nl,
( value( textflag, true ) ->
copy_term( TQL, TQLNV ), %% dont bind variables
drucke_baum(TQLNV)
; true),
%% user:track(2,gorg), %% listing gps-origins %% TA-110223
exetuc(TQL), %% Always succeed (command may change origlanguage)
norsource_postfix,
origlanguage =: O2,
language := O2, %
(TQL=end;
TQL=stop). %% Succeeds and exit when stop command.
abortword( georgewarrenbush ). %% <- Top Secret
haltword( johnforbeskerry ). %% <- Top Secret
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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),
new_origin := false, %% ugly reset explicit new_origin flag %% TA-110206
analyse2(L,TQL).
analyse2(L,Stop):-
stopcommand(L,Stop),
!.
analyse2(L,command(Rosenborg)):-
othercommand(L,Rosenborg),
!.
analyse2(L1,TQL):-
\+ value(teleflag,true),
!,
lexproc3( L1, AssumedLanguage, L2 ),
language := AssumedLanguage,
track( 4, pront(L2) ), %% TA-110218
error_phase:= 0,
layout2(L2,TQL),
print_tql(TQL), %% TA-110207
!.
analyse2(L1,TQL):-
value(teleflag,true), \+ value(busflag,true),
!,
create_tags(L1), %%% _TAGS) ,
!,
lexproc3(L1,AssumedLanguage,L2),
language := AssumedLanguage,
error_phase:= 0,
starttime,
layout2(L2,TQL),
present(1,TQL),
!.
analyse2(_,error).
print_tql(TQL):- %% TA-110207
value(norsource,true),
output('<tql> '),
!,
prettyprint(TQL),
output('</tql>').
print_tql(TQL):-
present(1,TQL).
startteleerror :-
value(teleflag,true), \+ value(busflag,true),
!,
teledbrowfile(TDBR),
%%tell(TDBR) %% RS-121121
open( TDBR, write, Stream, [encoding('UTF-8')] ),
set_output(Stream).
startteleerror :-!.
stopteleerror :-
value(teleflag,true),\+ value(busflag,true),
!,
told.
stopteleerror :-!.
grammar2( L, error ) :-
value(notimeoutflag,true),
length(L,M),M > 21, %% Temporary Emergency
!,
startteleerror,
nl,
doubt('- - - Sentence is too long and complicated - - - ',
'- - - Setningen er for lang og vanskelig - - - '),
nl,
stopteleerror.
grammar2(L,error):- % Failed with type check,
unknown_words(L,Z),
\+ (Z == []),
!, % => Incomprehensible (therefore)
startteleerror,
nl,
doubt('- - - Incomprehensible words: ', %% '-' means No Pay
'- - - Uforståelige ord '), %% Freak test AtB drops list of words
%% after : ????
%% TA-101201
writelist(Z),nl, nl, %% avoid [ ] which are rendered as blanks on some mobile
stopteleerror.
grammar2(_,FOL):-
cursor := 0,
maxl(N),
parse_sentence(P,N,Success), %% RS-141122 ( ProgramGenerated, NumberOfWords?, OK-flag )
(Success == success -> true; %% continue; else error-message
( startteleerror,
nl,
doubt('- - - Sentence is too difficult - - -', %% vague on
'- - - Setningen er for vanskelig - - -'), %% purpose
nl,
stopteleerror)
),
!, %% <------- One solution
present(4,P),
resolve(P,Q), %% (Short Circuit Scopes)
!,
present(3,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 * - - -'),