當前位置: 首頁>>代碼示例>>PHP>>正文


PHP similar_text函數代碼示例

本文整理匯總了PHP中similar_text函數的典型用法代碼示例。如果您正苦於以下問題:PHP similar_text函數的具體用法?PHP similar_text怎麽用?PHP similar_text使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了similar_text函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: OneQuery

 function OneQuery($query_key, $text, $limit = 1, $properties = null)
 {
     $url = 'http://tnrs.iplantc.org/tnrsm-svc/matchNames?retrieve=all&names=' . rawurlencode($text);
     $limit = 3;
     if (0) {
         file_put_contents('tmp/r.txt', "URL = {$url}\n", FILE_APPEND);
     }
     $json = get($url);
     if (0) {
         file_put_contents('tmp/r.txt', $json . "\n", FILE_APPEND);
     }
     $obj = json_decode($json);
     if (0) {
         file_put_contents('tmp/r.txt', print_r($obj, true), FILE_APPEND);
     }
     $n = min($limit, count($obj->items));
     for ($i = 0; $i < $n; $i++) {
         $hit = new stdclass();
         $hit->match = count($obj->items) == 1;
         $hit->name = $obj->items[$i]->acceptedName;
         similar_text($text, $hit->name, $hit->score);
         $hit->id = '';
         $this->StoreHit($query_key, $hit);
     }
 }
開發者ID:rdmpage,項目名稱:phyloinformatics,代碼行數:25,代碼來源:reconciliation_iplant.php

示例2: widget_lmee_by_talk

 function widget_lmee_by_talk($args)
 {
     extract($args);
     echo $before_widget;
     $lmee_popular_options = get_option('widget_lmee_popular');
     $title = '灌水區-這裏很熱鬧';
     //設置默認的標題
     echo $before_title . $title . $after_title;
     $page_ID = 789;
     //用來作為公告欄的頁麵或者文章id
     $num = 5;
     //顯示公告的條數
     echo '<ul class="by_talk">';
     $announcement = '';
     $comments = get_comments("number={$num}&post_id={$page_ID}");
     if (!empty($comments)) {
         $flg = 1;
         foreach ($comments as $comment) {
             if ($flg == 1) {
                 $li_title = $comment->comment_content;
                 if (similar_text($li_title, "<") > 0) {
                     //echo "is";
                     $start = stripos($li_title, "<");
                     //從前往後查找
                     $__li_title = strrev($li_title);
                     //反轉字符串
                     $length = strlen($li_title) - $start - stripos($__li_title, ">");
                     $_li_title = substr_replace($li_title, "含引用", $start, $length);
                     $_li_html = substr_replace($li_title, "", $start, $length);
                     $announcement .= '<li class="by-talk-first"><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $_li_title . '" rel="nofollow" target="_blank">' . $_li_html . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
                 } else {
                     //echo "un";
                     $announcement .= '<li class="by-talk-first"><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $li_title . '" rel="nofollow" target="_blank">' . convert_smilies($comment->comment_content) . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
                 }
                 $flg++;
             } else {
                 $li_title = $comment->comment_content;
                 if (similar_text($li_title, "<") > 0) {
                     //echo "is";
                     $start = stripos($li_title, "<");
                     //從前往後查找
                     $__li_title = strrev($li_title);
                     //反轉字符串
                     $length = strlen($li_title) - $start - stripos($__li_title, ">");
                     $_li_title = substr_replace($li_title, "含引用", $start, $length);
                     $_li_html = substr_replace($li_title, "", $start, $length);
                     $announcement .= '<li><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $_li_title . '" rel="nofollow" target="_blank">' . $_li_html . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
                 } else {
                     //echo "un";
                     $announcement .= '<li><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $li_title . '" rel="nofollow" target="_blank">' . convert_smilies($comment->comment_content) . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
                 }
             }
         }
     }
     //if ( empty($announcement) ) $announcement = '<li>還沒有人灌水奧!</li>';
     echo $announcement;
     echo '</ul>';
     echo "<p style='text-align:right;'>[<a href='" . get_page_link($page_ID) . "#respond' rel='nofollow'>說兩句</a>]</p>";
     echo $after_widget;
 }
