-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathANALYZER
1742 lines (1485 loc) · 86.5 KB
/
ANALYZER
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
(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)
(FILECREATED " 9-Mar-89 15:24:58" {ERINYES}<LISPUSERS>MEDLEY>ANALYZER.;9 86708
changes to%: (FNS Analyzer.ReadWordList)
previous date%: "13-Jan-89 15:50:22" {ERINYES}<LISPUSERS>MEDLEY>ANALYZER.;8)
(* "
Copyright (c) 1985, 1986, 1987, 1988, 1989 by Xerox Corporation. All rights reserved.
")
(PRETTYCOMPRINT ANALYZERCOMS)
(RPAQQ ANALYZERCOMS
[(COMS
(* ;;; "THE ANALYZER CLASS")
(RECORDS Morphalyzer)
(* ;; "renamed record to avoid a conflict.")
(MACROS Analyzer.Open Analyzer.Close Analyzer.Corrections Analyzer.Proofread
Analyzer.Analyze Analyzer.Lookup Analyzer.FindWord Analyzer.AddEntry
Dict.DisplayEntry)
(* ;; "MACROS that call apply the methods of the analyzer class.")
(FNS AnalyzerFromName Analyzer.CountWords Analyzer.DefaultCorrections
Analyzer.DefaultNextWord Analyzer.Name Analyzer.DefaultAddEntry
Analyzer.DefaultAnalyze Analyzer.DefaultProofread)
(* ;;
"Functions implementing the default case for various methods of the analyzer class.")
(FNS Analyzer.DefaultLoadWordList Analyzer.DefaultStoreWordList Analyzer.ReadWordList
Analyzer.WriteWordList CREATEWORDLISTRDTBL)
(INITVARS WORDLISTRDTBL)
(FNS Analyzer.Prop Analyzer.PushProp)
(MACROS Analyzer.AlphaCharP \Analyzer.TestCorruption Analyzer.Capitalization
Analyzer.UCaseP)
(* ;; "Service MACROS.")
(FNS STREAM.FETCHSTRING)
(MACROS Stream.Init Stream.NextChar)
(FNS Analyzer.CorruptWord)
(GLOBALVARS WORDLISTRDTBL))
[COMS
(* ;;; "TEDIT interface to analyzer.")
(FNS Analyzer.Establish AnalyzerForStream Analyzer.QuitFn Analyzer.BeforeLogout)
(FNS TEdit.ProofreadMenu PROOFREADER.WHENSELECTEDFN WITH-TEDIT TEdit.Correct
TEdit.CountWords TEdit.AddEntry TEdit.Proofread TEdit.SetAnalyzer
TEdit.LoadWordList TEdit.StoreWordList Analyzer.TEditMenuItems)
(INITVARS Analyzer.List Proofreader.AutoCorrect (Proofreader.AutoDelete T)
(Proofreader.MenuEdge 'LEFT)
Analyzer.TimeProofreader Proofreader.UserFns)
(GLOBALVARS Analyzer.List Proofreader.AutoCorrect Proofreader.AutoDelete
Proofreader.MenuEdge Analyzer.TimeProofreader Proofreader.UserFns)
(P (Analyzer.TEditMenuItems)
(COND ((NOT (FASSOC 'Analyzer.BeforeLogout BEFORELOGOUTFORMS))
(push BEFORELOGOUTFORMS '(Analyzer.BeforeLogout]
(COMS
(* ;;; "THE Dict CLASS")
(RECORDS Dict)
(MACROS Dict.Open Dict.Close Dict.GetEntry Dict.PutEntry Dict.PrintEntry
Dict.MapEntries)
(* ;;; "utility functions")
(FNS DictFromName Dict.Establish Dict.Prop Dict.Name)
(INITVARS Dict.DictionaryList)
(GLOBALVARS Dict.DictionaryList)
(* ;;; "a simple dictionary.")
(FNS SimpleDict.New SimpleDict.PutEntry SimpleDict.Lookup SimpleDict.MapEntries
SimpleDict.PrintEntries SimpleDict.Test)
(RECORDS SimpleDict.Node))
(COMS
(* ;;; "the INVERTEDDICT class")
(RECORDS INVERTEDDICT)
(FNS InvertedDictFromName InvertedDict.Establish InvertedDict.Prop InvertedDict.Name
InvertedDict.Open)
(INITVARS InvertedDict.List)
(GLOBALVARS InvertedDict.List))
(DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA)
(NLAML)
(LAMA InvertedDict.Prop
Dict.Prop
Analyzer.Prop])
(* ;;; "THE ANALYZER CLASS")
(DECLARE%: EVAL@COMPILE
(DATATYPE Morphalyzer (analyzerName grammar index analyzerProps openFn closeFn proofreadFn
analyzeFn lookupFn correctionsFn generateFn conjugateFn findWordFn
addEntryFn)
openFn _ (FUNCTION NILL)
closeFn _ (FUNCTION NILL)
proofreadFn _ (FUNCTION Analyzer.DefaultProofread)
analyzeFn _ (FUNCTION Analyzer.DefaultAnalyze)
lookupFn _ (FUNCTION NILL)
correctionsFn _ (FUNCTION Analyzer.DefaultCorrections)
generateFn _ (FUNCTION NILL)
conjugateFn _ (FUNCTION NILL)
findWordFn _ (FUNCTION NILL)
addEntryFn _ (FUNCTION Analyzer.DefaultAddEntry))
)
(/DECLAREDATATYPE 'Morphalyzer
'(POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER
POINTER POINTER POINTER)
'((Morphalyzer 0 POINTER)
(Morphalyzer 2 POINTER)
(Morphalyzer 4 POINTER)
(Morphalyzer 6 POINTER)
(Morphalyzer 8 POINTER)
(Morphalyzer 10 POINTER)
(Morphalyzer 12 POINTER)
(Morphalyzer 14 POINTER)
(Morphalyzer 16 POINTER)
(Morphalyzer 18 POINTER)
(Morphalyzer 20 POINTER)
(Morphalyzer 22 POINTER)
(Morphalyzer 24 POINTER)
(Morphalyzer 26 POINTER))
'28)
(* ;; "renamed record to avoid a conflict.")
(DECLARE%: EVAL@COMPILE
(PUTPROPS Analyzer.Open MACRO ((analyzer)
(APPLY* (fetch (Morphalyzer openFn) of analyzer)
analyzer)))
(PUTPROPS Analyzer.Close MACRO ((analyzer)
(APPLY* (fetch (Morphalyzer closeFn) of analyzer)
analyzer)))
(PUTPROPS Analyzer.Corrections MACRO ((analyzer stream start length)
(* * returns a list of possible corrections for the string starting at "start"
that is "length" characters long.)
(APPLY* (fetch (Morphalyzer correctionsFn)
of analyzer)
analyzer stream start length)))
(PUTPROPS Analyzer.Proofread MACRO ((analyzer stream start length prFn)
(* * The user interface to Analyzer.Analyze.)
(APPLY* (fetch (Morphalyzer proofreadFn) of
analyzer)
analyzer stream start length prFn)))
(PUTPROPS Analyzer.Analyze MACRO ((analyzer stream start length analFn allowWildCards)
(* * break up the stream into legal lexical items.
calls analFn (analyzer stream start len entries) on each item, where "entries"
is the analysis of that item. If "entries" is NIL, then the item could not be
analyzed.)
(APPLY* (fetch (Morphalyzer analyzeFn) of analyzer)
analyzer stream start length analFn allowWildCards)))
(PUTPROPS Analyzer.Lookup MACRO ((analyzer stream start length)
(* * Look up the substring of stream between start and length in dict.
"stream" can be a stream, a string, or a list of characters.)
(APPLY* (fetch (Morphalyzer lookupFn) of analyzer)
analyzer stream start length)))
(PUTPROPS Analyzer.FindWord MACRO ((analyzer word stream start length)
(APPLY* (fetch (Morphalyzer findWordFn) of
analyzer
)
analyzer word stream start length)))
(PUTPROPS Analyzer.AddEntry MACRO ((analyzer lemma entry dontRecord)
(* * add lemma to the dictionary with entry "entry" %.
If dontRecord is non-NIL, don't worry about keeping track of this word for the
word list.)
(APPLY* (fetch (Morphalyzer addEntryFn) of
analyzer
)
analyzer lemma entry dontRecord)))
(PUTPROPS Dict.DisplayEntry MACRO ((dict entry newwindowflg)
(APPLY* (OR [COND
((type? Dict dict)
(Dict.Prop dict 'DISPLAYENTRYFN))
((type? INVERTEDDICT dict)
(InvertedDict.Prop dict
'DISPLAYENTRYFN]
'NILL)
dict entry newwindowflg)))
)
(* ;; "MACROS that call apply the methods of the analyzer class.")
(DEFINEQ
(AnalyzerFromName
[LAMBDA (dictName remoteName) (* ; "Edited 6-Oct-88 09:56 by jtm:")
(* * find the analyzer corresponding to the dictionary.)
(PROG (analyzer COLONPOS)
[COND
((NULL dictName)
(SETQ analyzer (CAR Analyzer.List)))
[(for i in Analyzer.List do (COND
([AND (EQ dictName (fetch (Morphalyzer
analyzerName)
of i))
(EQ remoteName (Analyzer.Prop
i
'RemoteDict]
(SETQ analyzer i)
(RETURN T]
((SETQ COLONPOS (STRPOS ":" dictName))
(SETQ analyzer (AnalyzerFromName (SUBATOM dictName 1 (SUB1 COLONPOS))
(SUBATOM dictName (IPLUS COLONPOS 2)
-1]
(RETURN analyzer])
(Analyzer.CountWords
[LAMBDA (analyzer stream start length) (* jtm%: "13-Nov-86 13:32")
(LET [(n 0)
(FN (Analyzer.Prop analyzer 'CountWords]
(COND
(FN (APPLY* FN analyzer stream start length))
(T [Analyzer.Analyze analyzer stream start length (FUNCTION (LAMBDA (analyzer stream
start length
entries)
(add n 1)
NIL]
n])
(Analyzer.DefaultCorrections
[LAMBDA (analyzer stream start length) (* jtm%: " 7-Apr-87 08:23")
(* * returns a list of possible spelling corrections for the given word.)
(PROG [form word wordList caps periods (userDict (Analyzer.Prop analyzer 'UserDict]
[COND
[(STREAMP stream)
(SETFILEPTR stream start)
(SETQ word (for i from 1 to length collect (BIN stream]
((STRINGP stream)
(SETQ word (for i from 1 to (NCHARS stream) collect (NTHCHARCODE stream
i]
(SETQ caps (Analyzer.Capitalization word))
(SETQ periods (FMEMB (CHARCODE %.)
word))
(* * first try transpositions)
(for tail temp on word while (CDR tail)
do (SETQ temp (CAR tail))
(RPLACA tail (CADR tail))
(RPLACA (CDR tail)
temp)
(COND
((AND (EQ caps 'FIRST)
(EQ tail word)) (* don't transpose the first letters
of a capitalized word.)
NIL)
(T (\Analyzer.TestCorruption analyzer word wordList userDict)))
(RPLACA (CDR tail)
(CAR tail))
(RPLACA tail temp))
(* * next try deletions)
(COND
((CDR word)
(\Analyzer.TestCorruption analyzer (CDR word)
wordList userDict)))
(for tail temp on word while (CDR tail) do (SETQ temp (CDR tail))
(RPLACD tail (CDDR tail))
(\Analyzer.TestCorruption
analyzer word wordList
userDict)
(RPLACD tail temp))
(* * prepend a character.)
(SETQ word (CONS (CHARCODE A)
word))
(SELECTQ caps
(FIRST (* don't prepend a character before
a capitalized word.)
NIL)
(ALL (* prepend a capital letter.)
(for c from (CHARCODE A) to (CHARCODE Z)
do (RPLACA word c)
(\Analyzer.TestCorruption analyzer word wordList userDict)))
(for c from (CHARCODE a) to (CHARCODE z)
do (RPLACA word c)
(\Analyzer.TestCorruption analyzer word wordList userDict)))
(SETQ word (CDR word))
(* * insert characters.)
(for tail on word do (RPLACD tail (CONS (CHARCODE A)
(CDR tail)))
[COND
((EQ caps 'ALL)
(for c from (CHARCODE A)
to (CHARCODE Z)
do (RPLACA (CDR tail)
c)
(\Analyzer.TestCorruption analyzer word
wordList userDict)))
(T (for c from (CHARCODE a)
to (CHARCODE z)
do (RPLACA (CDR tail)
c)
(\Analyzer.TestCorruption analyzer word
wordList userDict]
(COND
(periods (RPLACA (CDR tail)
(CHARCODE %.))
(\Analyzer.TestCorruption analyzer word wordList
userDict)))
(RPLACD tail (CDDR tail)))
(* * replace characters)
(for tail temp on word do (SETQ temp (CAR tail))
[COND
((OR (EQ caps 'ALL)
(AND (EQ caps 'FIRST)
(EQ tail word)))
(for c from (CHARCODE A)
to (CHARCODE Z)
do (COND
((NEQ temp c)
(RPLACA tail c)
(\Analyzer.TestCorruption analyzer
word wordList userDict]
[COND
((OR (EQ caps NIL)
(NOT (ALPHACHARP (CHCON1 temp)))
(AND (EQ caps 'FIRST)
(NEQ tail word)))
(for c from (CHARCODE a)
to (CHARCODE z)
do (COND
((NEQ temp c)
(RPLACA tail c)
(\Analyzer.TestCorruption analyzer
word wordList userDict]
(COND
(periods (RPLACA tail (CHARCODE %.))
(\Analyzer.TestCorruption analyzer word
wordList userDict)))
(RPLACA tail temp))
(SETQ wordList (SORT wordList))
[for i on wordList do (while (STREQUAL (CAR i)
(CADR i))
do (RPLACD i (CDDR i]
(RETURN wordList])
(Analyzer.DefaultNextWord
[LAMBDA (analyzer stream startPtr searchLength NWFn) (* jtm%: "29-Oct-85 15:23")
(* * Scans the stream looking for a word, i.e.
a sequence of alphabetic charqacters. If the file ptr is already in the middle
of such a sequence, it backs up to the beginning of that sequence.
The function applies NWFn to (stream start stop) for each such word.)
(SETFILEPTR stream (OR startPtr (SETQ startPtr 0)))
(bind char end endPtr word length start value quote (filePtr _ (GETFILEPTR stream))
(EOFPtr _ (GETEOFPTR stream)) first (SETQ endPtr (COND
(searchLength (IPLUS startPtr
searchLength)
)
(T EOFPtr)))
(OR (ILEQ endPtr EOFPtr)
(SETQ endPtr EOFPtr))
do (SETQ char (AND (ILESSP (GETFILEPTR stream)
endPtr)
(BIN stream)))
(COND
[(AND char (AND (NUMBERP char)
(ILESSP char 128)
(Analyzer.AlphaCharP char)))
(OR start (SETQ start (SUB1 (GETFILEPTR stream]
(start (SETQ end (GETFILEPTR stream))
(SETQ length (IDIFFERENCE end start))
(AND char (add length -1)) (* back up to the last legal char.)
[COND
(NWFn (SETQ value (APPLY* NWFn analyzer stream start length]
(COND
((OR (NULL NWFn)
(EQ value T))
(RETURN (CONS start length)))
(value (RETURN value)))
(SETFILEPTR stream end)
(SETQ start NIL)))
(OR char (RETURN])
(Analyzer.Name
[LAMBDA (analyzer) (* jtm%: "13-Oct-87 10:44")
(COND
[(Analyzer.Prop analyzer 'RemoteDict)
(MKATOM (CONCAT (fetch (Morphalyzer analyzerName) of analyzer)
": "
(Analyzer.Prop analyzer 'RemoteDict]
(T (fetch (Morphalyzer analyzerName) of analyzer])
(Analyzer.DefaultAddEntry
[LAMBDA (analyzer lemma entry dontRecord errorStream) (* jtm%: " 7-Apr-87 07:57")
(LET [(userDict (Analyzer.Prop analyzer 'UserDict]
(COND
((NULL userDict)
(SETQ userDict (SimpleDict.New))
(Analyzer.Prop analyzer 'UserDict userDict)))
(Dict.PutEntry userDict lemma entry)
(COND
((NOT dontRecord)
(Analyzer.PushProp analyzer 'WordList lemma)))
lemma])
(Analyzer.DefaultAnalyze
[LAMBDA (analyzer stream startPtr searchLength NWFn allowWildCards)
(* ; "Edited 23-Nov-88 08:17 by jtm:")
(* * Scans the stream looking for a word, i.e.
a sequence of alphabetic charqacters. If the file ptr is already in the middle
of such a sequence, it backs up to the beginning of that sequence.
The function applies NWFn to (stream start stop) for each such word.)
[COND
((STRINGP stream)
(SETQ stream (OPENSTRINGSTREAM stream]
(SETFILEPTR stream (OR startPtr (SETQ startPtr 0)))
(bind char end endPtr length start lookup number initialQuote seprs
(userDict _ (Analyzer.Prop analyzer 'UserDict))
[optSeprCodes _ (OR (Analyzer.Prop analyzer 'OPT-SEPR-CODES)
'(39 46 45 47]
(addAlphaCharCodes _ (Analyzer.Prop analyzer 'ADD-ALPHA-CHAR-CODES))
(word _ (ALLOCSTRING 100 32))
(i _ startPtr) first (DECLARE (LOCALVARS . T))
[SETQ endPtr (COND
(searchLength (IMIN (GETEOFPTR stream)
(IPLUS startPtr searchLength)))
(T (GETEOFPTR stream]
do (SETQ char (AND (add i 1)
(ILEQ i endPtr)
(BIN stream)))
(COND
((AND start (NUMBERP char)
(ILESSP char 128))
(RPLCHARCODE word (IDIFFERENCE i start)
char)))
[COND
[[AND char (OR (AND (NUMBERP char)
(ILESSP char 128)
(Analyzer.AlphaCharP char))
(FMEMB char addAlphaCharCodes)
(AND allowWildCards (EQ char (CONSTANT (CHARCODE *]
(COND
((NULL start)
[COND
(number (SETQ start (IDIFFERENCE i 2))
(* we have a number followed by some characters.
(e.g. 7th, 21st, etc.) Take in the last digit of the number.)
(RPLCHARCODE word 1 number)
(SETQ number NIL))
(T (SETQ start (SUB1 i]
(RPLCHARCODE word (IDIFFERENCE i start)
char]
[(AND char (NUMBERP char)
(IGEQ char 48)
(ILEQ char 57)) (* a number)
(COND
((NULL start)
(SETQ number char)
(SETQ initialQuote NIL))
(T (RPLCHARCODE word (IDIFFERENCE i start)
char]
((AND start char (FMEMB char optSeprCodes)) (* optSeprCodes may or may not be a
part of the word.)
(push seprs i))
[start (* AND char (add length -1))
(* back up to the last legal char.)
(* * find the longest string of characters seperated by seprs that the analyzer
accepts.)
(COND
((NULL seprs)
(SETQ seprs i))
(T (push seprs i)))
[for stop inside seprs
do (SETQ length (SUB1 (IDIFFERENCE stop start)))
(COND
([SETQ lookup (OR (Analyzer.Lookup analyzer word 0 length)
(AND userDict (SimpleDict.Lookup userDict
word length]
(RETURN))
((AND initialQuote (EQP length 1)
(EQ (NTHCHARCODE word 1)
(CHARCODE s)))
(SETQ lookup 'possessive)
(RETURN]
(* * apply NWFn and return its value if non-NIL.)
(COND
((AND (NULL NWFn)
(NEQ lookup 'possessive))
(RETURN (CONS start length)))
((AND (NEQ lookup 'possessive)
(SETQ lookup (APPLY* NWFn analyzer stream start length lookup)))
(RETURN lookup))
(T (COND
((NEQ i (IPLUS start length 1))
(* we regressed.)
(SETQ i (IPLUS start length))
(* don't add 1 so that we will see the quote and initialQuote will get set
("time's"))
(SETFILEPTR stream i) (* set char to T to prevent the
RETURN at the end of the loop.)
(SETQ char T)))
(SETQ start NIL)
(SETQ seprs NIL)
(SETQ initialQuote NIL]
(T (SETQ number NIL)
(SETQ initialQuote (EQ char (CHARCODE %']
(OR char (RETURN])
(Analyzer.DefaultProofread
[LAMBDA (analyzer stream begin length) (* jtm%: "16-Dec-87 13:07")
(PROG (start.length correction startTime stopTime char (n 0))
(TEDIT.PROMPTPRINT stream "Proofreading . . . " T)
(* * initialize and back up to the beginning of a word.)
(SETQ startTime (CLOCK 0))
(Stream.Init stream begin length)
[COND
((NEQ length 0)
(while (AND (NUMBERP (SETQ char (BIN stream)))
(ALPHACHARP char)) do (COND
((EQUAL begin 0)
(RETURN))
(T (add begin -1)
(add length 1)
(SETFILEPTR stream begin]
(* * look for the next spelling error.)
[while [SETQ start.length (Analyzer.Analyze analyzer stream begin length
(FUNCTION (LAMBDA (analyzer stream start length
entries)
(add n 1)
(COND
((NULL entries)
(CONS start length]
do
(* * start.length is a CONS pair of locations delimiting an unrecognizable
word. Set the selection to it and display it.)
[COND
((AND Proofreader.UserFns (for fn (word _ (STREAM.FETCHSTRING
stream
(CAR start.length)
(CDR start.length)))
inside Proofreader.UserFns
thereis (APPLY* fn word)))
(SETQ correction '*SKIP*))
(T (TEDIT.SETSEL stream (ADD1 (CAR start.length))
(CDR start.length)
'RIGHT T)
(TEDIT.SHOWSEL stream NIL)
(TEDIT.NORMALIZECARET stream)
(TEDIT.SHOWSEL stream T)
(COND
([NOT (AND Proofreader.AutoCorrect (SETQ correction (TEdit.Correct
stream analyzer T]
(RETURN]
(COND
[(FMEMB correction '(*SKIP* *INSERT*))
[add length (IDIFFERENCE begin (IPLUS (CAR start.length)
(CDR start.length]
(SETQ begin (IPLUS (CAR start.length)
(CDR start.length]
((STRINGP correction)
(add length (IDIFFERENCE begin (CAR start.length)))
(* move start point.)
(add length (IDIFFERENCE (NCHARS correction)
(CDR start.length)))
(* adjust for correction.)
(SETQ begin (CAR start.length)))
(T (SHOULDNT]
(SETQ stopTime (CLOCK 0))
(COND
(Analyzer.TimeProofreader (TEDIT.PROMPTPRINT stream (CONCAT "Elapsed Time: "
(QUOTIENT (DIFFERENCE
stopTime
startTime)
1000.0)
" seconds.")))
(start.length (TEDIT.PROMPTPRINT stream "Error found."))
(T (* (ADD1 (GETEOFPTR stream)))
(TEDIT.SETSEL stream (IPLUS begin length 1)
0
'RIGHT)
(TEDIT.SHOWSEL stream NIL)
(TEDIT.NORMALIZECARET stream)
(TEDIT.SHOWSEL stream T)
(TEDIT.PROMPTPRINT stream (COND
((EQUAL n 0)
"No Errors.")
(T (CONCAT n " words proofread.")))
T])
)
(* ;; "Functions implementing the default case for various methods of the analyzer class.")
(DEFINEQ
(Analyzer.DefaultLoadWordList
[LAMBDA (analyzer file) (* jtm%: "17-Sep-86 09:39")
(* * adds a word list to the given analyzer.)
(PROG (wordList)
(SETQ wordList (Analyzer.ReadWordList file))
(for i in wordList do (Analyzer.AddEntry analyzer i T T))
(Analyzer.PushProp analyzer 'WordListFile file])
(Analyzer.DefaultStoreWordList
[LAMBDA (analyzer file) (* jtm%: "23-Sep-86 09:08")
(* * adds the current word list to the remote file.)
(PROG (wordList)
(SETQ wordList (Analyzer.Prop analyzer 'WordList))
[COND
((DIRECTORY file)
(SETQ wordList (APPEND wordList (Analyzer.ReadWordList file]
(Analyzer.WriteWordList wordList file)
(Analyzer.PushProp analyzer 'WordListFile file)
(Analyzer.Prop analyzer 'WordList NIL])
(Analyzer.ReadWordList
[LAMBDA (file) (* ; "Edited 9-Mar-89 15:22 by jtm:")
(PROG (firstWord word words stream)
(SETQ stream (OPENSTREAM file 'INPUT))
(SETFILEPTR stream 0)
(SETQ firstWord (READ stream))
(SETFILEPTR stream 0)
(COND
[(LISTP firstWord) (* old style format.)
(RETURN (CDR (READFILE stream]
(T (* new style format)
[COND
((NULL WORDLISTRDTBL)
(SETQ WORDLISTRDTBL (CREATEWORDLISTRDTBL]
[while (SKIPSEPRCODES stream WORDLISTRDTBL)
do (SETQ word (RSTRING stream WORDLISTRDTBL))
(COND
((EQ 0 (NCHARS word))
(BIN stream))
(T (push words word]
(CLOSEF stream)
(RETURN words])
(Analyzer.WriteWordList
[LAMBDA (wordList file) (* jtm%: "17-Sep-86 10:11")
(PROG (stream)
(SETQ stream (OPENSTREAM file 'OUTPUT))
(SETFILEPTR stream 0)
(for word in wordList do (printout stream word T))
(CLOSEF stream])
(CREATEWORDLISTRDTBL
[LAMBDA NIL (* jtm%: "17-Sep-86 10:55")
(LET (RDTBL)
(SETQ RDTBL (COPYREADTABLE 'ORIG))
(for SEPR in (GETSEPR RDTBL) do (SETSYNTAX (CHARACTER SEPR)
'OTHER RDTBL))
(for BREAK in (GETBRK RDTBL) do (SETSYNTAX (CHARACTER BREAK)
'OTHER RDTBL))
(SETSYNTAX (CHARACTER (CHARCODE CR))
'SEPR RDTBL)
RDTBL])
)
(RPAQ? WORDLISTRDTBL NIL)
(DEFINEQ
(Analyzer.Prop
[LAMBDA a (* jtm%: "13-Oct-87 11:54")
(LET (p (analyzer (ARG a 1))
(prop (ARG a 2)))
(SETQ p (FASSOC prop (fetch (Morphalyzer analyzerProps) of analyzer)))
(COND
((ILEQ a 2)
(CDR p))
[p (PROG1 (CDR p)
(RPLACD p (ARG a 3)))]
(T (CDAR (push (fetch (Morphalyzer analyzerProps) of analyzer)
(CONS prop (ARG a 3])
(Analyzer.PushProp
[LAMBDA (analyzer prop value) (* jtm%: "13-Oct-87 10:59")
(* * pushes value onto a list of values stored at prop.)
(LET [(prop.values (FASSOC prop (fetch (Morphalyzer analyzerProps) of analyzer]
(COND
[(NULL prop.values)
(push (fetch (Morphalyzer analyzerProps) of analyzer)
(CONS prop (LIST value]
((NOT (for i in (CDR prop.values) thereis (EQUAL i value)))
(push (CDR prop.values)
value)))
value])
)
(DECLARE%: EVAL@COMPILE
(PUTPROPS Analyzer.AlphaCharP MACRO [(CHAR)
(OR (EQ (LRSH CHAR 8)
241)
([LAMBDA (UCHAR)
(DECLARE (LOCALVARS UCHAR))
(OR (EQ (LRSH UCHAR 8)
241)
(AND (IGEQ UCHAR (CHARCODE A))
(ILEQ UCHAR (CHARCODE Z]
(LOGAND CHAR 95])
(PUTPROPS \Analyzer.TestCorruption MACRO [(analyzer word wordList userDict)
(COND
((OR (Analyzer.Lookup analyzer word)
(AND userDict (SimpleDict.Lookup
userDict word)))
(push wordList (CONCATCODES word])
(PUTPROPS Analyzer.Capitalization MACRO [(word)
(* * returns NIL, ALL or FIRST)
(COND
((AND (CAR word)
(Analyzer.UCaseP (CAR word)))
(COND
((AND (CADR word)
(Analyzer.UCaseP (CADR word)))
'ALL)
(T 'FIRST])
(PUTPROPS Analyzer.UCaseP MACRO [(UCHAR)
(OR (AND (IGEQ UCHAR (CHARCODE 361,041))
(ILEQ UCHAR (CHARCODE 361,160)))
(AND (IGEQ UCHAR (CHARCODE A))
(ILEQ UCHAR (CHARCODE Z])
)
(* ;; "Service MACROS.")
(DEFINEQ
(STREAM.FETCHSTRING
[LAMBDA (stream start length buffer restorePtr) (* jtm%: " 3-Apr-87 11:28")
(LET (pos)
[COND
(restorePtr (SETQ pos (GETFILEPTR stream]
[COND
((OR (NULL buffer)
(IGREATERP length (NCHARS buffer)))
(SETQ buffer (ALLOCSTRING length]
(SETFILEPTR stream start)
(for i from 1 to length do (RPLCHARCODE buffer i (BIN stream)))
(COND
(restorePtr (SETFILEPTR stream pos)))
(SUBSTRING buffer 1 length])
)
(DECLARE%: EVAL@COMPILE
(PUTPROPS Stream.Init MACRO [(stream start length)
(COND
[(STRINGP stream)
(OR start (SETQ start 0))
(OR length (SETQ length (NCHARS stream]
((NOT (LISTP stream))
(COND
((NULL start)
(SETQ start 0)))
[COND
((NULL length)
(SETQ length (IDIFFERENCE (GETEOFPTR stream)
start]
(SETFILEPTR stream start])
(PUTPROPS Stream.NextChar MACRO [(stream length index)
(COND
((LISTP stream)
(pop stream))
((OR (NULL stream)
(ILEQ length 0))
NIL)
((STRINGP stream)
(add length -1)
(add index 1)
(NTHCHARCODE stream index))
(T (add length -1)
(BIN stream])
)
(DEFINEQ
(Analyzer.CorruptWord
[LAMBDA (analyzer stream start length) (* jtm%: " 5-Feb-87 11:23")
(* * returns a list of possible spelling corrections for the given word.)
(PROG (form word wordList caps)
(SETQ word (for i from 1 to length collect (BIN stream)))
(SETQ caps (Analyzer.Capitalization word))
(* * first try transpositions)
(for tail temp on word while (CDR tail)
do (SETQ temp (CAR tail))
(RPLACA tail (CADR tail))
(RPLACA (CDR tail)
temp)
(COND
((AND (EQ caps 'FIRST)
(EQ tail word)) (* don't transpose the first letters
of a capitalized word.)
NIL)
(T (\Analyzer.TestCorruption analyzer word wordList)))
(RPLACA (CDR tail)
(CAR tail))
(RPLACA tail temp))
(* * next try deletions)
(COND
((CDR word)
(\Analyzer.TestCorruption analyzer (CDR word)
wordList)))
(for tail temp on word while (CDR tail) do (SETQ temp (CDR tail))
(RPLACD tail (CDDR tail))
(\Analyzer.TestCorruption
analyzer word wordList)
(RPLACD tail temp))
(* * prepend a character.)
(SETQ word (CONS 'A word))
(SELECTQ caps
(FIRST (* don't prepend a character before
a capitalized word.)
NIL)
(ALL (* prepend a capital letter.)
(for c from (CHARCODE A) to (CHARCODE Z)
do (RPLACA word c)
(\Analyzer.TestCorruption analyzer word wordList)))
(for c from (CHARCODE a) to (CHARCODE z) do (RPLACA word c)
(\Analyzer.TestCorruption
analyzer word wordList)))
(SETQ word (CDR word))
(* * insert characters.)
(for tail on word do (RPLACD tail (CONS 'A (CDR tail)))
[COND
((EQ caps 'ALL)
(for c from (CHARCODE A)
to (CHARCODE Z)
do (RPLACA (CDR tail)
c)
(\Analyzer.TestCorruption analyzer word
wordList)))
(T (for c from (CHARCODE a)
to (CHARCODE z)
do (RPLACA (CDR tail)
c)
(\Analyzer.TestCorruption analyzer word
wordList]
(RPLACD tail (CDDR tail)))
(* * replace characters)
(for tail temp on word do (SETQ temp (CAR tail))
[COND
((OR (EQ caps 'ALL)
(AND (EQ caps 'FIRST)
(EQ tail word)))
(for c from (CHARCODE A)
to (CHARCODE Z)
do (RPLACA tail c)
(COND
((EQ temp c))
(T (\Analyzer.TestCorruption analyzer
word wordList]
[COND
((OR (EQ caps NIL)
(NOT (ALPHACHARP temp))
(AND (EQ caps 'FIRST)
(NEQ tail word)))
(for c from (CHARCODE a)
to (CHARCODE z)
do (RPLACA tail c)
(COND
((EQ temp (CHARACTER c)))
(T (\Analyzer.TestCorruption analyzer
word wordList]
(RPLACA tail temp))
(SETQ wordList (SORT wordList))
[for i on wordList do (while (STREQUAL (CAR i)
(CADR i))
do (RPLACD i (CDR i]
(RETURN wordList])
)
(DECLARE%: DOEVAL@COMPILE DONTCOPY
(GLOBALVARS WORDLISTRDTBL)
)
(* ;;; "TEDIT interface to analyzer.")
(DEFINEQ
(Analyzer.Establish
[LAMBDA (analyzer) (* jtm%: "13-Oct-87 10:44")
(AND analyzer (OR (AND (BOUNDP 'Analyzer.List)
(bind (analyzerName _ (fetch (Morphalyzer analyzerName)
of analyzer)) for tail on
Analyzer.List
when (EQUAL analyzerName (fetch (Morphalyzer analyzerName)
of (CAR tail)))
do (RPLACA tail analyzer)
(RETURN T)))
(push Analyzer.List analyzer])
(AnalyzerForStream
[LAMBDA (stream) (* jtm%: " 2-Oct-85 14:00")
(* * comment)
(COND
((STREAMPROP stream 'analyzer))
(T (TEdit.SetAnalyzer stream])
(Analyzer.QuitFn
[LAMBDA (window stream textObj) (* jtm%: "14-Jan-86 15:58")
(* * ask the user if he wants to save the word list.)
(PROG ((analyzer (AnalyzerForStream stream)))
(COND
((AND analyzer (Analyzer.Prop analyzer 'WordList)
(STREQUAL "yes" (TEDIT.GETINPUT stream "Do you want to save the word list? " "yes"
)))
(TEdit.StoreWordList stream])
(Analyzer.BeforeLogout
[LAMBDA NIL (* jtm%: "13-Oct-87 10:45")