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


PHP PKPString::diff方法代码示例

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


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

示例1: testDiff

 /**
  * @covers PKPString::diff
  */
 public function testDiff()
 {
     // Test two strings that have common substrings.
     $originalString = 'The original string.';
     $editedString = 'The edited original.';
     $expectedDiff = array(array(0 => 'The'), array(1 => ' edited'), array(0 => ' original'), array(-1 => ' string'), array(0 => '.'));
     $resultDiff = PKPString::diff($originalString, $editedString);
     self::assertEquals($expectedDiff, $resultDiff);
     // Test two completely different strings.
     $originalString = 'abc';
     $editedString = 'def';
     $expectedDiff = array(array(-1 => 'abc'), array(1 => 'def'));
     $resultDiff = PKPString::diff($originalString, $editedString);
     self::assertEquals($expectedDiff, $resultDiff);
     // A more realistic example from the citation editor use case
     $originalString = 'Willinsky, B. (2006). The access principle: The case for open acces to research and scholarship. Cambridge, MA: MIT Press.';
     $editedString = 'Willinsky, J. (2006). The access principle: The case for open access to research and scholarship. Cambridge, MA: MIT Press.';
     $expectedDiff = array(array(0 => 'Willinsky, '), array(-1 => 'B'), array(1 => 'J'), array(0 => '. (2006). The access principle: The case for open acce'), array(1 => 's'), array(0 => 's to research and scholarship. Cambridge, MA: MIT Press.'));
     $resultDiff = PKPString::diff($originalString, $editedString);
     self::assertEquals($expectedDiff, $resultDiff);
 }
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:24,代码来源:StringTest.php

示例2: _filterConfidenceScore

 /**
  * Derive a confidence score calculated as the similarity of the
  * original raw citation and the citation text generated from the
  * citation description.
  * @param $metadataDescription MetadataDescription
  * @return integer filter confidence score
  */
 function _filterConfidenceScore(&$metadataDescription)
 {
     // Retrieve the original plain text citation.
     $originalCitation = $this->getOriginalRawCitation();
     // Generate the formatted citation output from the description.
     $citationOutputFilter =& $this->getCitationOutputFilter();
     $generatedCitation = $citationOutputFilter->execute($metadataDescription);
     // Strip formatting and the Google Scholar tag so that we get a plain
     // text string that is comparable with the raw citation.
     $generatedCitation = trim(str_replace(GOOGLE_SCHOLAR_TAG, '', strip_tags($generatedCitation)));
     // Compare the original to the generated citation.
     $citationDiff = PKPString::diff($originalCitation, $generatedCitation);
     // Calculate similarity as the number of deleted characters in relation to the
     // number of characters in the original citation. This intentionally excludes
     // additions as these can represent useful data like a DOI or an external link.
     $deletedCharacters = 0;
     foreach ($citationDiff as $diffPart) {
         // Identify deletions.
         if (key($diffPart) == -1) {
             $deletedCharacters += PKPString::strlen(current($diffPart));
         }
     }
     $originalCharacters = PKPString::strlen($originalCitation);
     $partOfCommonCharacters = ($originalCharacters - $deletedCharacters) / $originalCharacters;
     $filterConfidenceScore = (int) round(min($partOfCommonCharacters * 100, 100));
     return $filterConfidenceScore;
 }
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:34,代码来源:Nlm30CitationDemultiplexerFilter.inc.php


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