當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。