当前位置: 首页>>代码示例>>PHP>>正文


PHP Strings::levenshteinQuality方法代码示例

本文整理汇总了PHP中Strings::levenshteinQuality方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::levenshteinQuality方法的具体用法?PHP Strings::levenshteinQuality怎么用?PHP Strings::levenshteinQuality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Strings的用法示例。


在下文中一共展示了Strings::levenshteinQuality方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTranslationMemoryResults

 /**
  * Return an array of search results from our Translation Memory API
  * service with a quality index based on the levenshtein distance.
  *
  * @param  array  $entities      The entities we want to analyse
  * @param  array  $array_strings The strings to look into [locale1 strings, locale2 strings]
  * @param  string $search        The string to search for
  * @param  int    $max_results   Optional, default to 200, the max number of results we return
  * @param  int    $min_quality   Optional, default to 0, The minimal quality index to filter result
  * @return array  An array of strings as [source => string, target => string, quality=> Levenshtein index]
  */
 public static function getTranslationMemoryResults($entities, $array_strings, $search, $max_results = 200, $min_quality = 0)
 {
     $search_results = array_values(self::getTMXResults($entities, $array_strings));
     $output = [];
     foreach ($search_results as $set) {
         // We only want results for which we have a translation
         if ($set[1]) {
             $quality = Strings::levenshteinQuality($search, $set[0]);
             if ($quality >= $min_quality) {
                 $output[] = ['source' => $set[0], 'target' => $set[1], 'quality' => $quality];
             }
         }
     }
     // We sort by quality to get the best results first
     usort($output, function ($a, $b) {
         return $a['quality'] < $b['quality'];
     });
     if ($max_results > 0) {
         array_splice($output, $max_results);
     }
     return $output;
 }
开发者ID:jobava-mozilla,项目名称:transvision,代码行数:33,代码来源:ShowResults.php

示例2: getTranslationMemoryResults

 /**
  * Return an array of search results from our Translation Memory API
  * service with a quality index based on the levenshtein distance.
  *
  * @param  array  $source_strings The source reference strings with entities as keys
  * @param  array  $target_strings The target strings to look into with entities as keys
  * @param  string $search         The string to search for
  * @param  int    $max_results    Optional, default to 200, the max number of results we return
  * @param  int    $min_quality    Optional, default to 0, The minimal quality index to filter result
  * @return array  An array of strings as [source => string, target => string, quality=> Levenshtein index]
  */
 public static function getTranslationMemoryResults($source_strings, $target_strings, $search, $max_results = 200, $min_quality = 0)
 {
     $search_results = array_values(self::getTMXResults(array_keys($source_strings), [$source_strings, $target_strings]));
     $output = [];
     foreach ($search_results as $set) {
         // We only want results for which we have a translation
         if ($set[1]) {
             $quality = round(Strings::levenshteinQuality($search, $set[0]), 2);
             if ($quality >= $min_quality) {
                 $output[] = ['source' => $set[0], 'target' => $set[1], 'quality' => $quality];
             }
         }
     }
     // Remove duplicate results
     $output = array_unique($output, SORT_REGULAR);
     // We sort by quality to get the best results first
     usort($output, function ($a, $b) {
         return $a['quality'] < $b['quality'];
     });
     if ($max_results > 0) {
         array_splice($output, $max_results);
     }
     return $output;
 }
开发者ID:lester-shu,项目名称:transvision,代码行数:35,代码来源:ShowResults.php

示例3: getTranslationMemoryResults

 /**
  * Return an array of search results from our Translation Memory API
  * service with a quality index based on the levenshtein distance.
  *
  * @param  array  $strings     The source and target strings to look into
  * @param  string $search      The string to search for
  * @param  int    $max_results Optional, default to 200, the max number of results we return
  * @param  int    $min_quality Optional, default to 0, The minimal quality index to filter result
  * @return array  An array of strings as [source => string, target => string, quality=> Levenshtein index]
  */
 public static function getTranslationMemoryResults($strings, $search, $max_results = 200, $min_quality = 0)
 {
     if (empty($strings)) {
         return [];
     }
     /*
         Here we prepare an output array with source and target strings plus
         a quality index.
         $set[0] is the source string (usually English) on which we
         calculate a quality index based on the Levenshtein algorithm.
         $set[1] is the target string, that is the language we want
         translations from.
     */
     foreach ($strings as $set) {
         $quality = round(Strings::levenshteinQuality($search, $set[0]), 2);
         if ($quality >= $min_quality) {
             $output[] = ['source' => $set[0], 'target' => $set[1], 'quality' => $quality];
         }
     }
     // Remove duplicate results
     $output = array_unique($output, SORT_REGULAR);
     // We sort by quality to get the best results first
     usort($output, function ($a, $b) {
         return $a['quality'] < $b['quality'];
     });
     if ($max_results > 0) {
         array_splice($output, $max_results);
     }
     return $output;
 }
开发者ID:hellosct1,项目名称:transvision,代码行数:40,代码来源:ShowResults.php


注:本文中的Strings::levenshteinQuality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。