DIRECTORY PFS USING [PathFromRope, StreamOpen], IO, Random USING [Create, ChooseInt, RandomStream], BitTableLookup USING [Read, Lookup, Table], RefText USING [TrustTextAsRope], SpellingToolServices USING [BruteForceCorrection], Rope USING [ROPE]; SpellingTestImpl: CEDAR PROGRAM IMPORTS PFS, IO, BitTableLookup, Random, RefText, SpellingToolServices = BEGIN ROPE: TYPE = Rope.ROPE; experimental: ROPE ¬ "Experimental.BitTable"; web2: ROPE ¬ "Web2.dic"; Garbage: PROC [minLength, maxLength: CARDINAL, number: INT, file: ROPE] RETURNS [passed, failed: INT ¬ 0] = { s: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; trouble: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file], create]; globalBitTable: BitTableLookup.Table ¬ NIL; length: INT; randomSequence: Random.RandomStream ¬ Random.Create[-1, 0]; word: REF TEXT ¬ NEW[TEXT[maxLength]]; globalBitTable ¬ BitTableLookup.Read[s]; s.Close[]; FOR i: INT IN [0..number) DO length ¬ Random.ChooseInt[randomSequence, minLength, maxLength]; word.length ¬ length; FOR j: INT IN [0..length) DO word[j] ¬ 'a + Random.ChooseInt[randomSequence, 0, 25]; ENDLOOP; IF globalBitTable.Lookup[word] THEN { trouble.Put1[IO.text[word]]; trouble.PutChar['\n]; passed ¬ passed + 1; } ELSE failed ¬ failed + 1; ENDLOOP; trouble.Close[]; }; Garbage4: PROC [file: ROPE] RETURNS [passed, failed: INT ¬ 0] = { s: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; trouble: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file], create]; globalBitTable: BitTableLookup.Table ¬ NIL; word: REF TEXT ¬ NEW[TEXT[4]]; globalBitTable ¬ BitTableLookup.Read[s]; s.Close[]; word.length ¬ 4; FOR c0: CHAR IN ['a..'z] DO FOR c1: CHAR IN ['a..'z] DO FOR c2: CHAR IN ['a..'z] DO FOR c3: CHAR IN ['a..'z] DO word[0] ¬ c0; word[1] ¬ c1; word[2] ¬ c2; word[3] ¬ c3; IF globalBitTable.Lookup[word] THEN { trouble.PutText[word]; trouble.PutChar['\n]; passed ¬ passed + 1; } ELSE failed ¬ failed + 1; ENDLOOP; ENDLOOP; ENDLOOP; ENDLOOP; trouble.Close[]; }; Garbage3: PROC [file: ROPE] RETURNS [passed, failed: INT ¬ 0] = { s: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; trouble: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file], create]; globalBitTable: BitTableLookup.Table ¬ NIL; word: REF TEXT ¬ NEW[TEXT[3]]; globalBitTable ¬ BitTableLookup.Read[s]; s.Close[]; word.length ¬ 3; FOR c0: CHAR IN ['a..'z] DO FOR c1: CHAR IN ['a..'z] DO FOR c2: CHAR IN ['a..'z] DO word[0] ¬ c0; word[1] ¬ c1; word[2] ¬ c2; IF globalBitTable.Lookup[word] THEN { trouble.PutText[word]; trouble.PutChar['\n]; passed ¬ passed + 1; } ELSE failed ¬ failed + 1; ENDLOOP; ENDLOOP; ENDLOOP; trouble.Close[]; }; Garbage2: PROC [file: ROPE] RETURNS [passed, failed: INT ¬ 0] = { s: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; trouble: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file], create]; globalBitTable: BitTableLookup.Table ¬ NIL; word: REF TEXT ¬ NEW[TEXT[2]]; globalBitTable ¬ BitTableLookup.Read[s]; s.Close[]; word.length ¬ 2; FOR c0: CHAR IN ['a..'z] DO FOR c1: CHAR IN ['a..'z] DO word[0] ¬ c0; word[1] ¬ c1; IF globalBitTable.Lookup[word] THEN { trouble.PutText[word]; trouble.PutChar['\n]; passed ¬ passed + 1; } ELSE failed ¬ failed + 1; ENDLOOP; ENDLOOP; trouble.Close[]; }; Garbage1: PROC [file: ROPE] RETURNS [passed, failed: INT ¬ 0] = { s: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; trouble: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file], create]; globalBitTable: BitTableLookup.Table ¬ NIL; word: REF TEXT ¬ NEW[TEXT[2]]; globalBitTable ¬ BitTableLookup.Read[s]; s.Close[]; word.length ¬ 2; FOR c0: CHAR IN ['a..'z] DO word[0] ¬ c0; IF globalBitTable.Lookup[word] THEN { trouble.PutText[word]; trouble.PutChar['\n]; passed ¬ passed + 1; } ELSE failed ¬ failed + 1; ENDLOOP; trouble.Close[]; }; CloseOnes: PROC [outFile: ROPE ¬ "Spelling.CloseOnes"] RETURNS [passed, failed: INT ¬ 0] = { bitStream: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[experimental]]; listStream: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[web2]]; outStream: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[outFile], create]; buffer: REF TEXT ¬ NEW[TEXT[100]]; wordBuffer: REF TEXT ¬ NEW[TEXT[100]]; correctionList: LIST OF ROPE ¬ NIL; globalBitTable: BitTableLookup.Table ¬ BitTableLookup.Read[bitStream]; WordChecker: PROC [w: REF TEXT] RETURNS [inTable: BOOL] = { inTable ¬ globalBitTable.Lookup[w]; }; bitStream.Close[]; DO wordBuffer ¬ GetToken[listStream, wordBuffer ! IO.EndOfStream => EXIT]; [correctionList, buffer] ¬ SpellingToolServices.BruteForceCorrection [RefText.TrustTextAsRope[wordBuffer], WordChecker, buffer]; FOR l: LIST OF ROPE ¬ correctionList, l.rest UNTIL l = NIL DO outStream.PutRope[l.first]; outStream.PutChar['\n]; ENDLOOP; ENDLOOP; outStream.Close[]; listStream.Close[]; }; GetToken: PROC [s: IO.STREAM, word: REF TEXT] RETURNS [w: REF TEXT] = { UnPrintable: PROC [c: CHAR] RETURNS [unPrintable: BOOL] = INLINE { unPrintable ¬ c IN ['\000 .. '\040]; }; c: CHAR; w ¬ word; WHILE UnPrintable[c ¬ s.GetChar[]] DO ENDLOOP; s.Backup[c]; w.length ¬ w.maxLength; FOR i: CARDINAL ¬ 0, i+1 DO c ¬ s.GetChar[ ! IO.EndOfStream => GOTO done]; IF UnPrintable[c] THEN GOTO done; IF i >= w.maxLength THEN { w ¬ NEW[TEXT[2*w.maxLength+1]]; w.length ¬ w.maxLength; }; w[i] ¬ c; REPEAT done => w.length ¬ i; ENDLOOP; }; END. ( SpellingTestImpl.mesa Copyright Σ 1983, 1987, 1990, 1992 by Xerox Corporation. All rights reserved. Created by Nix on September 8, 1983 11:17 am Last Edited by: Nix, November 17, 1983 1:36 pm Jack Kent July 24, 1987 1:26:36 pm PDT Tim Diebert: January 26, 1987 5:06:53 pm PST Rick Beach, May 2, 1985 3:21:23 pm PDT Bill Jackson (bj), March 7, 1990 9:50 pm PST Doug Terry, March 4, 1991 12:45 pm PST Willie-s, May 22, 1992 2:28 pm PDT Utility for reading a token from the given stream into the given buffer. How's this for device independence? ΚX–(cedarcode) style•NewlineDelimiter ™code– "Cedar" stylešœ™K– "Cedar" stylešœ ΟeœC™NKšœ,™,K™.K™&K™,K™&K™,K™&K™"K˜—šΟk ˜ Kšžœžœ˜%Kšžœ˜Kšœžœ#˜/Kšœžœ˜+Kšœžœ˜ Kšœžœ˜2Kšœžœžœ˜K˜—šΟnœžœž˜Kšžœžœžœ:ž˜NKšžœžœžœ˜K˜Kšœžœ˜-Kšœžœ˜K˜šŸœžœžœ žœžœžœžœ ˜mKš œžœžœžœ žœ˜>Kš œ žœžœžœ žœ˜DKšœ'žœ˜+Kšœžœ˜ K˜;Kš œžœžœžœžœ ˜&K˜(K˜ šžœžœžœ ž˜K˜@K˜šžœžœžœ ž˜K˜7Kšžœ˜—šžœžœ˜%Kšœ žœ ˜K˜K˜K˜—šžœ˜K˜—Kšžœ˜—K˜K˜K˜—š Ÿœžœžœžœžœ ˜AKš œžœžœžœ žœ˜>Kš œ žœžœžœ žœ˜DKšœ(žœ˜,Kš œžœžœžœžœ˜K˜(K˜ K˜šžœžœžœ ž˜šžœžœžœ ž˜šžœžœžœ ž˜šžœžœžœ ž˜K˜K˜ K˜ K˜ šžœžœ˜%K˜K˜K˜K˜—šžœ˜K˜—Kšžœ˜—Kšžœ˜—Kšžœ˜—Kšžœ˜—K˜K˜K˜—š Ÿœžœžœžœžœ ˜AKš œžœžœžœ žœ˜>Kš œ žœžœžœ žœ˜DKšœ(žœ˜,Kš œžœžœžœžœ˜K˜(K˜ K˜šžœžœžœ ž˜šžœžœžœ ž˜šžœžœžœ ž˜K˜K˜ K˜ šžœžœ˜%K˜K˜K˜K˜—šžœ˜K˜—Kšžœ˜—Kšžœ˜—Kšžœ˜—K˜K˜K˜—š Ÿœžœžœžœžœ ˜AKš œžœžœžœ žœ˜>Kš œ žœžœžœ žœ˜DKšœ(žœ˜,Kš œžœžœžœžœ˜K˜(K˜ K˜šžœžœžœ ž˜šžœžœžœ ž˜K˜K˜ šžœžœ˜%K˜K˜K˜K˜—šžœ˜K˜—Kšžœ˜—Kšžœ˜—K˜K˜K˜—š Ÿœžœžœžœžœ ˜AKš œžœžœžœ žœ˜>Kš œ žœžœžœ žœ˜DKšœ'žœ˜+Kš œžœžœžœžœ˜K˜(K˜ K˜šžœžœžœ ž˜K˜šžœžœ˜%K˜K˜K˜K˜—šžœ˜K˜—Kšžœ˜—K˜K˜K˜—š Ÿ œžœ žœžœžœ ˜\Kš œ žœžœžœ žœ˜FKš œ žœžœžœ žœ˜?Kš œ žœžœžœ žœ ˜IKš œžœžœžœžœ˜"Kš œ žœžœžœžœ˜&Kš œžœžœžœžœ˜#K˜Fš Ÿ œžœžœžœžœ žœ˜;K˜#K˜—Kšœ˜šžœ˜Kšœ/žœžœ˜GK˜€š žœžœžœžœžœžœž˜=K˜K˜Kšžœ˜—Kšžœ˜—K˜Kšœ˜šœ˜K˜—K˜—šŸœžœžœžœžœžœžœžœžœ˜GKšœH™Hš Ÿ œžœžœžœžœžœ˜BKšœ#™#Kšœžœ˜$K˜—Kšœžœ˜K˜ Kšžœžœžœ˜/K˜ K˜šžœžœ ž˜Kšœžœžœ˜.Kšžœžœžœ˜!šžœžœ˜Kšœžœžœ˜K˜K˜—K˜ šž˜K˜—Kšžœ˜—K˜—K˜Kšžœ˜K™——…—Έ8