当前位置: 首页>>代码示例>>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;未经允许,请勿转载。