How to resolve the algorithm I before E except after C step by step in the Modula-2 programming language
How to resolve the algorithm I before E except after C step by step in the Modula-2 programming language
Table of Contents
Problem Statement
The phrase "I before E, except after C" is a widely known mnemonic which is supposed to help when spelling English words.
Using the word list from http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, check if the two sub-clauses of the phrase are plausible individually:
If both sub-phrases are plausible then the original phrase can be said to be plausible. Something is plausible if the number of words having the feature is more than two times the number of words having the opposite feature (where feature is 'ie' or 'ei' preceded or not by 'c' as appropriate).
As a stretch goal use the entries from the table of Word Frequencies in Written and Spoken English: based on the British National Corpus, (selecting those rows with three space or tab separated words only), to see if the phrase is plausible when word frequencies are taken into account.
Show your output here as well as your program.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm I before E except after C step by step in the Modula-2 programming language
Source code in the modula-2 programming language
MODULE IEC;
IMPORT SeqIO;
IMPORT Texts;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
FROM Strings IMPORT Pos;
VAR words, cie, cei, xie, xei: CARDINAL;
xie_plausible, cei_plausible: BOOLEAN;
PROCEDURE Classify(word: ARRAY OF CHAR);
VAR end: CARDINAL;
BEGIN
INC(words);
end := Pos("", word);
IF Pos("ie", word) # end THEN
IF Pos("cie", word) # end
THEN INC(cie);
ELSE INC(xie);
END;
ELSIF Pos("ei", word) # end THEN
IF Pos("cei", word) # end
THEN INC(cei);
ELSE INC(xei);
END;
END;
END Classify;
PROCEDURE ProcessFile(filename: ARRAY OF CHAR);
VAR file: SeqIO.FILE;
dict: Texts.TEXT;
word: ARRAY [0..63] OF CHAR;
fs: SeqIO.FileState;
ts: Texts.TextState;
BEGIN
fs := SeqIO.Open(file, filename);
ts := Texts.Connect(dict, file);
WHILE NOT Texts.EOT(dict) DO
Texts.ReadLn(dict, word);
Classify(word);
END;
ts := Texts.Disconnect(dict);
fs := SeqIO.Close(file);
END ProcessFile;
PROCEDURE WriteStat(name: ARRAY OF CHAR; num: CARDINAL);
BEGIN
WriteString(name);
WriteString(": ");
WriteCard(num, 0);
WriteLn;
END WriteStat;
PROCEDURE Plausible(feature: ARRAY OF CHAR; match, nomatch: CARDINAL): BOOLEAN;
VAR plausible: BOOLEAN;
BEGIN
WriteString(feature);
WriteString(": ");
plausible := 2 * match > nomatch;
IF NOT plausible THEN
WriteString("not ");
END;
WriteString("plausible.");
WriteLn;
RETURN plausible;
END Plausible;
BEGIN
words := 0;
cie := 0;
cei := 0;
xie := 0;
xei := 0;
ProcessFile("unixdict.txt");
WriteStat("Amount of words", words);
WriteStat("CIE", cie);
WriteStat("xIE", xie);
WriteStat("CEI", cei);
WriteStat("xEI", xei);
WriteLn;
xie_plausible :=
Plausible("I before E when not preceded by C", xie, cie);
cei_plausible :=
Plausible("E before I when preceded by C", cei, xei);
WriteString("I before E, except after C: ");
IF NOT (xie_plausible AND cei_plausible) THEN
WriteString("not ");
END;
WriteString("plausible.");
WriteLn;
END IEC.
You may also check:How to resolve the algorithm Universal Turing machine step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Variable size/Set step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the C# programming language
You may also check:How to resolve the algorithm Steffensen's method step by step in the Nim programming language