/** * Measures the Damerau-Levenshtein distance between frequencies of letters * in input string against supported languages. * * @return string the most resembling language */ protected function gageDamerauLevenshtein() { if (!\key_exists('damerau', $this->measures['suggestions'])) { $damerau = array(); foreach (\array_keys(self::$letters) as $lang) { $freqs = $this->gageFrequencies(); $this->measures[$lang]['damerau'] = \extension_loaded('damerau') && function_exists('damerau_levenshtein') ? \damerau_levenshtein($freqs, self::getLettersAsString($lang, $freqs)) : $this->damerauLevenshteinUtf8($freqs, self::getLettersAsString($lang, $freqs)); $damerau[$lang] = $this->measures[$lang]['damerau']; } $this->measures['suggestions']['damerau'] = $this->getTopLangConfidence($damerau, false); } return $this->measures['suggestions']['damerau']['language']; }
$view[MIN_EDIT_TIMESTAMP] = $min_edit_timestamp; $view[MAX_EDIT_TIMESTAMP] = $max_edit_timestamp; array_push($view_array, $view); } //echo("array of view info arrays:"); //print_r($view_array); //If we have a target name, add case-sensitive and non-case-sensitive distances from it. //For assignment, we have to use the original node array in the array. //Assigning it to another variable makes a copy. if ($sort_by_name_similarity) { for ($view_index = 0; $view_index < count($view_array); $view_index++) { $view = $view_array[$view_index]; $comparisson_name = $view[NAME]; $comparisson_name_lc = strtolower($comparisson_name); $view_array[$view_index][DISTANCE_BY_NAME] = damerau_levenshtein($comparisson_name, $target_name); $view_array[$view_index][DISTANCE_BY_NAME_CASE_INSENSITIVE] = damerau_levenshtein($comparisson_name_lc, $target_name_lc); } //end of loop through paths } //end of if we have a target name //echo("array of view info arrays with distances:"); //print_r($view_array); function compare_closeness($view1, $view2) { $output = 0; //Try case-insensitive name similarity. if (!$output && isset($view1[DISTANCE_BY_NAME_CASE_INSENSITIVE])) { $output = $view1[DISTANCE_BY_NAME_CASE_INSENSITIVE] - $view2[DISTANCE_BY_NAME_CASE_INSENSITIVE]; //Then try case-sensitive name similarity. if (!$output) { $output = $view1[DISTANCE_BY_NAME] - $view2[DISTANCE_BY_NAME];
<?php require_once '/var/www/config.php'; sro('/Includes/mysql.php'); sro('/Includes/session.php'); sro('/Includes/functions.php'); sro('/PHP5/lib/PHPLang/common.php'); sro('/PHP5/lib/PHPLang/display.php'); sro('/PHP5/lib/PHPLang/string.php'); sro('/PHP5/lib/PHPLang/misc.php'); global $OP_APOS; global $DEBUG_STRING_PHP; echo "<meta charset='utf-8'>"; $START = microtime(true); var_dump(extension_loaded('damerau') ? damerau_levenshtein("aple", "apple") : "DAMERAU-LEVENSHTEIN NOT LOADED"); echo "<hr>"; $stime = microtime(true); /* var_dump(strncmp("hhh","hh",2)); var_dump(strncmp("hhh","aa",2)); /**/ /*var_dump(compare_syntax("test", "test", ["unescaped"=>true]));echo "<hr>"; var_dump(compare_syntax("test1|test2", "test1", ["unescaped"=>true]));echo "<hr>"; var_dump(compare_syntax("test1|test2", "test2", ["unescaped"=>true]));echo "<hr>";*/ var_dump(compare_syntax("(this|that [system]) machina", "this machina", ["unescaped" => true])); var_dump(compare_syntax("(this|that [system]) machina", "that machina", ["unescaped" => true])); var_dump(compare_syntax("(this|that [system]) machina", "that system machina", ["unescaped" => true])); echo "took " . (microtime(true) - $stime) . " seconds"; echo "<hr>"; $stime = microtime(true); var_dump(compare_syntax("{this} {that}", "this that", ["unescaped" => true]));