⚠️ This article was originally published in 2005 at dubi.org/spell-checker. The content is extremely outdated and is preserved here for nostalgic purposes only.
I was bored so I wrote a spell checker. I played around with making a realtime spell checker but someone beat me to it (read: I couldn’t get it working properly).
This spell checker uses the SCOWL word list and the DoubleMetaphone phonetic algorithm for suggestions.
Source Code
<?php
/*************************************************************Spell Checker by Alan NouriDoubleMetaphone by Stephen WoodbridgeWord list by Kevin Atkinson**************************************************************/
/* ------------------------ SETTINGS ------------------------------- */$debug = false; // when true, adds several tracers$max_suggestions = 8; // max amount of suggestions displayed$try_for = 3; // try hard to get this many suggestions$try_hard_for = 1; // perform the cpu intensive stuff to // get at least this many suggestions$leniency = 2; // max allowed levenshtein edit dist is // strlen(word) / $leniency
$host = 'xxxx'; // database connection settings$user = 'xxxx';$pass = 'xxxx';$dbase = 'xxxx';
$self = $_SERVER['PHP_SELF']; // this page/* ----------------------------------------------------------------- */
$timestart = microtime(); // start time counter$correct = false;$diff1 = $diff2 = $diff3 = $diff4 = $diff5 = 0;$suggestions = array();
require 'DoubleMetaphone.php';
// sort based on rank and then lev edit distance// 1 = primary metaphone// 2 = secondary metaphone// 3 = random crapfunction compareByLev($a, $b) { if ($a['rank'] != $b['rank']) { return $a['rank'] - $b['rank']; } return ($a['lev'] - $b['lev']);}
// case sensitive? i don't think sofunction levenshtein_helper($str1, $str2) { return levenshtein(strtolower($str1), strtolower($str2));}
if ($debug) { echo '<h1>DEBUGGING MODE ON</h1>';}
?>
<p><form action="<?=$self?>" method="GET">Word: <input type="text" name="word"> <input type="submit" value="Lookup"></form><p>
<?php
if (!$_GET['word']) { echo "<p>Specify a word</p>";}else { // grab the input, sanitize it if (get_magic_quotes_gpc()) { $word = mysql_escape_string(strip_tags(stripslashes($_GET['word']))); $niceword = strip_tags(stripslashes($_GET['word'])); } else { $word = mysql_escape_string(strip_tags($_GET['word'])); $niceword = strip_tags($_GET['word']); }
if (!preg_match("/^([a-zA-Z]|'|-)+$/", $niceword)) { echo "<p>Invalid word</p>"; } else { $max_allowed_lev = strlen($word) / $leniency;
$link = mysql_connect($host, $user, $pass) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbase) or die('Could not select database');
// check for word $query = "SELECT DISTINCT Word FROM Words WHERE Word = '$word' OR Word = LOWER('$word')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<b><p>"; if ($row = mysql_fetch_assoc($result)) { echo "$niceword found!"; $correct = true; } else { echo "$niceword not found :("; } echo "</b></p>";
// end time $lookupend = microtime(); $diff1 = number_format(((substr($lookupend,0,9)) + (substr($lookupend,-10)) - (substr($timestart,0,9)) - (substr($timestart,-10))),4);
if ($correct) { echo "<b>------------------------------------------------------------------</b><br>\n"; echo "<p>Lookup time: $diff1 </p>\n"; } else { echo "<p><b>Suggestions:</b></p>";
//**************************************************************************** // check for corrections (ONLY PRIMARY FOR NOW) $metaphone = double_metaphone($word);
$query = "SELECT Word FROM Words W, PrimaryMetaphones PM WHERE PM.Metaphone = '$metaphone[primary]' AND PM.Wid = W.Id"; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
// grab suggestions while ($row = mysql_fetch_assoc($result)) { $suggestions[$row['Word']] = 1; if ($debug) echo "adding1: ", $row['Word'], "<br>"; }
// primary suggestion time $suggestionend = microtime(); $diff2 = number_format(((substr($suggestionend,0,9)) + (substr($suggestionend,-10)) - (substr($lookupend,0,9)) - (substr($lookupend,-10))),4);
// filter out stuff with high edit distances foreach ($suggestions as $suggestion => $rank) { $lev = levenshtein_helper($word, $suggestion); if ($lev > $max_allowed_lev) { unset($suggestions[$suggestion]); if ($debug) echo "erasing1[$lev]: ", $suggestion, "<br>"; } }
//**************************************************************************** // check for secondary metaphones if no suggestions found yet if (count($suggestions) < $try_for) { $metaphone = double_metaphone($word);
$query = "SELECT Word FROM Words W, SecondaryMetaphones PM WHERE PM.Metaphone = '$metaphone[secondary]' AND PM.Wid = W.Id"; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
// grab suggestions while ($row = mysql_fetch_assoc($result)) { if (!$suggestions[$row['Word']]) { $suggestions[$row['Word']] = 2; if ($debug) echo "adding2: ", $row['Word'], "<br>"; } }
// filter out stuff with high edit distances foreach ($suggestions as $suggestion => $rank) { $lev = levenshtein_helper( $word, $suggestion ); if ($lev > $max_allowed_lev) { unset($suggestions[$suggestion]); if ($debug) echo "erasing2[$lev]: ", $suggestion, "<br>"; } }
// suggestion time $secsuggestionend = microtime(); $diff3 = number_format(((substr($secsuggestionend,0,9)) + (substr($secsuggestionend,-10)) - (substr($suggestionend,0,9)) - (substr($suggestionend,-10))),4); }
//**************************************************************************** // do some kind of crazy shit to find some suggestions because this guy doesn't know how to spell :( if (count($suggestions) < $try_for) { // check for the uppercase and lowercase versions? $query = "SELECT DISTINCT Word FROM Words WHERE Word = UPPER('$word') OR Word = LOWER('$word')";
// get every combination of the word with two letters reversed for ($i=0; $i+1 < strlen($word); $i++) { // don't reverse certain characters if ($word[$i] == '\\' || $word[$i+1] == '\\' || $word[$i] == '\'' || $word[$i+1] == '\'') { continue; } $newword = substr($word, 0, $i); $newword .= $word[$i+1]; $newword .= $word[$i]; $newword .= substr($word, $i+2);
$query .= " OR Word = '$newword' "; }
// get every combination of the word with one letter removed for ($i=0; $i < strlen($word); $i++) { // don't remove backslashes if ($word[$i] == '\\' || $word[$i] == '\'') { continue; } $newword = ""; if ($i != 0) { $newword = substr($word, 0, $i); } $newword .= substr($word, $i+1); $query .= " OR "; $query .= " Word = '$newword' "; }
if ($debug) echo $query, "<br>"; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
// grab suggestions while ($row = mysql_fetch_assoc($result)) { if (!$suggestions[$row['Word']]) { $suggestions[$row['Word']] = 3; } if ($debug) echo "adding3: ", $row['Word'], "<br>"; }
// filter out stuff with high edit distances foreach ($suggestions as $suggestion => $rank) { $lev = levenshtein_helper( $word, $suggestion ); if ($lev > $max_allowed_lev) { unset($suggestions[$suggestion]); if ($debug) echo "erasing3[$lev]: ", $suggestion, "<br>"; } }
// suggestion time $editsuggestionend = microtime(); $diff4 = number_format(((substr($editsuggestionend,0,9)) + (substr($editsuggestionend,-10)) - (substr($secsuggestionend,0,9)) - (substr($secsuggestionend,-10))),4); }
//**************************************************************************** // save the CPU intensive stuff for here... this guy is absolutely the worst speller in the world! :( // ONLY do these searches when there are no other matches if (count($suggestions) < $try_hard_for) { $query = "SELECT DISTINCT Word FROM Words WHERE";
// get every combination of the word with one letter as a wildcard (except for the first) for ($i=1; $i < strlen($word); $i++) { // don't wildcard backslashes if ($word[$i] == '\\') { continue; } $newword = ""; $newword = substr($word, 0, $i); $newword .= '_'; if ($i != strlen($word)) { $newword .= substr($word, $i+1); } if ($i != 1) { $query .= " OR "; } $query .= " Word LIKE '$newword' "; }
// get every combination of the word with one wildcard inserted (except for the first) for ($i=1; $i < strlen($word); $i++) { // don't insert wildcards after slashes if ($word[$i] == '\\' || $word[$i+1] == '\\' || $word[$i] == '\'' || $word[$i+1] == '\'') { continue; } $newword = ""; $newword = substr($word, 0, $i); $newword .= '_'; if ($i != strlen($word)) { $newword .= substr($word, $i); } $query .= " OR "; $query .= " Word LIKE '$newword' "; }
if ($debug) echo $query, "<br>"; $result = mysql_query($query) or die('Query failed: ' . mysql_error());
// grab suggestions while ($row = mysql_fetch_assoc($result)) { if (!$suggestions[$row['Word']]) { $suggestions[$row['Word']] = 4; } if ($debug) echo "adding4: ", $row['Word'], "<br>"; }
// filter out stuff with high edit distances foreach ($suggestions as $suggestion => $rank) { $lev = levenshtein_helper( $word, $suggestion ); if ($lev > $max_allowed_lev) { unset($suggestions[$suggestion]); if ($debug) echo "erasing4[$lev]: ", $suggestion, "<br>"; } }
// suggestion time $cpusuggestionend = microtime(); $diff5 = number_format(((substr($cpusuggestionend,0,9)) + (substr($cpusuggestionend,-10)) - (substr($editsuggestionend,0,9)) - (substr($editsuggestionend,-10))),4); }
// DISPLAY SUGGESTIONS **************************** // calculate levenshtein edit distance
if (empty($suggestions)) { echo '<p><i>My only suggestion is that you learn to spell :(</i></p>'; } else { foreach ($suggestions as $suggestion => $rank) { $lev = levenshtein_helper( $word, $suggestion ); $results[] = array( 'lev' => $lev, 'suggestion' => $suggestion, 'rank' => $rank ); }
// sort by levenshtein edit distance usort( $results, 'compareByLev' );
// display 8 suggestions $num = 0; foreach ($results as $result) { $num++; if ($result['lev'] > $max_allowed_lev || $num > $max_suggestions) break;
echo $result['suggestion'], "<sup>$result[rank]</sup>", '<br>'; } }
// total time $total = $diff1 + $diff2 + $diff3 + $diff4 + $diff5;
// display time echo "<b>------------------------------------------------------------------</b><br>\n"; echo "[0] Lookup time: $diff1 <br>\n"; echo "[1] Primary Metaphone Suggestion lookup time: $diff2 <br>\n"; if ($diff3) echo "[2] Secondary Metaphone Suggestion lookup time: $diff3 <br>\n"; if ($diff4) echo "[3] Close Edits Suggestion lookup time: $diff4 <br>\n"; if ($diff5) echo "[4] CPU-Intensive Close Edits Suggestion lookup time: $diff5 <br>\n"; if ($diff5) echo "[5] Some number I just RANDOMLY made up: ". rand(1,9)/10000 ." <br>\n"; echo "Total time: $total <br>\n"; } }}
echo '<br>';?>
<?php// VERSION DoubleMetaphone Class 1.01//// DESCRIPTION//// This class implements a "sounds like" algorithm developed// by Lawrence Philips which he published in the June, 2000 issue// of C/C++ Users Journal. Double Metaphone is an improved// version of Philips' original Metaphone algorithm.//// COPYRIGHT//// Copyright 2001, Stephen Woodbridge <[email protected]>// All rights reserved.//// http://swoodbridge.com/DoubleMetaPhone///// This PHP translation is based heavily on the C implementation// by Maurice Aubrey <[email protected]>, which in turn// is based heavily on the C++ implementation by// Lawrence Philips and incorporates several bug fixes courtesy// of Kevin Atkinson <[email protected]>.//// This module is free software; you may redistribute it and/or// modify it under the same terms as Perl itself.//// CONTRIBUTIONS//// 17-May-2002 Geoff Caplan http://www.advantae.com// Bug fix: added code to return class object which I forgot to do// Created a functional callable version instead of the class version// which is faster if you are calling this a lot.//// ------------------------------------------------------------------
class DoubleMetaPhone{// properties
var $original = ""; var $primary = ""; var $secondary = ""; var $length = 0; var $last = 0; var $current = 0;
// methods
// Public method
function DoubleMetaPhone($string) {
$this->primary = ""; $this->secondary = ""; $this->current = 0;
$this->current = 0; $this->length = strlen($string); $this->last = $this->length - 1; $this->original = $string . " ";
$this->original = strtoupper($this->original);
// skip this at beginning of word if ($this->StringAt($this->original, 0, 2, array('GN', 'KN', 'PN', 'WR', 'PS'))) $this->current++;
// Initial 'X' is pronounced 'Z' e.g. 'Xavier' if (substr($this->original, 0, 1) == 'X') { $this->primary .= "S"; // 'Z' maps to 'S' $this->secondary .= "S"; $this->current++; }
// main loop
while (strlen($this->primary) < 4 || strlen($this->secondary < 4)) { if ($this->current >= $this->length) break;
switch (substr($this->original, $this->current, 1)) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y': if ($this->current == 0) { // all init vowels now map to 'A' $this->primary .= 'A'; $this->secondary .= 'A'; } $this->current += 1; break;
case 'B': // '-mb', e.g. "dumb", already skipped over ... $this->primary .= 'P'; $this->secondary .= 'P';
if (substr($this->original, $this->current + 1, 1) == 'B') $this->current += 2; else $this->current += 1; break;
case '�': $this->primary .= 'S'; $this->secondary .= 'S'; $this->current += 1; break;
case 'C': // various gremanic if (($this->current > 1) && !$this->IsVowel($this->original, $this->current - 2) && $this->StringAt($this->original, $this->current - 1, 3, array("ACH")) && ((substr($this->original, $this->current + 2, 1) != 'I') && ((substr($this->original, $this->current + 2, 1) != 'E') || $this->StringAt($this->original, $this->current - 2, 6, array("BACHER", "MACHER"))))) {
$this->primary .= 'K'; $this->secondary .= 'K'; $this->current += 2; break; }
// special case 'caesar' if (($this->current == 0) && $this->StringAt($this->original, $this->current, 6, array("CAESAR"))) { $this->primary .= 'S'; $this->secondary .= 'S'; $this->current += 2; break; }
// italian 'chianti' if ($this->StringAt($this->original, $this->current, 4, array("CHIA"))) { $this->primary .= 'K'; $this->secondary .= 'K'; $this->current += 2; break; }
if ($this->StringAt($this->original, $this->current, 2, array("CH"))) {
// find 'michael' if (($this->current > 0) && $this->StringAt($this->original, $this->current, 4, array("CHAE"))) { $this->primary .= 'K'; $this->secondary .= 'X'; $this->current += 2; break; }
// greek roots e.g. 'chemistry', 'chorus' if (($this->current == 0) && ($this->StringAt($this->original, $this->current + 1, 5, array("HARAC", "HARIS")) || $this->StringAt($this->original, $this->current + 1, 3, array("HOR", "HYM", "HIA", "HEM"))) && !$this->StringAt($this->original, 0, 5, array("CHORE"))) { $this->primary .= 'K'; $this->secondary .= 'K'; $this->current += 2; break; }
// germanic, greek, or otherwise 'ch' for 'kh' sound if (($this->StringAt($this->original, 0, 4, array("VAN ", "VON ")) || $this->StringAt($this->original, 0, 3, array("SCH"))) // 'architect' but not 'arch', orchestra', 'orchid' || $this->StringAt($this->original, $this->current - 2, 6, array("ORCHES", "ARCHIT", "ORCHID")) || $this->StringAt($this->original, $this->current + 2, 1, array("T", "S")) || (($this->StringAt($this->original, $this->current - 1, 1, array("A","O","U","E")) || ($this->current == 0)) // e.g. 'wachtler', 'weschsler', but not 'tichner' && $this->StringAt($this->original, $this->current + 2, 1, array("L","R","N","M","B","H","F","V","W"," ")))) { $this->primary .= 'K'; $this->secondary .= 'K'; } else { if ($this->current > 0) { if ($this->StringAt($this->original, 0, 2, array("MC"))) { // e.g. 'McHugh' $this->primary .= 'K'; $this->secondary .= 'K'; } else { $this->primary .= 'X'; $this->secondary .= 'K'; } } else { $this->primary .= 'X'; $this->secondary .= 'X'; } } $this->current += 2; break; }
// e.g. 'czerny' if ($this->StringAt($this->original, $this->current, 2, array("CZ")) && !$this->StringAt($this->original, $this->current -2, 4, array("WICZ"))) { $this->primary .= 'S'; $this->secondary .= 'X'; $this->current += 2; break; }
// e.g. 'focaccia' if ($this->StringAt($this->original, $this->current + 1, 3, array("CIA"))) { $this->primary .= 'X'; $this->secondary .= 'X'; $this->current += 3; break; }
// double 'C', but not McClellan' if ($this->StringAt($this->original, $this->current, 2, array("CC")) && !(($this->current == 1) && (substr($this->original, 0, 1) == 'M'))) { // 'bellocchio' but not 'bacchus' if ($this->StringAt($this->original, $this->current + 2, 1, array("I","E","H")) && !$this->StringAt($this->original, $this->current + 2, 2, array("HU"))) { // 'accident', 'accede', 'succeed' if ((($this->current == 1) && (substr($this->original, $this->current - 1, 1) == 'A')) || $this->StringAt($this->original, $this->current - 1, 5, array("UCCEE", "UCCES"))) { $this->primary .= "KS"; $this->secondary .= "KS"; // 'bacci', 'bertucci', other italian } else { $this->primary .= "X"; $this->secondary .= "X"; } $this->current += 3; break; } else { // Pierce's rule $this->primary .= "K"; $this->secondary .= "K"; $this->current += 2; break; } }
if ($this->StringAt($this->original, $this->current, 2, array("CK","CG","CQ"))) { $this->primary .= "K"; $this->secondary .= "K"; $this->current += 2; break; }
if ($this->StringAt($this->original, $this->current, 2, array("CI","CE","CY"))) { // italian vs. english if ($this->StringAt($this->original, $this->current, 3, array("CIO","CIE","CIA"))) { $this->primary .= "S"; $this->secondary .= "X"; } else { $this->primary .= "S"; $this->secondary .= "S"; } $this->current += 2; break; }
// else $this->primary .= "K"; $this->secondary .= "K";
// name sent in 'mac caffrey', 'mac gregor' if ($this->StringAt($this->original, $this->current + 1, 2, array(" C"," Q"," G"))) { $this->current += 3; } else { if ($this->StringAt($this->original, $this->current + 1, 1, array("C","K","Q")) && !$this->StringAt($this->original, $this->current + 1, 2, array("CE","CI"))) { $this->current += 2; } else { $this->current += 1; } } break;
case 'D': if ($this->StringAt($this->original, $this->current, 2, array("DG"))) { if ($this->StringAt($this->original, $this->current + 2, 1, array("I","E","Y"))) { // e.g. 'edge' $this->primary .= "J"; $this->secondary .= "J"; $this->current += 3; break; } else { // e.g. 'edgar' $this->primary .= "TK"; $this->secondary .= "TK"; $this->current += 2; break; } }
if ($this->StringAt($this->original, $this->current, 2, array("DT","DD"))) { $this->primary .= "T"; $this->secondary .= "T"; $this->current += 2; break; }
// else $this->primary .= "T"; $this->secondary .= "T"; $this->current += 1; break;
case 'F': if (substr($this->original, $this->current + 1, 1) == 'F') $this->current += 2; else $this->current += 1; $this->primary .= "F"; $this->secondary .= "F"; break;
case 'G': if (substr($this->original, $this->current + 1, 1) == 'H') { if (($this->current > 0) && !$this->IsVowel($this->original, $this->current - 1)) { $this->primary .= "K"; $this->secondary .= "K"; $this->current += 2; break; }
if ($this->current < 3) { // 'ghislane', 'ghiradelli' if ($this->current == 0) { if (substr($this->original, $this->current + 2, 1) == 'I') { $this->primary .= "J"; $this->secondary .= "J"; } else { $this->primary .= "K"; $this->secondary .= "K"; } $this->current += 2; break; } }
// Parker's rule (with some further refinements) - e.g. 'hugh' if ((($this->current > 1) && $this->StringAt($this->original, $this->current - 2, 1, array("B","H","D"))) // e.g. 'bough' || (($this->current > 2) && $this->StringAt($this->original, $this->current - 3, 1, array("B","H","D"))) // e.g. 'broughton' || (($this->current > 3) && $this->StringAt($this->original, $this->current - 4, 1, array("B","H")))) { $this->current += 2; break; } else { // e.g. 'laugh', 'McLaughlin', 'cough', 'gough', 'rough', 'tough' if (($this->current > 2) && (substr($this->original, $this->current - 1, 1) == 'U') && $this->StringAt($this->original, $this->current - 3, 1, array("C","G","L","R","T"))) { $this->primary .= "F"; $this->secondary .= "F"; } elseif (($this->current > 0) && substr($this->original, $this->current - 1, 1) != 'I') { $this->primary .= "K"; $this->secondary .= "K"; } $this->current += 2; break; } }
if (substr($this->original, $this->current + 1, 1) == 'N') { if (($this->current == 1) && $this->IsVowel($this->original, 0) && !$this->SlavoGermanic($this->original)) { $this->primary .= "KN"; $this->secondary .= "N"; } else { // not e.g. 'cagney' if (!$this->StringAt($this->original, $this->current + 2, 2, array("EY")) && (substr($this->original, $this->current + 1) != "Y") && !$this->SlavoGermanic($this->original)) { $this->primary .= "N"; $this->secondary .= "KN"; } else { $this->primary .= "KN"; $this->secondary .= "KN"; } } $this->current += 2; break; }
// 'tagliaro' if ($this->StringAt($this->original, $this->current + 1, 2, array("LI")) && !$this->SlavoGermanic($this->original)) { $this->primary .= "KL"; $this->secondary .= "L"; $this->current += 2; break; }
// -ges-, -gep-, -gel- at beginning if (($this->current == 0) && ((substr($this->original, $this->current + 1, 1) == 'Y') || $this->StringAt($this->original, $this->current + 1, 2, array("ES","EP","EB","EL","EY","IB","IL","IN","IE", "EI","ER")))) { $this->primary .= "K"; $this->secondary .= "J"; $this->current += 2; break; }
// -ger-, -gy- if (($this->StringAt($this->original, $this->current + 1, 2, array("ER")) || (substr($this->original, $this->current + 1, 1) == 'Y')) && !$this->StringAt($this->original, 0, 6, array("DANGER","RANGER","MANGER")) && !$this->StringAt($this->original, $this->current -1, 1, array("E", "I")) && !$this->StringAt($this->original, $this->current -1, 3, array("RGY","OGY"))) { $this->primary .= "K"; $this->secondary .= "J"; $this->current += 2; break; }
// italian e.g. 'biaggi' if ($this->StringAt($this->original, $this->current + 1, 1, array("E","I","Y")) || $this->StringAt($this->original, $this->current -1, 4, array("AGGI","OGGI"))) { // obvious germanic if (($this->StringAt($this->original, 0, 4, array("VAN ", "VON ")) || $this->StringAt($this->original, 0, 3, array("SCH"))) || $this->StringAt($this->original, $this->current + 1, 2, array("ET"))) { $this->primary .= "K"; $this->secondary .= "K"; } else { // always soft if french ending if ($this->StringAt($this->original, $this->current + 1, 4, array("IER "))) { $this->primary .= "J"; $this->secondary .= "J"; } else { $this->primary .= "J"; $this->secondary .= "K"; } } $this->current += 2; break; }
if (substr($this->original, $this->current +1, 1) == 'G') $this->current += 2; else $this->current += 1;
$this->primary .= 'K'; $this->secondary .= 'K'; break;
case 'H': // only keep if first & before vowel or btw. 2 vowels if ((($this->current == 0) || $this->IsVowel($this->original, $this->current - 1)) && $this->IsVowel($this->original, $this->current + 1)) { $this->primary .= 'H'; $this->secondary .= 'H'; $this->current += 2; } else $this->current += 1; break;
case 'J': // obvious spanish, 'jose', 'san jacinto' if ($this->StringAt($this->original, $this->current, 4, array("JOSE")) || $this->StringAt($this->original, 0, 4, array("SAN "))) { if ((($this->current == 0) && (substr($this->original, $this->current + 4, 1) == ' ')) || $this->StringAt($this->original, 0, 4, array("SAN "))) { $this->primary .= 'H'; $this->secondary .= 'H'; } else { $this->primary .= "J"; $this->secondary .= 'H'; } $this->current += 1; break; }
if (($this->current == 0) && !$this->StringAt($this->original, $this->current, 4, array("JOSE"))) { $this->primary .= 'J'; // Yankelovich/Jankelowicz $this->secondary .= 'A'; } else { // spanish pron. of .e.g. 'bajador' if ($this->IsVowel($this->original, $this->current - 1) && !$this->SlavoGermanic($this->original) && ((substr($this->original, $this->current + 1, 1) == 'A') || (substr($this->original, $this->current + 1, 1) == 'O'))) { $this->primary .= "J"; $this->secondary .= "H"; } else { if ($this->current == $this->last) { $this->primary .= "J"; $this->secondary .= ""; } else { if (!$this->StringAt($this->original, $this->current + 1, 1, array("L","T","K","S","N","M","B","Z")) && !$this->StringAt($this->original, $this->current - 1, 1, array("S","K","L"))) { $this->primary .= "J"; $this->secondary .= "J"; } } } }
if (substr($this->original, $this->current + 1, 1) == 'J') // it could happen $this->current += 2; else $this->current += 1; break;
case 'K': if (substr($this->original, $this->current + 1, 1) == 'K') $this->current += 2; else $this->current += 1; $this->primary .= "K"; $this->secondary .= "K"; break;
case 'L': if (substr($this->original, $this->current + 1, 1) == 'L') { // spanish e.g. 'cabrillo', 'gallegos' if ((($this->current == ($this->length - 3)) && $this->StringAt($this->original, $this->current - 1, 4, array("ILLO","ILLA","ALLE"))) || (($this->StringAt($this->original, $this->last-1, 2, array("AS","OS")) || $this->StringAt($this->original, $this->last, 1, array("A","O"))) && $this->StringAt($this->original, $this->current - 1, 4, array("ALLE")))) { $this->primary .= "L"; $this->secondary .= ""; $this->current += 2; break; } $this->current += 2; } else $this->current += 1; $this->primary .= "L"; $this->secondary .= "L"; break;
case 'M': if (($this->StringAt($this->original, $this->current - 1, 3, array("UMB")) && ((($this->current + 1) == $this->last) || $this->StringAt($this->original, $this->current + 2, 2, array("ER")))) // 'dumb', 'thumb' || (substr($this->original, $this->current + 1, 1) == 'M')) { $this->current += 2; } else { $this->current += 1; } $this->primary .= "M"; $this->secondary .= "M"; break;
case 'N': if (substr($this->original, $this->current + 1, 1) == 'N') $this->current += 2; else $this->current += 1; $this->primary .= "N"; $this->secondary .= "N"; break;
case '�': $this->current += 1; $this->primary .= "N"; $this->secondary .= "N"; break;
case 'P': if (substr($this->original, $this->current + 1, 1) == 'H') { $this->current += 2; $this->primary .= "F"; $this->secondary .= "F"; break; }
// also account for "campbell" and "raspberry" if ($this->StringAt($this->original, $this->current + 1, 1, array("P","B"))) $this->current += 2; else $this->current += 1; $this->primary .= "P"; $this->secondary .= "P"; break;
case 'Q': if (substr($this->original, $this->current + 1, 1) == 'Q') $this->current += 2; else $this->current += 1; $this->primary .= "K"; $this->secondary .= "K"; break;
case 'R': // french e.g. 'rogier', but exclude 'hochmeier' if (($this->current == $this->last) && !$this->SlavoGermanic($this->original) && $this->StringAt($this->original, $this->current - 2, 2, array("IE")) && !$this->StringAt($this->original, $this->current - 4, 2, array("ME","MA"))) { $this->primary .= ""; $this->secondary .= "R"; } else { $this->primary .= "R"; $this->secondary .= "R"; } if (substr($this->original, $this->current + 1, 1) == 'R') $this->current += 2; else $this->current += 1; break;
case 'S': // special cases 'island', 'isle', 'carlisle', 'carlysle' if ($this->StringAt($this->original, $this->current - 1, 3, array("ISL","YSL"))) { $this->current += 1; break; }
// special case 'sugar-' if (($this->current == 0) && $this->StringAt($this->original, $this->current, 5, array("SUGAR"))) { $this->primary .= "X"; $this->secondary .= "S"; $this->current += 1; break; }
if ($this->StringAt($this->original, $this->current, 2, array("SH"))) { // germanic if ($this->StringAt($this->original, $this->current + 1, 4, array("HEIM","HOEK","HOLM","HOLZ"))) { $this->primary .= "S"; $this->secondary .= "S"; } else { $this->primary .= "X"; $this->secondary .= "X"; } $this->current += 2; break; }
// italian & armenian if ($this->StringAt($this->original, $this->current, 3, array("SIO","SIA")) || $this->StringAt($this->original, $this->current, 4, array("SIAN"))) { if (!$this->SlavoGermanic($this->original)) { $this->primary .= "S"; $this->secondary .= "X"; } else { $this->primary .= "S"; $this->secondary .= "S"; } $this->current += 3; break; }
// german & anglicisations, e.g. 'smith' match 'schmidt', 'snider' match 'schneider' // also, -sz- in slavic language altho in hungarian it is pronounced 's' if ((($this->current == 0) && $this->StringAt($this->original, $this->current + 1, 1, array("M","N","L","W"))) || $this->StringAt($this->original, $this->current + 1, 1, array("Z"))) { $this->primary .= "S"; $this->secondary .= "X"; if ($this->StringAt($this->original, $this->current + 1, 1, array("Z"))) $this->current += 2; else $this->current += 1; break; }
if ($this->StringAt($this->original, $this->current, 2, array("SC"))) { // Schlesinger's rule if (substr($this->original, $this->current + 2, 1) == 'H') // dutch origin, e.g. 'school', 'schooner' if ($this->StringAt($this->original, $this->current + 3, 2, array("OO","ER","EN","UY","ED","EM"))) { // 'schermerhorn', 'schenker' if ($this->StringAt($this->original, $this->current + 3, 2, array("ER","EN"))) { $this->primary .= "X"; $this->secondary .= "SK"; } else { $this->primary .= "SK"; $this->secondary .= "SK"; } $this->current += 3; break; } else { if (($this->current == 0) && !$this->IsVowel($this->original, 3) && (substr($this->original, $this->current + 3, 1) != 'W')) { $this->primary .= "X"; $this->secondary .= "S"; } else { $this->primary .= "X"; $this->secondary .= "X"; } $this->current += 3; break; }
if ($this->StringAt($this->original, $this->current + 2, 1, array("I","E","Y"))) { $this->primary .= "S"; $this->secondary .= "S"; $this->current += 3; break; }
// else $this->primary .= "SK"; $this->secondary .= "SK"; $this->current += 3; break; }
// french e.g. 'resnais', 'artois' if (($this->current == $this->last) && $this->StringAt($this->original, $this->current - 2, 2, array("AI","OI"))) { $this->primary .= ""; $this->secondary .= "S"; } else { $this->primary .= "S"; $this->secondary .= "S"; }
if ($this->StringAt($this->original, $this->current + 1, 1, array("S","Z"))) $this->current += 2; else $this->current += 1; break;
case 'T': if ($this->StringAt($this->original, $this->current, 4, array("TION"))) { $this->primary .= "X"; $this->secondary .= "X"; $this->current += 3; break; }
if ($this->StringAt($this->original, $this->current, 3, array("TIA","TCH"))) { $this->primary .= "X"; $this->secondary .= "X"; $this->current += 3; break; }
if ($this->StringAt($this->original, $this->current, 2, array("TH")) || $this->StringAt($this->original, $this->current, 3, array("TTH"))) { // special case 'thomas', 'thames' or germanic if ($this->StringAt($this->original, $this->current + 2, 2, array("OM","AM")) || $this->StringAt($this->original, 0, 4, array("VAN ","VON ")) || $this->StringAt($this->original, 0, 3, array("SCH"))) { $this->primary .= "T"; $this->secondary .= "T"; } else { $this->primary .= "0"; $this->secondary .= "T"; } $this->current += 2; break; }
if ($this->StringAt($this->original, $this->current + 1, 1, array("T","D"))) $this->current += 2; else $this->current += 1; $this->primary .= "T"; $this->secondary .= "T"; break;
case 'V': if (substr($this->original, $this->current + 1, 1) == 'V') $this->current += 2; else $this->current += 1; $this->primary .= "F"; $this->secondary .= "F"; break;
case 'W': // can also be in middle of word if ($this->StringAt($this->original, $this->current, 2, array("WR"))) { $this->primary .= "R"; $this->secondary .= "R"; $this->current += 2; break; }
if (($this->current == 0) && ($this->IsVowel($this->original, $this->current + 1) || $this->StringAt($this->original, $this->current, 2, array("WH")))) { // Wasserman should match Vasserman if ($this->IsVowel($this->original, $this->current + 1)) { $this->primary .= "A"; $this->secondary .= "F"; } else { // need Uomo to match Womo $this->primary .= "A"; $this->secondary .= "A"; } }
// Arnow should match Arnoff if ((($this->current == $this->last) && $this->IsVowel($this->original, $this->current - 1)) || $this->StringAt($this->original, $this->current - 1, 5, array("EWSKI","EWSKY","OWSKI","OWSKY")) || $this->StringAt($this->original, 0, 3, array("SCH"))) { $this->primary .= ""; $this->secondary .= "F"; $this->current += 1; break; }
// polish e.g. 'filipowicz' if ($this->StringAt($this->original, $this->current, 4, array("WICZ","WITZ"))) { $this->primary .= "TS"; $this->secondary .= "FX"; $this->current += 4; break; }
// else skip it $this->current += 1; break;
case 'X': // french e.g. breaux if (!(($this->current == $this->last) && ($this->StringAt($this->original, $this->current - 3, 3, array("IAU", "EAU")) || $this->StringAt($this->original, $this->current - 2, 2, array("AU", "OU"))))) { $this->primary .= "KS"; $this->secondary .= "KS"; }
if ($this->StringAt($this->original, $this->current + 1, 1, array("C","X"))) $this->current += 2; else $this->current += 1; break;
case 'Z': // chinese pinyin e.g. 'zhao' if (substr($this->original, $this->current + 1, 1) == "H") { $this->primary .= "J"; $this->secondary .= "J"; $this->current += 2; break; } elseif ($this->StringAt($this->original, $this->current + 1, 2, array("ZO", "ZI", "ZA")) || ($this->SlavoGermanic($this->original) && (($this->current > 0) && substr($this->original, $this->current - 1, 1) != 'T'))) { $this->primary .= "S"; $this->secondary .= "TS"; } else { $this->primary .= "S"; $this->secondary .= "S"; }
if (substr($this->original, $this->current + 1, 1) == 'Z') $this->current += 2; else $this->current += 1; break;
default: $this->current += 1;
} // end switch
// printf("<br>ORIGINAL: '%s'\n", $this->original); // printf("<br>current: '%s'\n", $this->current); // printf("<br> PRIMARY: '%s'\n", $this->primary); // printf("<br> SECONDARY: '%s'\n", $this->secondary);
} // end while
$this->primary = substr($this->primary, 0, 4); $this->secondary = substr($this->secondary, 0, 4);
$result["primary"] = $this->primary ; $result["secondary"] = $this->secondary ;
return $result ;
} // end of function MetaPhone
// Private methods
function StringAt($string, $start, $length, $list) { if (($start <0) || ($start >= strlen($string))) return 0;
for ($i=0; $i<count($list); $i++) { if ($list[$i] == substr($string, $start, $length)) return 1; } return 0; }
function IsVowel($string, $pos) { return ereg("[AEIOUY]", substr($string, $pos, 1)); }
function SlavoGermanic($string) { return ereg("W|K|CZ|WITZ", $string); }} // end of class MetaPhone
//***********************************************************************
/*=================================================================*\ # Name: double_metaphone( $string ) # Purpose: Get the primary and secondary double metaphone tokens # Return: Array: if secondary == primary, secondary = NULL\*=================================================================*/
/* VERSION
DoubleMetaphone Functional 1.01
DESCRIPTION
This function implements a "sounds like" algorithm developed by Lawrence Philips which he published in the June, 2000 issue of C/C++ Users Journal. Double Metaphone is an improved version of Philips' original Metaphone algorithm.
COPYRIGHT
Slightly adapted from the class by Stephen Woodbridge. Copyright 2001, Stephen Woodbridge <[email protected]> All rights reserved.
http://swoodbridge.com/DoubleMetaPhone/
This PHP translation is based heavily on the C implementation by Maurice Aubrey <[email protected]>, which in turn is based heavily on the C++ implementation by Lawrence Philips and incorporates several bug fixes courtesy of Kevin Atkinson <[email protected]>.
This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
CONTRIBUTIONS
17-May-2002 Geoff Caplan http://www.advantae.com Bug fix: added code to return class object which I forgot to do Created a functional callable version instead of the class version which is faster if you are calling this a lot.
*/
function double_metaphone( $string ){ $primary = ""; $secondary = ""; $current = 0;
$current = 0; $length = strlen($string); $last = $length - 1; $original = $string . " ";
$original = strtoupper($original);
// skip this at beginning of word
if (string_at($original, 0, 2, array('GN', 'KN', 'PN', 'WR', 'PS'))) $current++;
// Initial 'X' is pronounced 'Z' e.g. 'Xavier'
if (substr($original, 0, 1) == 'X') { $primary .= "S"; // 'Z' maps to 'S' $secondary .= "S"; $current++; }
// main loop
while (strlen($primary) < 4 || strlen($secondary < 4)) { if ($current >= $length) break;
switch (substr($original, $current, 1)) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y': if ($current == 0) { // all init vowels now map to 'A' $primary .= 'A'; $secondary .= 'A'; } $current += 1; break;
case 'B': // '-mb', e.g. "dumb", already skipped over ... $primary .= 'P'; $secondary .= 'P';
if (substr($original, $current + 1, 1) == 'B') $current += 2; else $current += 1; break;
case '�': $primary .= 'S'; $secondary .= 'S'; $current += 1; break;
case 'C': // various gremanic if (($current > 1) && !is_vowel($original, $current - 2) && string_at($original, $current - 1, 3, array("ACH")) && ((substr($original, $current + 2, 1) != 'I') && ((substr($original, $current + 2, 1) != 'E') || string_at($original, $current - 2, 6, array("BACHER", "MACHER"))))) {
$primary .= 'K'; $secondary .= 'K'; $current += 2; break; }
// special case 'caesar' if (($current == 0) && string_at($original, $current, 6, array("CAESAR"))) { $primary .= 'S'; $secondary .= 'S'; $current += 2; break; }
// italian 'chianti' if (string_at($original, $current, 4, array("CHIA"))) { $primary .= 'K'; $secondary .= 'K'; $current += 2; break; }
if (string_at($original, $current, 2, array("CH"))) {
// find 'michael' if (($current > 0) && string_at($original, $current, 4, array("CHAE"))) { $primary .= 'K'; $secondary .= 'X'; $current += 2; break; }
// greek roots e.g. 'chemistry', 'chorus' if (($current == 0) && (string_at($original, $current + 1, 5, array("HARAC", "HARIS")) || string_at($original, $current + 1, 3, array("HOR", "HYM", "HIA", "HEM"))) && !string_at($original, 0, 5, array("CHORE"))) { $primary .= 'K'; $secondary .= 'K'; $current += 2; break; }
// germanic, greek, or otherwise 'ch' for 'kh' sound if ((string_at($original, 0, 4, array("VAN ", "VON ")) || string_at($original, 0, 3, array("SCH"))) // 'architect' but not 'arch', orchestra', 'orchid' || string_at($original, $current - 2, 6, array("ORCHES", "ARCHIT", "ORCHID")) || string_at($original, $current + 2, 1, array("T", "S")) || ((string_at($original, $current - 1, 1, array("A","O","U","E")) || ($current == 0)) // e.g. 'wachtler', 'weschsler', but not 'tichner' && string_at($original, $current + 2, 1, array("L","R","N","M","B","H","F","V","W"," ")))) { $primary .= 'K'; $secondary .= 'K'; } else { if ($current > 0) { if (string_at($original, 0, 2, array("MC"))) { // e.g. 'McHugh' $primary .= 'K'; $secondary .= 'K'; } else { $primary .= 'X'; $secondary .= 'K'; } } else { $primary .= 'X'; $secondary .= 'X'; } } $current += 2; break; }
// e.g. 'czerny' if (string_at($original, $current, 2, array("CZ")) && !string_at($original, $current -2, 4, array("WICZ"))) { $primary .= 'S'; $secondary .= 'X'; $current += 2; break; }
// e.g. 'focaccia' if (string_at($original, $current + 1, 3, array("CIA"))) { $primary .= 'X'; $secondary .= 'X'; $current += 3; break; }
// double 'C', but not McClellan' if (string_at($original, $current, 2, array("CC")) && !(($current == 1) && (substr($original, 0, 1) == 'M'))) { // 'bellocchio' but not 'bacchus' if (string_at($original, $current + 2, 1, array("I","E","H")) && !string_at($original, $current + 2, 2, array("HU"))) { // 'accident', 'accede', 'succeed' if ((($current == 1) && (substr($original, $current - 1, 1) == 'A')) || string_at($original, $current - 1, 5, array("UCCEE", "UCCES"))) { $primary .= "KS"; $secondary .= "KS"; // 'bacci', 'bertucci', other italian } else { $primary .= "X"; $secondary .= "X"; } $current += 3; break; } else { // Pierce's rule $primary .= "K"; $secondary .= "K"; $current += 2; break; } }
if (string_at($original, $current, 2, array("CK","CG","CQ"))) { $primary .= "K"; $secondary .= "K"; $current += 2; break; }
if (string_at($original, $current, 2, array("CI","CE","CY"))) { // italian vs. english if (string_at($original, $current, 3, array("CIO","CIE","CIA"))) { $primary .= "S"; $secondary .= "X"; } else { $primary .= "S"; $secondary .= "S"; } $current += 2; break; }
// else $primary .= "K"; $secondary .= "K";
// name sent in 'mac caffrey', 'mac gregor' if (string_at($original, $current + 1, 2, array(" C"," Q"," G"))) { $current += 3; } else { if (string_at($original, $current + 1, 1, array("C","K","Q")) && !string_at($original, $current + 1, 2, array("CE","CI"))) { $current += 2; } else { $current += 1; } } break;
case 'D': if (string_at($original, $current, 2, array("DG"))) { if (string_at($original, $current + 2, 1, array("I","E","Y"))) { // e.g. 'edge' $primary .= "J"; $secondary .= "J"; $current += 3; break; } else { // e.g. 'edgar' $primary .= "TK"; $secondary .= "TK"; $current += 2; break; } }
if (string_at($original, $current, 2, array("DT","DD"))) { $primary .= "T"; $secondary .= "T"; $current += 2; break; }
// else $primary .= "T"; $secondary .= "T"; $current += 1; break;
case 'F': if (substr($original, $current + 1, 1) == 'F') $current += 2; else $current += 1; $primary .= "F"; $secondary .= "F"; break;
case 'G': if (substr($original, $current + 1, 1) == 'H') { if (($current > 0) && !is_vowel($original, $current - 1)) { $primary .= "K"; $secondary .= "K"; $current += 2; break; }
if ($current < 3) { // 'ghislane', 'ghiradelli' if ($current == 0) { if (substr($original, $current + 2, 1) == 'I') { $primary .= "J"; $secondary .= "J"; } else { $primary .= "K"; $secondary .= "K"; } $current += 2; break; } }
// Parker's rule (with some further refinements) - e.g. 'hugh' if ((($current > 1) && string_at($original, $current - 2, 1, array("B","H","D"))) // e.g. 'bough' || (($current > 2) && string_at($original, $current - 3, 1, array("B","H","D"))) // e.g. 'broughton' || (($current > 3) && string_at($original, $current - 4, 1, array("B","H")))) { $current += 2; break; } else { // e.g. 'laugh', 'McLaughlin', 'cough', 'gough', 'rough', 'tough' if (($current > 2) && (substr($original, $current - 1, 1) == 'U') && string_at($original, $current - 3, 1, array("C","G","L","R","T"))) { $primary .= "F"; $secondary .= "F"; } elseif (($current > 0) && substr($original, $current - 1, 1) != 'I') { $primary .= "K"; $secondary .= "K"; } $current += 2; break; } }
if (substr($original, $current + 1, 1) == 'N') { if (($current == 1) && is_vowel($original, 0) && !Slavo_Germanic($original)) { $primary .= "KN"; $secondary .= "N"; } else { // not e.g. 'cagney' if (!string_at($original, $current + 2, 2, array("EY")) && (substr($original, $current + 1) != "Y") && !Slavo_Germanic($original)) { $primary .= "N"; $secondary .= "KN"; } else { $primary .= "KN"; $secondary .= "KN"; } } $current += 2; break; }
// 'tagliaro' if (string_at($original, $current + 1, 2, array("LI")) && !Slavo_Germanic($original)) { $primary .= "KL"; $secondary .= "L"; $current += 2; break; }
// -ges-, -gep-, -gel- at beginning if (($current == 0) && ((substr($original, $current + 1, 1) == 'Y') || string_at($original, $current + 1, 2, array("ES","EP","EB","EL","EY","IB","IL","IN","IE", "EI","ER")))) { $primary .= "K"; $secondary .= "J"; $current += 2; break; }
// -ger-, -gy- if ((string_at($original, $current + 1, 2, array("ER")) || (substr($original, $current + 1, 1) == 'Y')) && !string_at($original, 0, 6, array("DANGER","RANGER","MANGER")) && !string_at($original, $current -1, 1, array("E", "I")) && !string_at($original, $current -1, 3, array("RGY","OGY"))) { $primary .= "K"; $secondary .= "J"; $current += 2; break; }
// italian e.g. 'biaggi' if (string_at($original, $current + 1, 1, array("E","I","Y")) || string_at($original, $current -1, 4, array("AGGI","OGGI"))) { // obvious germanic if ((string_at($original, 0, 4, array("VAN ", "VON ")) || string_at($original, 0, 3, array("SCH"))) || string_at($original, $current + 1, 2, array("ET"))) { $primary .= "K"; $secondary .= "K"; } else { // always soft if french ending if (string_at($original, $current + 1, 4, array("IER "))) { $primary .= "J"; $secondary .= "J"; } else { $primary .= "J"; $secondary .= "K"; } } $current += 2; break; }
if (substr($original, $current +1, 1) == 'G') $current += 2; else $current += 1;
$primary .= 'K'; $secondary .= 'K'; break;
case 'H': // only keep if first & before vowel or btw. 2 vowels if ((($current == 0) || is_vowel($original, $current - 1)) && is_vowel($original, $current + 1)) { $primary .= 'H'; $secondary .= 'H'; $current += 2; } else $current += 1; break;
case 'J': // obvious spanish, 'jose', 'san jacinto' if (string_at($original, $current, 4, array("JOSE")) || string_at($original, 0, 4, array("SAN "))) { if ((($current == 0) && (substr($original, $current + 4, 1) == ' ')) || string_at($original, 0, 4, array("SAN "))) { $primary .= 'H'; $secondary .= 'H'; } else { $primary .= "J"; $secondary .= 'H'; } $current += 1; break; }
if (($current == 0) && !string_at($original, $current, 4, array("JOSE"))) { $primary .= 'J'; // Yankelovich/Jankelowicz $secondary .= 'A'; } else { // spanish pron. of .e.g. 'bajador' if (is_vowel($original, $current - 1) && !Slavo_Germanic($original) && ((substr($original, $current + 1, 1) == 'A') || (substr($original, $current + 1, 1) == 'O'))) { $primary .= "J"; $secondary .= "H"; } else { if ($current == $last) { $primary .= "J"; $secondary .= ""; } else { if (!string_at($original, $current + 1, 1, array("L","T","K","S","N","M","B","Z")) && !string_at($original, $current - 1, 1, array("S","K","L"))) { $primary .= "J"; $secondary .= "J"; } } } }
if (substr($original, $current + 1, 1) == 'J') // it could happen $current += 2; else $current += 1; break;
case 'K': if (substr($original, $current + 1, 1) == 'K') $current += 2; else $current += 1; $primary .= "K"; $secondary .= "K"; break;
case 'L': if (substr($original, $current + 1, 1) == 'L') { // spanish e.g. 'cabrillo', 'gallegos' if ((($current == ($length - 3)) && string_at($original, $current - 1, 4, array("ILLO","ILLA","ALLE"))) || ((string_at($original, $last-1, 2, array("AS","OS")) || string_at($original, $last, 1, array("A","O"))) && string_at($original, $current - 1, 4, array("ALLE")))) { $primary .= "L"; $secondary .= ""; $current += 2; break; } $current += 2; } else $current += 1; $primary .= "L"; $secondary .= "L"; break;
case 'M': if ((string_at($original, $current - 1, 3, array("UMB")) && ((($current + 1) == $last) || string_at($original, $current + 2, 2, array("ER")))) // 'dumb', 'thumb' || (substr($original, $current + 1, 1) == 'M')) { $current += 2; } else { $current += 1; } $primary .= "M"; $secondary .= "M"; break;
case 'N': if (substr($original, $current + 1, 1) == 'N') $current += 2; else $current += 1; $primary .= "N"; $secondary .= "N"; break;
case '�': $current += 1; $primary .= "N"; $secondary .= "N"; break;
case 'P': if (substr($original, $current + 1, 1) == 'H') { $current += 2; $primary .= "F"; $secondary .= "F"; break; }
// also account for "campbell" and "raspberry" if (string_at($original, $current + 1, 1, array("P","B"))) $current += 2; else $current += 1; $primary .= "P"; $secondary .= "P"; break;
case 'Q': if (substr($original, $current + 1, 1) == 'Q') $current += 2; else $current += 1; $primary .= "K"; $secondary .= "K"; break;
case 'R': // french e.g. 'rogier', but exclude 'hochmeier' if (($current == $last) && !Slavo_Germanic($original) && string_at($original, $current - 2, 2, array("IE")) && !string_at($original, $current - 4, 2, array("ME","MA"))) { $primary .= ""; $secondary .= "R"; } else { $primary .= "R"; $secondary .= "R"; } if (substr($original, $current + 1, 1) == 'R') $current += 2; else $current += 1; break;
case 'S': // special cases 'island', 'isle', 'carlisle', 'carlysle' if (string_at($original, $current - 1, 3, array("ISL","YSL"))) { $current += 1; break; }
// special case 'sugar-' if (($current == 0) && string_at($original, $current, 5, array("SUGAR"))) { $primary .= "X"; $secondary .= "S"; $current += 1; break; }
if (string_at($original, $current, 2, array("SH"))) { // germanic if (string_at($original, $current + 1, 4, array("HEIM","HOEK","HOLM","HOLZ"))) { $primary .= "S"; $secondary .= "S"; } else { $primary .= "X"; $secondary .= "X"; } $current += 2; break; }
// italian & armenian if (string_at($original, $current, 3, array("SIO","SIA")) || string_at($original, $current, 4, array("SIAN"))) { if (!Slavo_Germanic($original)) { $primary .= "S"; $secondary .= "X"; } else { $primary .= "S"; $secondary .= "S"; } $current += 3; break; }
// german & anglicisations, e.g. 'smith' match 'schmidt', 'snider' match 'schneider' // also, -sz- in slavic language altho in hungarian it is pronounced 's' if ((($current == 0) && string_at($original, $current + 1, 1, array("M","N","L","W"))) || string_at($original, $current + 1, 1, array("Z"))) { $primary .= "S"; $secondary .= "X"; if (string_at($original, $current + 1, 1, array("Z"))) $current += 2; else $current += 1; break; }
if (string_at($original, $current, 2, array("SC"))) { // Schlesinger's rule if (substr($original, $current + 2, 1) == 'H') // dutch origin, e.g. 'school', 'schooner' if (string_at($original, $current + 3, 2, array("OO","ER","EN","UY","ED","EM"))) { // 'schermerhorn', 'schenker' if (string_at($original, $current + 3, 2, array("ER","EN"))) { $primary .= "X"; $secondary .= "SK"; } else { $primary .= "SK"; $secondary .= "SK"; } $current += 3; break; } else { if (($current == 0) && !is_vowel($original, 3) && (substr($original, $current + 3, 1) != 'W')) { $primary .= "X"; $secondary .= "S"; } else { $primary .= "X"; $secondary .= "X"; } $current += 3; break; }
if (string_at($original, $current + 2, 1, array("I","E","Y"))) { $primary .= "S"; $secondary .= "S"; $current += 3; break; }
// else $primary .= "SK"; $secondary .= "SK"; $current += 3; break; }
// french e.g. 'resnais', 'artois' if (($current == $last) && string_at($original, $current - 2, 2, array("AI","OI"))) { $primary .= ""; $secondary .= "S"; } else { $primary .= "S"; $secondary .= "S"; }
if (string_at($original, $current + 1, 1, array("S","Z"))) $current += 2; else $current += 1; break;
case 'T': if (string_at($original, $current, 4, array("TION"))) { $primary .= "X"; $secondary .= "X"; $current += 3; break; }
if (string_at($original, $current, 3, array("TIA","TCH"))) { $primary .= "X"; $secondary .= "X"; $current += 3; break; }
if (string_at($original, $current, 2, array("TH")) || string_at($original, $current, 3, array("TTH"))) { // special case 'thomas', 'thames' or germanic if (string_at($original, $current + 2, 2, array("OM","AM")) || string_at($original, 0, 4, array("VAN ","VON ")) || string_at($original, 0, 3, array("SCH"))) { $primary .= "T"; $secondary .= "T"; } else { $primary .= "0"; $secondary .= "T"; } $current += 2; break; }
if (string_at($original, $current + 1, 1, array("T","D"))) $current += 2; else $current += 1; $primary .= "T"; $secondary .= "T"; break;
case 'V': if (substr($original, $current + 1, 1) == 'V') $current += 2; else $current += 1; $primary .= "F"; $secondary .= "F"; break;
case 'W': // can also be in middle of word if (string_at($original, $current, 2, array("WR"))) { $primary .= "R"; $secondary .= "R"; $current += 2; break; }
if (($current == 0) && (is_vowel($original, $current + 1) || string_at($original, $current, 2, array("WH")))) { // Wasserman should match Vasserman if (is_vowel($original, $current + 1)) { $primary .= "A"; $secondary .= "F"; } else { // need Uomo to match Womo $primary .= "A"; $secondary .= "A"; } }
// Arnow should match Arnoff if ((($current == $last) && is_vowel($original, $current - 1)) || string_at($original, $current - 1, 5, array("EWSKI","EWSKY","OWSKI","OWSKY")) || string_at($original, 0, 3, array("SCH"))) { $primary .= ""; $secondary .= "F"; $current += 1; break; }
// polish e.g. 'filipowicz' if (string_at($original, $current, 4, array("WICZ","WITZ"))) { $primary .= "TS"; $secondary .= "FX"; $current += 4; break; }
// else skip it $current += 1; break;
case 'X': // french e.g. breaux if (!(($current == $last) && (string_at($original, $current - 3, 3, array("IAU", "EAU")) || string_at($original, $current - 2, 2, array("AU", "OU"))))) { $primary .= "KS"; $secondary .= "KS"; }
if (string_at($original, $current + 1, 1, array("C","X"))) $current += 2; else $current += 1; break;
case 'Z': // chinese pinyin e.g. 'zhao' if (substr($original, $current + 1, 1) == "H") { $primary .= "J"; $secondary .= "J"; $current += 2; break; } elseif (string_at($original, $current + 1, 2, array("ZO", "ZI", "ZA")) || (Slavo_Germanic($original) && (($current > 0) && substr($original, $current - 1, 1) != 'T'))) { $primary .= "S"; $secondary .= "TS"; } else { $primary .= "S"; $secondary .= "S"; }
if (substr($original, $current + 1, 1) == 'Z') $current += 2; else $current += 1; break;
default: $current += 1;
} // end switch
// printf("<br>ORIGINAL: '%s'\n", $original); // printf("<br>current: '%s'\n", $current); // printf("<br> PRIMARY: '%s'\n", $primary); // printf("<br> SECONDARY: '%s'\n", $secondary);
} // end while
$primary = substr($primary, 0, 4); $secondary = substr($secondary, 0, 4);
if( $primary == $secondary ) { $secondary = NULL ; }
$result["primary"] = $primary ; $result["secondary"] = $secondary ;
return $result ;
} // end of function MetaPhone
/*=================================================================*\ # Name: string_at($string, $start, $length, $list) # Purpose: Helper function for double_metaphone( ) # Return: Bool\*=================================================================*/
function string_at($string, $start, $length, $list){ if (($start <0) || ($start >= strlen($string))) return 0;
for ($i=0; $i<count($list); $i++) { if ($list[$i] == substr($string, $start, $length)) return 1; } return 0; }
/*=================================================================*\ # Name: is_vowel($string, $pos) # Purpose: Helper function for double_metaphone( ) # Return: Bool\*=================================================================*/
function is_vowel($string, $pos){ return ereg("[AEIOUY]", substr($string, $pos, 1));}
/*=================================================================*\ # Name: Slavo_Germanic($string, $pos) # Purpose: Helper function for double_metaphone( ) # Return: Bool\*=================================================================*/
function Slavo_Germanic($string){ return ereg("W|K|CZ|WITZ", $string);}
?>
Since I used a DoubleMetaphone function and wordlist that I did notcreate, and come with copyrights of their own, I must include thosecopyrights with my software. You are free to modify/redistribute thissoftware and all its contents as long as you adhere to those copyrights.
- Alan Nouri
=========================================================================
http: swoodbridge.com/DoubleMetaPhone/
VERSION DoubleMetaphone Class 1.01
DESCRIPTION
This class implements a "sounds like" algorithm developed by Lawrence Philips which he published in the June, 2000 issue of C/C++ Users Journal. Double Metaphone is an improved version of Philips' original Metaphone algorithm.
COPYRIGHT
Copyright 2001, Stephen Woodbridge <[email protected]> All rights reserved.
http: swoodbridge.com/DoubleMetaPhone/
This PHP translation is based heavily on the C implementation by Maurice Aubrey <[email protected]>, which in turn is based heavily on the C++ implementation by Lawrence Philips and incorporates several bug fixes courtesy of Kevin Atkinson <[email protected]>.
This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
CONTRIBUTIONS
17-May-2002 Geoff Caplan http: www.advantae.com Bug fix: added code to return class object which I forgot to do Created a functional callable version instead of the class version which is faster if you are calling this a lot.
=========================================================================
http: wordlist.sourceforge.net/
Copyright 2000-2004 by Kevin Atkinson
Permission to use, copy, modify, distribute and sell these word lists, the associated scripts, the output created from the scripts, and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Kevin Atkinson makes no representations about the suitability of this array for any purpose. It is provided "as is" without express or implied warranty.
=========================================================================
Also included is a file SCOWL-LICENSE, which contains the individuallicenses for the word lists that are included with SCOWL. I only usedwordlists that are in the public domain, I think, but since I wrote thisso long ago I'm being safe and including all these copyrights. If forsome reason you want to re-distribute this spell checker without thosecopyrights, feel free to verify that none of the words in the databaseare in those wordlists.
Spell Checking Oriented Word Lists (SCOWL)Revision 6August 10, 2004by Kevin Atkinson
The SCOWL is a collection of word lists split up in various sizes, andother categories, intended to be suitable for use in spell checkers.However, I am sure it will have numerous other uses as well.
The latest version can be found at http://wordlist.sourceforge.net/
The directory final/ contains the actual word lists broken up intovarious sizes and categories. The r/ directory contains Readmes fromthe various sources used to create this package.
The other directories contain the necessary information to recreate theword lists from the raw data. Unless you are interested in improving thewords lists you should not need to worry about what's here. See thesection on recreating the words lists for more information on what'sthere.
Except for the special word lists the files follow the followingnaming convention: <spelling category>-<classification>.<size>Where the spelling category is one of english, american, british, british_z, canadian, variant_0, varaint_1, variant_2Classification is one of abbreviations, contractions, proper-names, upper, wordsAnd size is one of 10, 20, 35 (small), 40, 50 (medium), 55, 60, 70 (large), 80 (huge), 95 (insane)The special word lists follow are in the following format: special-<description>.<size>Where description is one of: roman-numerals, hacker
When combining the words lists the "english" spelling category shouldbe used as well as one of "american", "british", "british_z" (britishwith ize spelling), or "canadian". Great care has been taken so thatthat only one spelling for any particular word is included in the mainlist. When two variants were considered equal I randomly picked onefor inclusion in the main word list. Unfortunately this means that mychoice in how to spell a word may not match your choice. If this isthe case you can try including the "variant_0" spelling category whichincludes most variants which are considered almost equal. The"variant_1" spelling category include variants which are alsogenerally considered acceptable, and "variant_2" contains variantswhich are seldom used.
The "abbreviation" category includes abbreviations and acronyms whichare not also normal words. The "contractions" category should be selfexplanatory. The "upper" category includes upper case words and propernames which are common enough to appear in a typical dictionary. The"proper-names" category included all the additional uppercase words.Final the "words" category contains all the normal English words.
To give you an idea of what the words in the various sizes look likehere is a sample of 25 random words found only in that size:
10: began both buffer cause collection content documenting easiest equally examines expecting first firstly hence inclining irrelevant justified little logs necessarily ought sadly six thing visible
20: chunks commodity contempt contexts cruelty crush dictatorship disgusted dose elementary evolved frog god hordes notion overdraft overlong overlook phoning poster recordings sand skull substituted throughput
35: aliasing blackouts blowout bluntness corroborated derrick dredging elopements entrancing excising fellowship flagpole germination glimpse gondola guidebook madams minimalism minnows partisans petitions shelling swarmed throng welding
40: altercation blender castigation chump coffeehouse determiners doggoning exhibitor finders flophouse gazebo lumbering masochism mopeds poetically pubic refinance reggae scragglier softhearted stubbornness teargassed township underclassman whoosh
50: accumulative adulterant allegorically amorousness astrophysics camphor coif dickey elusiveness enviousness fakers fetishistic flippantly headsets liefs midyears myna pacification persiflage phosphoric pinhole sappy seres unrealistically unworldly
55: becquerel brickie centralist cine conveyancing courgette disarmingly gar�on gobstopper infilling insipidity internationalist kabuki lyrebirds obscurantism rejigged revisionist satsuma slapper sozzled sublieutenants teletext vino wellness wracking
60: absorber acceptableness adventurousness antifascists arrhythmia audiology cartage cruses fontanel forelimbs granter hairlike installers jugglery lappets libbers mandrels micrometeorite mineshaft reconsecrates saccharides smellable spavined sud timbrel
70: atomisms benedict carven coxa cyanite detraining diazonium dogberry dogmatics entresol fatherlessnesses firestone imprecator laterality legitimisms maxwell microfloppies nonteaching pelerine pentane pestiferousness piscator profascist tusche twirp
80: cotransfers embrangled forkednesses giftwrapped globosity hatpegs hepsters hermitess interspecific inurbanities lamiae literaehumaniores literatures masulas misbegun plook prerupt quaalude rosanilin sabbatism scowder subreptive thumbstalls understrata yakows
95: anatropal anientise bakshi brouzes corsie daimiote dhaw dislikened ectoretina fortuitisms guardeen hyperlithuria nonanachronistic overacceleration pamphletic parma phytolith starvedly trophoplasmic ulorrhagia undared undertide unplunderously unworkmanly vasoepididymostomy
And here is a rough count on the number of words in the "english"spelling category for each size:
Size Words Proper Names Running Total
10 5,000 5,000 20 8,700 14,000 35 34,500 200 48,000 40 6,000 500 55,000 50 23,200 17,200 95,000 55 7,500 103,000 60 16,000 12,800 132,000 70 45,100 34,300 211,000 80 137,000 30,400 379,000 95 198,000 51,800 628,000
(The "Words" column does not include the proper name count.)
Size 35 is the recommended small size, 50 the medium and 70 the large.Sizes 70 and below contain words found in most dictionaries while the80 size contains all the strange and unusual words people like to usein word games such as Scrabble (TM). While a lot of the the words inthe 80 size are not used very often, they are all generally consideredvalid words in the English language. The 95 contains just about everyEnglish word in existence and then some. Many of the words at the 95level will probally not be considered valid english words by mostpeople. I don't recommend anyone use levels above 70 for spellchecking as they contain rarely used words which can hide misspellingsof similar more commonly used words. For example the word "ort" canhide a common typo of "or". No one should need to use a size largerthan 80, the 95 size is labeled insane for a reason.
Accents are present on certain words such as caf� in iso8859-1 format.
CHANGES:
From Revision 5 to 6 (August 10, 2004)
Updated to version 4.0 of the 12dicts package.
Included the 3esl, 2of4brif, and 5desk list from the new 12dicts package. The 3esl was included in the 40 size, the 2of4brif in the 55 size and the 5desk in the 70 size.
Removed the Ispell word list as it was a source of too many errors. This eliminated the 65 size.
Removed clause 4 from the Ispell copyright with permission of Geoff Kuenning.
Updated to version 4.1 of VarCon.
Added the "british_z" spelling category which it British using the "ize" spelling.
From Revision 4a to 5 (January 3, 2002)
Added variants that were not really spelling variants (such as forwards) back into the main list.
Fixed a bug which caused variants of words to incorrectly appear in the non-variant lists.
Moved rarly used inflections of a word into higher number lists.
Added other inflections of a words based on the following criteria If the word is in the base form: only include that word. If the word is in a plural form: include the base word and the plural If the word is a verb form (other than plural): include all verb forms If the word is an ad* form: include all ad* forms If the word is in a possessive form: also include the non-possessive
Updated to the latest version of many of the source dictionaries.
Removed the DEC Word List due to the questionable licence and because removing it will not seriously decrese the quality of SCOWL (there are a few less proper names).
From Revision 4 to 4a (April 4, 2001)
Reran the scripts on a never version of AGID (3a) which fixes a bug which caused some common words to be improperly marked as variants.
From Revision 3 to 4 (January 28, 2001)
Split the variant "spelling category" up into 3 different levels.
Added words in the Ispell word list at the 65 level.
Other changes due to using more recent versions of various sources included a more accurete version of AGID thanks to the word of Alan Beale
From Revision 2 to 3 (August 18, 2000)
Renamed special-unix-terms to special-hacker and added a large number of communly used words within the hacker (not cracker) community.
Added a couple more signature words including "newbie".
Minor changes due to changes in the inflection database.
From Revision 1 to 2 (August 5, 2000)
Moved the male and female name lists from the mwords package and the DEC name lists form the 50 level to the 60 level and moved Alan's name list from the 60 level to the 50 level. Also added the top 1000 male, female, and last names from the 1990 Census report to the 50 level. This reduced the number of names in the 50 level from 17,000 to 7,000.
Added a large number of Uppercase words to the 50 level.
Properly accented the possessive form of some words.
Minor other changes due to changes in my raw data files which have not been released yet. Email if you are interested in these files.
COPYRIGHT, SOURCES, and CREDITS:
The collective work is Copyright 2000-2004 by Kevin Atkinson as wellas any of the copyrights mentioned below:
Copyright 2000-2004 by Kevin Atkinson
Permission to use, copy, modify, distribute and sell these word lists, the associated scripts, the output created from the scripts, and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Kevin Atkinson makes no representations about the suitability of this array for any purpose. It is provided "as is" without express or implied warranty.
Alan Beale <[email protected]> also deserves special credit as he has,in addition to providing the 12Dicts package and being a majorcontributor to the ENABLE word list, given me an incredible amount offeedback and created a number of special lists (those found in theSupplement) in order to help improve the overall quality of SCOWL.
The 10 level includes the 1000 most common English words (according tothe Moby (TM) Words II [MWords] package), a subset of the 1000 mostcommon words on the Internet (again, according to Moby Words II), andfrequently class 16 from Brian Kelk's "UK English Wordlistwith Frequency Classification".
The MWords package was explicitly placed in the public domain:
The Moby lexicon project is complete and has been place into the public domain. Use, sell, rework, excerpt and use in any way on any platform.
Placing this material on internal or public servers is also encouraged. The compiler is not aware of any export restrictions so freely distribute world-wide.
You can verify the public domain status by contacting
Grady Ward 3449 Martha Ct. Arcata, CA 95521-4884
The "UK English Wordlist With Frequency Classification" is also in thePublic Domain:
Date: Sat, 08 Jul 2000 20:27:21 +0100 From: Brian Kelk <[email protected]>
> I was wondering what the copyright status of your "UK English > Wordlist With Frequency Classification" word list as it seems to > be lacking any copyright notice.
There were many many sources in total, but any text marked "copyright" was avoided. Locally-written documentation was one source. An earlier version of the list resided in a filespace called PUBLIC on the University mainframe, because it was considered public domain.
Date: Tue, 11 Jul 2000 19:31:34 +0100
> So are you saying your word list is also in the public domain?
That is the intention.
The 20 level includes frequency classes 7-15 from Brian's word list.
The 35 level includes frequency classes 2-6 and words appearing in atleast 11 of 12 dictionaries as indicated in the 12Dicts package. Allwords from the 12Dicts package have had likely inflections added viamy inflection database.
The 12Dicts package and Supplement is in the Public Domain.
The WordNet database, which was used in the creation of theInflections database, is under the following copyright:
This software and database is being provided to you, the LICENSEE, by Princeton University under the following license. By obtaining, using and/or copying this software and database, you agree that you have read, understood, and will comply with these terms and conditions.:
Permission to use, copy, modify and distribute this software and database and its documentation for any purpose and without fee or royalty is hereby granted, provided that you agree to comply with the following copyright notice and statements, including the disclaimer, and that the same appear on ALL copies of the software, database and documentation, including modifications that you make for internal use or for distribution.
WordNet 1.6 Copyright 1997 by Princeton University. All rights reserved.
THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT- ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
The name of Princeton University or Princeton may not be used in advertising or publicity pertaining to distribution of the software and/or database. Title to copyright in this software, database and any associated documentation shall at all times remain with Princeton University and LICENSEE agrees to preserve same.
The 40 level includes words from Alan's 3esl list found in version 4.0of his 12dicts package. Like his other stuff the 3esl list is also in thepublic domain.
The 50 level includes Brian's frequency class 1, words words appearingin at least 5 of 12 of the dictionaries as indicated in the 12Dictspackage, and uppercase words in at least 4 of the previous 12dictionaries. A decent number of proper names is also included: Thetop 1000 male, female, and Last names from the 1990 Census report; alist of names sent to me by Alan Beale; and a few names that I addedmyself. Finally a small list of abbreviations not commonly found inother word lists is included.
The name files form the Census report is a government document which Idon't think can be copyrighted.
The file special-jargon.50 uses common.lst and word.lst from the"Unofficial Jargon File Word Lists" which is derived from "The JargonFile". All of which is in the Public Domain. This file also containa few extra UNIX terms which are found in the file "unix-terms" in thespecial/ directory.
The 55 level includes words from Alan's 2of4brif list found in version4.0 of his 12dicts package. Like his other stuff the 2of4brif is alsoin the public domain.
The 60 level includes Brian's frequency class 0 and all wordsappearing in at least 2 of the 12 dictionaries as indicated by the12Dicts package. A large number of names are also included: The 4,946female names and the 3,897 male names from the MWords package.
The 70 level includes the 74,550 common dictionary words and the21,986 names list from the MWords package The common dictionary words,like those from the 12Dicts package, have had all likely inflectionsadded. The 70 level also included the 5desk list from version 4.0 ofthe 12Dics package which is the public domain
The 80 level includes the ENABLE word list, all the lists in theENABLE supplement package (except for ABLE), the "UK Advanced CrypticsDictionary" (UKACD), the list of signature words in from YAWL package,and the 10,196 places list from the MWords package.
The ENABLE package, mainted by M\Cooper <[email protected]>,is in the Public Domain:
The ENABLE master word list, WORD.LST, is herewith formally released into the Public Domain. Anyone is free to use it or distribute it in any manner they see fit. No fee or registration is required for its use nor are "contributions" solicited (if you feel you absolutely must contribute something for your own peace of mind, the authors of the ENABLE list ask that you make a donation on their behalf to your favorite charity). This word list is our gift to the Scrabble community, as an alternate to "official" word lists. Game designers may feel free to incorporate the WORD.LST into their games. Please mention the source and credit us as originators of the list. Note that if you, as a game designer, use the WORD.LST in your product, you may still copyright and protect your product, but you may *not* legally copyright or in any way restrict redistribution of the WORD.LST portion of your product. This *may* under law restrict your rights to restrict your users' rights, but that is only fair.
UKACD, by J Ross Beresford <[email protected]>, is under thefollowing copyright:
Copyright (c) J Ross Beresford 1993-1999. All Rights Reserved.
The following restriction is placed on the use of this publication: if The UK Advanced Cryptics Dictionary is used in a software package or redistributed in any form, the copyright notice must be prominently displayed and the text of this document must be included verbatim.
There are no other restrictions: I would like to see the list distributed as widely as possible.
The 95 level includes the 354,984 single words and 256,772 compoundwords from the MWords package, ABLE.LST from the ENABLE Supplement,and some additional words found in my part-of-speech database thatwere not found anywhere else.
Accent information was taken from UKACD.
My VARCON package was used to create the American, British, andCanadian word list.
Since the original word lists used used in the VARCON package camefrom the Ispell distribution they are under the Ispell copyright:
Copyright 1993, Geoff Kuenning, Granada Hills, CA All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All modifications to the source code must be clearly marked as such. Binary redistributions based on modified source code must be clearly marked as modified versions in the documentation and/or other materials provided with the distribution. (clause 4 removed with permission from Geoff Kuenning) 5. The name of Geoff Kuenning may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The variant word lists were created from a list of variants found inthe 12dicts supplement package as well as a list of variants I createdmyself.
The Readmes for the various packages used can be found in theappropriate directory under the r/ directory.
FUTURE PLANS:
There is a very nice frequency analyse of the BNC corpus done byAdam Kilgarriff. Unlike Brain's word lists the BNC lists include partof speech information. I plan on somehow using these lists as AdamKilgarriff has given me the OK to use it in SCOWL. These lists willgreatly reduce the problem of inflected forms of a word appearing atdifferent levels due to the part-of-speech information.
I also plan on perhaps putting the data in a database and use SQLqueries to create the wordlists instead of tons of "sort"s, "comm"s,and Perl scripts.
RECREATING THE WORD LISTS:
In order to recreate the word lists you need a modern version of Perl,bash, the traditional set of shell utilities, a system that supportssymbolic links, and quite possibly GNU Make. Once you have downloadedall the necessary raw data in the r/ directory you should be able totype "rm final/* && make all" and the word lists in the final/directory should be recreated. If you have any problems fell free tocontact me; however, unless you are interested in improving thescripts used, I will likely ignore you as there should be little needfor anyone not interested in improving the word list to do so.
The src/ directory contains the numerous scripts used in the creationof the final product.
The r/ directory contains the raw data used tocreate the final product. In order for the scripts to work variousword lists and databases need to be created and put into thisdirectory. See the README file in the r/ directory for moreinformation.
The l/ directory contains symbolic links used by the actual scripts.
Finally, the working/ directory is where all the intermittent files gothat are not specific to one source.
Download
You can download and modify the code as you wish as long as you abide by the license requirements.
IMPORTANT: Please read the SCOWL LICENSE before using the word collection.