How to resolve the algorithm I before E except after C step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm I before E except after C step by step in the zkl 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 zkl programming language

Source code in the zkl programming language

fcn wcnt(wordList,altrs,aAdjust,bltrs,bAdjust,text){
   a:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(altrs) },0) - aAdjust;
   b:=wordList.reduce('wrap(cnt,word){ cnt+word.holds(bltrs) },0) - bAdjust;
   ratio:=a.toFloat()/b;
   "%s is %splausible".fmt(text,ratio<2 and "im" or "").println();
   "  %d cases for and %d cases against is a ratio of %.3f.".fmt(a,b,ratio).println();
   return(a,b,ratio);
}
wordList:=File("unixdict.txt").read();

a,b,r1:=wcnt(wordList,"cei",0,"cie",0,"E before I when preceded by C");
_,_,r2:=wcnt(wordList,"ie",b,"ei",a,  "I before E when not preceded by C");
"Overall the rule is %splausible".fmt((r1<2 or r2<2) and "im" or "").println();

fcn wc2(wordList,altrs,aAdjust,bltrs,bAdjust,text){
   a,b:=wordList.reduce('wrap(cnts,line){
      // don't care if line is "Word PoS Freq" or "as yet Adv 14"
      word,_,n:=line.split();  
      if(word.holds(altrs)) cnts[0]=cnts[0]+n;
      if(word.holds(bltrs)) cnts[1]=cnts[1]+n;
      cnts
   },L(0,0));
   a-=aAdjust; b-=bAdjust;
   ratio:=a.toFloat()/b;
   "%s is %splausible".fmt(text,ratio<2 and "im" or "").println();
   "  %d cases for and %d cases against is a ratio of %.3f.".fmt(a,b,ratio).println();
   return(a,b,ratio);
}
wordList:=File("1_2_all_freq.txt").read();

  

You may also check:How to resolve the algorithm Calendar step by step in the Fortran programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the Rust programming language
You may also check:How to resolve the algorithm Elliptic Curve Digital Signature Algorithm step by step in the Wren programming language
You may also check:How to resolve the algorithm Search a list step by step in the Action! programming language
You may also check:How to resolve the algorithm Exceptions step by step in the OCaml programming language