Wikka Spellchecker

This is code derived from a class released at Php Classes as a generic PHP Spell Checker and is released under GPL for non-commercial uses. (Version 1.1 with improved punctuation & wikicode removal)

I don't doubt it is less "efficient" than those using packages that are "built into" the server, but it has the advantage that to set it up you don't need server root access, or the permission of your server provider. I'll also apologize that it is so "english" based, but the beauty of using this text-based file system is that non-English words can be added or other dictionaries used instead.

If anyone wants to improve this spellchecker, I think it needs a "regular expression" thing (or something) added somewhere that....
Other slight oddities also crop up (like two words being run together despite the space between them).

I modified the handlers/page/edit.php file by adding this code close to the bottom of the file...
// Spellcheck added by GMB
    if ($_POST["submit"] == "Spellcheck")
include("spellchecker/dictionary_class.php"); // this is the main class and must be included to the main body.
$dr=new dataReader();   // creating a new instance of the class dataReader.
               // this class gets the input text and uses the class LookupTable to find misspelt words.

// instantiate new instance (from jsearchstring from phpclasses.org) to remove punctuation & wikiwords
$jSS=new jSearchString();

//output formatted string
$str = $jSS->parseString($body);

$str= strtolower($str);

// end of Spellcheck code}

The handlers/page/edit.php file was further altered by adding code for a "Spellcheck" button.....
// ORIGINAL LINE          "<input name=\"submit\" type=\"submit\" value=\"Store\" accesskey=\"s\" /> <input name=\"submit\" type=\"submit\" value=\"Preview\" accesskey=\"p\" /> <input type=\"button\" value=\"Cancel\" onClick=\"document.location='".$this->href("")."';\" />\n".
// Line below this has added spellcheck button (GMB)
            "<input name=\"submit\" type=\"submit\" value=\"Store\" accesskey=\"s\" /> <input name=\"submit\" type=\"submit\" value=\"Preview\" accesskey=\"p\" /> <input name=\"submit\" type=\"submit\" value=\"Spellcheck\" /> <input type=\"button\" value=\"Cancel\" onClick=\"document.location='".$this->href("")."';\" />\n".

The dictionary_class.php file (provided at phpclasses) was modified to the following (and placed in the directory "spellchecker" in the wiki root).
//////////////////////////////// Dictionary class originally written by Reza Salehi.     ////////////////////////////////////////////
//////////////////////////////// General Public License.                    ////////////////////////////////////////////
//////////////////////////////// zaalion@yahoo.com, http://zaalion.com          ////////////////////////////////////////////
//////////////////////////////// tel : +98 912 2345463                         ////////////////////////////////////////////
//////////////////////////////// Dec. 2004.                            ////////////////////////////////////////////
//////////////////////////////// JSearchString by Johan De Klerk from PHPCLASSES.org     ////////////////////////////////////////////
//////////////////////////////// Modified by GMBowen for Wikka Wiki Dec. 2004 under GPL  ////////////////////////////////////////////

class hashing
        function hashFunction($str, $len)
                $l = strlen($str);
                //step 1
                for($i=0; $i<$l; $i++)                
                //step 2

class lookupTable
        var $MAX=6967;//6967
        var $MaxWordLength=45;
        var $dictionaryFile="spellchecker/dictionary.txt";
        var $lookupTable;
        var $MAXLen=16;
        function initializeArray()
            for($i=0; $i<$this->MAX; $i++)                 
                for($j=0; $j<$this->MAXLen; $j++)                      
        function readToTable()
                $buffer=""; $n=0;
                $hash=new hashing();
                $count=0; $i=0;
                $fp = fopen ("spellchecker/dictionary.txt", "r");                      
                        $buffer=fgets($fp, $this->MaxWordLength);
                        $index=$hash->hashFunction($buffer, $this->MAX);
                        //---->read process
                        //<--- read process

        function isIn($str)
                $h=new hashing();
                $index=$h->hashFunction($str, $this->MAX);

        function suggestion($str)

                for($i=0; $i<strlen($strC); $i++)
                        for($j=0; $j<26; $j++)
                                $strC[$i]= chr($current++);
                                        if($count>0) print(" , ");
} ;

// modified by GMB from JsearchString
// obtained from phpclasses.org, written by Johan De Klerk released as "Freely Distributable"

class jSearchString {

// other words can be added to this string...probably all actions would be a good idea, and maybe code to list all wikipagenames?  

    var $wikiwords = array("{{google}}", "{{chat}}", "{{showcode}}", "{{hiddenpages}}", "CategoryWiki");
    var $symbols = array('/','\\','\'','"',',','.','<','>','?',';',':','[',']','{','}','|','=','+','-','_',')','(','*','&','^','%','$','#','@','!','~','`');
    function parseString($string) {
        $string = ' '.$string.' ';
        $string = $this->removeWikiwords($string);
        $string = $this->removeSymbols($string);
        return $string;
    function removeWikiwords($string) {
        for ($i = 0; $i < sizeof($this->wikiwords); $i++) {
            $string = str_replace($this->wikiwords[$i],' ',$string);
        //$string = str_replace('  ',' ',$string);
        return trim($string);
    function removeSymbols($string) {
        for ($i = 0; $i < sizeof($this->symbols); $i++) {
            $string = str_replace($this->symbols[$i],'',$string);
        return trim($string);

class dataReader
        function reader($strToCheck)
                $lt=new lookupTable();

                $words=explode(' ', $strToCheck);
                $h=new hashing();
                print("<b>These words are mis-spelled, suggestions for correct spellings are provided :<br></b>");
                for($i=0; $i<count($words); $i++)
                                print("<b>&nbsp;&nbsp;&nbsp;".$buffer." : </b>");
                                $sug=1; //added by GMB

The "dictionary.txt" file may either be downloaded from phpclasses, or is available from my server here (at least for now) and also must be placed in the "spellchecker" directory in the wikka root.

Free Web Counter
Chadwicks of Boston

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki