本文整理汇总了PHP中metaphone函数的典型用法代码示例。如果您正苦于以下问题:PHP metaphone函数的具体用法?PHP metaphone怎么用?PHP metaphone使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了metaphone函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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>';
}
}
示例2: 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;
}
示例3: search_items
function search_items()
{
$search_string = $this->input->post('keyword');
$search_string = preg_replace('/[^a-zA-Z0-9_ %\\[\\]\\.\\(\\)%&-]/s', '', $search_string);
$words = explode(" ", $search_string);
$data = $this->browse_gallery_model->get_all_search_strings();
$row = 0;
$row_array = array();
$ad_array = array();
foreach ($data as $text) {
$text_word = explode("~", $text['Title_Text']);
$ad_id = $text['ad_id'];
$count = 0;
foreach ($text_word as $single) {
foreach ($words as $keyword) {
if (soundex(strtoupper($keyword)) == soundex(strtoupper($single)) || metaphone(strtoupper($keyword)) == metaphone(strtoupper($single))) {
$count = $count + 1;
}
}
}
if (intval($count) > 0) {
array_push($row_array, $ad_id);
}
}
if (!empty($row_array)) {
$data['ads'] = $this->browse_gallery_model->get_gallery_ads_by_adid($row_array);
$data['top'] = $this->browse_gallery_model->get_top_categories();
$this->load->view('search_items_view', $data);
} else {
$data['ads'] = NULL;
$data['top'] = $this->browse_gallery_model->get_top_categories();
$this->load->view('search_items_view', $data);
}
}
示例4: testStringPreparation
public function testStringPreparation()
{
$string = new String();
$testString = "This is my-book title. BY Jesse.";
$actual = $string->prepare($testString);
$expected = [metaphone('this'), metaphone('book'), metaphone('title'), metaphone('jesse')];
$this->assertEquals($actual, $expected);
}
示例5: compareMetaphone
function compareMetaphone($v1, $v2)
{
$v1 = metaphone($v1);
$v2 = metaphone($v2);
similar_text($v1, $v2, $p);
// return similarity percentage
return $p;
}
示例6: strmp
function strmp($str)
{
$arr = explode(' ', $str);
foreach ($arr as $ind => $word) {
$word = trim($word);
$arr[$ind] = metaphone($word);
}
$str = implode(' ', $arr);
return $str;
}
示例7: testMultipleFind
public function testMultipleFind()
{
$redis = m::mock('Illuminate\\Redis\\Database');
$redis->shouldReceive('sinter')->times(2)->andReturn([1], []);
$string = m::mock('Reach\\String');
$string->shouldReceive('prepare')->times(2)->andReturn([metaphone('the'), metaphone('story')], [metaphone('the'), metaphone('story')]);
$string->shouldReceive('stripPunctuation')->times(2)->andReturn('books', 'authors');
$reach = new Reach($redis, $string);
$expected = ['books' => [1], 'authors' => []];
$this->assertEquals($reach->findIn(['books', 'authors'], 'the story'), $expected);
}
示例8: similar_phase
function similar_phase($a, $b)
{
$a = metaphone($a);
$b = metaphone($b);
$na = strlen($a);
$nb = strlen($b);
$n = $nb;
if ($na > $nb) {
$n = $na;
}
return levenshtein($a, $b) * 100.0 / $n;
}
示例9: prepare
/**
* Prepare a string to have it's pieces inserted into the search index
*
* @param string $term
* @return array
*/
public function prepare($string)
{
$string = strtolower($this->stripPunctuation($string));
$string = str_replace("-", " ", $string);
$terms = explode(" ", $string);
$prepared = [];
foreach ($terms as &$t) {
if (!$this->isStopWord($t) and strlen($t) >= 3) {
$prepared[] = metaphone($t);
}
}
return $prepared;
}
示例10: formatRecord
function formatRecord($person, $merge_with = array())
{
$base_person = array('pidm' => '', 'wpid' => '', 'psu_id' => '', 'username' => '', 'email' => '', 'msc' => '', 'name_first' => '', 'name_first_formatted' => '', 'name_first_metaphone' => '', 'name_last' => '', 'name_last_formatted' => '', 'name_last_metaphone' => '', 'name_middle_formatted' => '', 'name_full' => '', 'phone_of' => '', 'phone_vm' => '', 'emp' => '0', 'stu' => '0', 'stu_account' => '0', 'dept' => '', 'title' => '', 'major' => '', 'has_idcard' => '0');
$person['office_phone'] = PSU::stripPunct($person['office_phone']);
$person['phone_number'] = PSU::stripPunct($person['phone_number']);
if ($merge_with) {
$merge_with = PSU::params($merge_with, $base_person);
$person = PSU::params($person, $merge_with);
} else {
$person = PSU::params($person, $base_person);
}
//end else
$final = array('pidm' => $person['pidm'], 'wpid' => $person['wp_id'], 'psu_id' => $person['psu_id'], 'username' => !strpos($person['username'], '@') ? trim($person['username']) : substr($person['username'], 0, strpos($person['username'], '@')), 'email' => !strpos($person['email'], '@') ? trim($person['email']) : substr($person['email'], 0, strpos($person['email'], '@')), 'msc' => $person['msc'] ? $person['msc'] : '', 'name_first' => PSU::stripPunct($person['first_name']), 'name_first_formatted' => $person['first_name'], 'name_first_metaphone' => metaphone(PSU::stripPunct($person['first_name'])), 'name_last' => PSU::stripPunct($person['last_name']), 'name_last_formatted' => $person['last_name'], 'name_last_metaphone' => metaphone(PSU::stripPunct($person['last_name'])), 'name_middle_formatted' => $person['middle_name'], 'name_full' => trim(preg_replace('/\\s\\s+/', ' ', $person['first_name'] . ' ' . substr($person['middle_name'], 0, 1) . ' ' . $person['last_name'] . ' ' . $person['spbpers_name_suffix'])), 'phone_of' => $person['office_phone'] ? '(603) ' . substr($person['office_phone'], 0, 3) . '-' . substr($person['office_phone'], 3) : FALSE, 'phone_vm' => $person['phone_number'] ? '(603) ' . substr($person['phone_number'], 0, 3) . '-' . substr($person['phone_number'], 3) : FALSE, 'emp' => $person['emp'] ? 1 : 0, 'stu' => $person['stu'] ? 1 : 0, 'stu_account' => $person['stu_account'] ? 1 : 0, 'dept' => $person['department'] ?: '', 'title' => $person['title'] ?: '', 'major' => $person['major'] ?: '', 'has_idcard' => $person['has_idcard']);
return $final;
}
示例11: customize
function customize()
{
print metaphone("That's just wack");
$fields = array();
$fields["heading_1"] = COMP_NAME;
$fields["heading_2"] = date("d/m/Y");
$fields["heading_3"] = "Balance Sheet";
$fields["heading_4"] = "Prepared by: " . USER_NAME;
foreach ($fields as $var_name => $value) {
${$var_name} = $value;
}
db_conn("cubit");
$OUTPUT = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n\t\t<tr>\n\t\t\t<td align='left'><h3>{$heading_1}</h3></td>\n\t\t\t<td align='right'><h3>{$heading_2}</h3></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='left'><h3>{$heading_3}</h3></td>\n\t\t\t<td align='right'><h3>{$heading_4}</h3></td>\n\t\t</tr>\n\t</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr>\n\t\t\t<th>";
return $OUTPUT;
}
示例12: decode
/**
* Get web wervice polyline parameter being decoded
* @param $rsp - string
* @param string $param - response key
* @return string - JSON
*/
protected function decode($rsp, $param = 'routes.overview_polyline.points')
{
$needle = metaphone($param);
// get response
$obj = json_decode($rsp, true);
// flatten array into single level array using 'dot' notation
$obj_dot = array_dot($obj);
// create empty response
$response = [];
// iterate
foreach ($obj_dot as $key => $val) {
// Calculate the metaphone key and compare with needle
$val = strcmp(metaphone($key, strlen($needle)), $needle) === 0 ? PolyUtil::decode($val) : $val;
array_set($response, $key, $val);
}
return json_encode($response, JSON_PRETTY_PRINT);
}
示例13: findPhonetically
public function findPhonetically($productName)
{
$productNameMeta = metaphone($productName);
$map = [];
$max = SIMILAR_MIN_THRESHOLD;
$productId = 0;
$products = Product::scope()->with('default_tax_rate')->get();
foreach ($products as $product) {
if (!$product->product_key) {
continue;
}
$map[$product->id] = $product;
$similar = similar_text($productNameMeta, metaphone($product->product_key), $percent);
if ($percent > $max) {
$productId = $product->id;
$max = $percent;
}
}
return $productId && isset($map[$productId]) ? $map[$productId] : null;
}
示例14: getMetaphoneM
function getMetaphoneM($first, $second, $result)
{
$arFirst = explode(" ", $first);
$arSecond = explode(" ", $second);
$m1 = $m2 = "";
foreach ($arFirst as $val) {
$m1 .= metaphone($val);
}
foreach ($arSecond as $val2) {
$m2 .= metaphone($val2);
}
$metaphone['levenshtein'] = levenshtein($m1, $m2);
$metaphone['similarity'] = similar_text($m1, $m2, $perc);
$metaphone['percentage'] = $perc;
if ($result['levenshtein'] > $metaphone['levenshtein'] && $result['percentage'] <= $metaphone['percentage']) {
$result["levenshtein"] = $metaphone['levenshtein'];
$result["percentage"] = $metaphone['percentage'];
$result["match"] = $second;
}
return $result;
}
示例15: pleac_Soundex_Matching
function pleac_Soundex_Matching()
{
#-----------------------------
$code = soundex($string);
#-----------------------------
$phoned_words = metaphone("Schwern");
#-----------------------------
// substitution function for getpwent():
// returns an array of user entries,
// each entry contains the username and the full name
function getpwent()
{
$pwents = array();
$handle = fopen("passwd", "r");
while (!feof($handle)) {
$line = fgets($handle);
if (preg_match("/^#/", $line)) {
continue;
}
$cols = explode(":", $line);
$pwents[$cols[0]] = $cols[4];
}
return $pwents;
}
print "Lookup user: ";
$user = rtrim(fgets(STDIN));
if (empty($user)) {
exit;
}
$name_code = soundex($user);
$pwents = getpwent();
foreach ($pwents as $username => $fullname) {
preg_match("/(\\w+)[^,]*\\b(\\w+)/", $fullname, $matches);
list(, $firstname, $lastname) = $matches;
if ($name_code == soundex($username) || $name_code == soundex($lastname) || $name_code == soundex($firstname)) {
printf("%s: %s %s\n", $username, $firstname, $lastname);
}
}
#-----------------------------
}