開發者ID:uglmee,項目名稱:kikiku.com,代碼行數:60,代碼來源:By-talk-for-lmee.php

示例3: m_relatedURL

 public function m_relatedURL($title)
 {
     global $system, $settings;
     $title = mysql_real_escape_string($title);
     $system->dbm->db->select("`id`, `url`, `title`", "`{$this->table}`", "`domain` = '{$settings['domain']}' AND `title` <> '{$title}'");
     while ($row = $system->dbm->db->fetch_array()) {
         similar_text($title, $row[title], $percent);
         $percent = intval($percent);
         //			print "$title $percent% -> Id: $row[id] - Title: $row[title] - Url: $row[url]<br>";
         //			if($percent > 60){
         $sim[$percent][id] = $row[id];
         $row[url] = str_replace("op=", '', $row[url]);
         $row[url] = str_replace("&mode=", '/', $row[url]);
         $row[url] = str_replace("&filter=", '/', $row[url]);
         $row[url] = str_replace("&p=", '/', $row[url]);
         $row[url] = str_replace("&f=", '/', $row[url]);
         $sim[$percent][url] = $row[url];
         $sim[$percent][title] = $row[title];
         //			}
     }
     //		print_r($sim);
     if (count($sim) > 0) {
         krsort($sim);
         $system->xorg->smarty->assign("relatedContent", array_slice($sim, 0, 5, true));
         return $system->xorg->smarty->fetch($settings[moduleAddress] . "/relatedContent/view/tpl/object/relatedContent" . $settings[ext4]);
     }
 }
開發者ID:rezarahimi4861,項目名稱:icmf,代碼行數:27,代碼來源:relatedContent.php

示例4: getKeys

 public function getKeys($imgPath)
 {
     if (!($res = @imagecreatefromjpeg($imgPath))) {
         return '';
     }
     //提取文字部分圖片
     $wordData = array();
     for ($i = 0; $i < $this->imgInfo['wordNum']; $i++) {
         $wordData[$i] = '';
         $x = $i * ($this->imgInfo['wordWidth'] + $this->imgInfo['wordSpace']) + $this->imgInfo['offsetWidth'];
         $y = $this->imgInfo['offsetHeight'];
         for ($h = $y; $h < $this->imgInfo['offsetHeight'] + $this->imgInfo['wordHeight']; $h++) {
             for ($w = $x; $w < $x + $this->imgInfo['wordWidth']; $w++) {
                 $rgb = imagecolorsforindex($res, imagecolorat($res, $w, $h));
                 $wordData[$i] .= $rgb['red'] < 127 || $rgb['green'] < 127 || $rgb['blue'] < 127 ? '1' : '0';
             }
         }
     }
     $keys = '';
     //相似度比較
     foreach ($wordData as $wordStr) {
         $maxPercent = 0.0;
         foreach ($this->keyData as $k => $v) {
             $percent = 0.0;
             similar_text($v, $wordStr, $percent);
             if ($percent > $maxPercent) {
                 $maxPercent = $percent;
                 $key = $k;
             }
         }
         $keys .= $key;
     }
     return $keys;
 }
開發者ID:qious,項目名稱:Hnust,代碼行數:34,代碼來源:VCode.php

示例5: OneQuery

 function OneQuery($query_key, $text, $limit = 5, $properties = null)
 {
     $param = array('partialName' => $text, 'ontologyName' => 'ENVO', 'reverseKeyOrder' => false);
     //print_r($param);
     $envo_result = $this->client->call('getTermsByName', $param);
     //print_r($envo_result);
     //$envo_result = $this->client->call('getOntologyNames');
     //print_r($this->client);
     // Check for a fault
     if ($this->client->fault) {
         // handle this
     } else {
         // Check for errors
         $err = $this->client->getError();
         if ($err) {
         } else {
             //print_r($envo_result);
             // Extract names
             $n = count($envo_result['getTermsByNameReturn']['item']);
             //echo "n=$n\n";
             $n = min($n, $limit);
             for ($i = 0; $i < $n; $i++) {
                 $hit = new stdclass();
                 //echo $envo_result['getTermsByNameReturn']['item'][$i]['key'] . "\n";
                 similar_text($text, $envo_result['getTermsByNameReturn']['item'][$i]['value'], $hit->score);
                 $hit->match = $hit->score == 100;
                 $hit->id = $envo_result['getTermsByNameReturn']['item'][$i]['key'];
                 $hit->name = $envo_result['getTermsByNameReturn']['item'][$i]['value'];
                 $this->StoreHit($query_key, $hit);
             }
         }
     }
 }
開發者ID:rdmpage,項目名稱:phyloinformatics,代碼行數:33,代碼來源:reconciliation_envo.php

示例6: similarWord

 /**
  *
  * @param string $word
  * @param array $words
  * @return array
  */
 public static function similarWord($word, array $words)
 {
     $similarity = config('pages.similar.similarity');
     $metaSimilarity = 0;
     $minLevenshtein = 1000;
     $metaMinLevenshtein = 1000;
     $result = [];
     $metaResult = [];
     foreach ($words as $n) {
         $minLevenshtein = min($minLevenshtein, levenshtein($n, $word));
     }
     foreach ($words as $n => $k) {
         if (levenshtein($k, $word) <= $minLevenshtein) {
             if (similar_text($k, $word) >= $similarity) {
                 $result[$n] = $k;
             }
         }
     }
     foreach ($result as $n) {
         $metaMinLevenshtein = min($metaMinLevenshtein, levenshtein(metaphone($n), metaphone($word)));
     }
     foreach ($result as $n) {
         if (levenshtein($n, $word) == $metaMinLevenshtein) {
             $metaSimilarity = max($metaSimilarity, similar_text(metaphone($n), metaphone($word)));
         }
     }
     foreach ($result as $n => $k) {
         if (levenshtein(metaphone($k), metaphone($word)) <= $metaMinLevenshtein) {
             if (similar_text(metaphone($k), metaphone($word)) >= $metaSimilarity) {
                 $metaResult[$n] = $k;
             }
         }
     }
     return $metaResult;
 }
開發者ID:BlueCatTAT,項目名稱:kodicms-laravel,代碼行數:41,代碼來源:Text.php

示例7: getTestsToRun

 private function getTestsToRun()
 {
     $root = $this->getProjectRoot();
     $test_dir = $root . "/tests/";
     $tests = array();
     foreach (glob($test_dir . "*.t") as $test) {
         $relname = substr($test, strlen($test_dir));
         $tests[$relname] = $test;
     }
     if (!$this->getRunAllTests()) {
         /* run tests that sound similar to the modified paths */
         printf("Finding tests based on name similarity\n");
         printf("Use `arc unit --everything` to run them all\n");
         $paths = array();
         foreach ($this->getPaths() as $path) {
             $paths[] = $this->stripName($path);
         }
         foreach ($tests as $relname => $test) {
             $keep = false;
             $strip = $this->stripName($relname);
             foreach ($paths as $path) {
                 $pct = 0;
                 similar_text($path, $strip, $pct);
                 if ($pct > 55) {
                     $keep = true;
                     break;
                 }
             }
             if (!$keep) {
                 unset($tests[$relname]);
             }
         }
     }
     return $tests;
 }
開發者ID:colindj,項目名稱:libphenom,代碼行數:35,代碼來源:PhenomUnitEngine.php

示例8: compare

 public static function compare($first, $second)
 {
     $first = static::sanitize($first);
     $second = static::sanitize($second);
     similar_text($first, $second, $result);
     return (double) number_format($result, 2);
 }
開發者ID:jgrossi,項目名稱:masters-met,代碼行數:7,代碼來源:Title.php

示例9: OneQuery

 function OneQuery($query_key, $text, $limit = 1, $properties = null)
 {
     $url = '';
     if ($properties) {
         file_put_contents(dirname(__FILE__) . '/tmp/prop.txt', json_encode($properties), FILE_APPEND);
         if ($properties[0]->pid == '/type/object/id') {
             // find datasets for this organisation
             $url .= 'http://api.gbif.org/v1/organization/' . $properties[0]->v . '/publishedDataset';
         } else {
             // crude search
             $url = 'http://api.gbif.org/v1/dataset?q=' . urlencode($text);
         }
     } else {
         // crude search
         $url = 'http://api.gbif.org/v1/dataset?q=' . urlencode($text);
     }
     file_put_contents(dirname(__FILE__) . '/tmp/url.txt', $url . "\n", FILE_APPEND);
     $json = get($url);
     if ($json != '') {
         $obj = json_decode($json);
         foreach ($obj->results as $result) {
             $hit = new stdclass();
             $hit->id = $result->key;
             $hit->name = $result->title;
             similar_text($text, $hit->name, $hit->score);
             $hit->match = $hit->score == 1;
             $this->StoreHit($query_key, $hit);
         }
     }
 }
開發者ID:rdmpage,項目名稱:phyloinformatics,代碼行數:30,代碼來源:reconciliation_gbif_dataset.php

示例10: show_similar_codes

function show_similar_codes($reference)
{
    $reference = strtolower($reference);
    $result = do_query("\n            SELECT deposref, uid FROM users WHERE uid > 1\n        UNION\n            SELECT deposref, uid FROM old_deposrefs\n        ORDER BY deposref\n    ");
    while ($row = mysql_fetch_assoc($result)) {
        $deposref = strtolower($row['deposref']);
        $scores[$deposref] = round((9 + similar_text($reference, $deposref) - levenshtein($reference, $deposref)) * 100 / 18);
        $uid[$deposref] = $row['uid'];
    }
    arsort($scores);
    $first = true;
    foreach ($scores as $deposref => $score) {
        if ($score >= 50) {
            if ($first) {
                $first = false;
                echo "<p>" . _("Did you mean one of these?  Higher percentage = closer match.") . "</p>\n";
                echo "<p>" . _("Click an entry to copy it to the form below, then click 'Deposit' again.") . "</p>\n";
                echo "<table class='display_data'>\n";
                echo "<tr><th>Reference</th><th>Match</th><th>UID</th></tr>\n";
            }
            $formatted = format_deposref($deposref);
            echo "<tr", " class=\"me\"", " onmouseover=\"style.backgroundColor='#8ae3bf';\"", " onmouseout=\"style.backgroundColor='#7ad3af';\"", " onclick=\"ObjById('reference').value = '{$deposref}';\">";
            echo "<td>{$formatted}</td><td>{$score}%</td><td>{$uid[$deposref]}</td></tr>\n";
        }
    }
    if (!$first) {
        echo "</table>\n";
    }
}
開發者ID:martinkirov,項目名稱:intersango,代碼行數:29,代碼來源:add_cash.php

示例11: compare

 function compare($debug = false)
 {
     $first = $this->str1;
     $second = $this->str2;
     $this->levenshtein = levenshtein($first, $second);
     $this->similarity['value'] = $sim = similar_text($first, $second, $perc);
     $this->similarity['percentage'] = $perc;
     if ($debug) {
         echo "{$first} | {$second}<br>";
         echo "leven: " . $this->levenshtein;
         echo '<br>similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $soundex1 = soundex($first);
     $soundex2 = soundex($second);
     $this->soundex['levenshtein'] = levenshtein($soundex1, $soundex2);
     $this->soundex['similarity'] = $sim = similar_text($soundex1, $soundex2, $perc);
     $this->soundex['percentage'] = $perc;
     if ($debug) {
         echo "Soundex: " . $soundex1 . ", " . $soundex2 . "<BR>";
         echo 'levenshtein: ' . $this->soundex['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $m1 = metaphone($first);
     $m2 = metaphone($second);
     $this->metaphone['levenshtein'] = levenshtein($m1, $m2);
     $this->metaphone['similarity'] = $sim = similar_text($m1, $m2, $perc);
     $this->metaphone['percentage'] = $perc;
     if ($debug) {
         echo "metaphone: " . $m1 . ", " . $m2 . "<br>";
         echo 'levenshtein: ' . $this->metaphone['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br>';
         echo '<br>-------------------<br>';
     }
 }
開發者ID:superego546,項目名稱:SMSGyan,代碼行數:34,代碼來源:class.CompareString.php

示例12: stringSimilarity

 public static function stringSimilarity($s1, $s2)
 {
     $s1 = preg_replace("/[^A-Za-z0-9]/", '', strtolower($s1));
     $s2 = preg_replace("/[^A-Za-z0-9]/", '', strtolower($s2));
     similar_text($s1, $s2, $percent);
     return floatval($percent);
 }
開發者ID:ardhimaarik,項目名稱:dapus-generator,代碼行數:7,代碼來源:StringHelper.php

示例13: solve

 public function solve(Request $request, \Exception $exception)
 {
     if (!$exception instanceof ServiceNotFoundException) {
         return null;
     }
     try {
         $finder = new ObjectFinder();
         $container = $finder->find('Symfony\\Component\\DependencyInjection\\Container');
         $ids = $container->getServiceIds();
         $searchedId = $exception->getId();
         $similarity = array();
         foreach ($ids as $id) {
             $percentage = 0.0;
             similar_text($id, $searchedId, $percentage);
             if ($percentage >= 90.0) {
                 $similarity[$id] = $percentage;
             }
         }
         arsort($similarity);
         if (!$similarity) {
             return null;
         }
         return new SimpleBlockSolution('Do you have a typo in the service name?', 'Solution:service_name_typo.html.php', array('serviceIds' => $similarity));
     } catch (\Exception $ex) {
         return null;
     }
 }
開發者ID:richardmiller,項目名稱:DebuggingBundle,代碼行數:27,代碼來源:ServiceNotFoundProblemSolver.php

示例14: getLocation

 function getLocation($place)
 {
     global $ANALYTICS;
     $query = "select LocId from Location where Search LIKE '%" . $place . "%'";
     $result = mysql_fetch_array(mysql_query($query, $ANALYTICS));
     $loc_id = $result['LocId'];
     if (!isset($loc_id)) {
         $query1 = "select LocId, Search from Location";
         $query_return = mysql_query($query1, $ANALYTICS);
         $max = 0.0;
         $place = strtoupper($place);
         $location = '';
         $loc_id = 0;
         while ($result1 = mysql_fetch_array($query_return)) {
             $match = 0.0;
             $loc = strtoupper($result1['Search']);
             similar_text($place, $loc, $match);
             if ($match > 80 && $match > $max) {
                 $max = $match;
                 $location = $result1['Search'];
                 $loc_id = $result1['LocId'];
             }
         }
     }
     return $loc_id;
 }
開發者ID:KetanDesh,項目名稱:Bikevaluation,代碼行數:26,代碼來源:location_handler.php

示例15: OneQuery

 function OneQuery($query_key, $text, $limit = 1, $properties = null)
 {
     $url = 'http://gni.globalnames.org/name_strings.json?search_term=' . rawurlencode($text);
     $limit = 5;
     if (0) {
         file_put_contents('tmp/r.txt', "URL = {$url}\n", FILE_APPEND);
     }
     $json = get($url);
     if (0) {
         file_put_contents('tmp/r.txt', $json . "\n", FILE_APPEND);
     }
     $obj = json_decode($json);
     if (0) {
         file_put_contents('tmp/r.txt', print_r($obj, true), FILE_APPEND);
     }
     $n = min($limit, $obj->name_strings_total);
     for ($i = 0; $i < $n; $i++) {
         $hit = new stdclass();
         $hit->match = $obj->name_strings_total == 1;
         $hit->name = $obj->name_strings[$i]->name;
         $hit->id = $obj->name_strings[$i]->id;
         similar_text($text, $hit->name, $hit->score);
         $this->StoreHit($query_key, $hit);
     }
 }
開發者ID:rdmpage,項目名稱:phyloinformatics,代碼行數:25,代碼來源:reconciliation_globalnames.php


注:本文中的similar_text函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。