PHP Class DiffMatchPatch\Match

Author: Neil Fraser ([email protected])
Author: Daniil Skrobov ([email protected])
Exibir arquivo Open project: yetanotherape/diff-match-patch

Protected Properties

Property Type Description
$distance How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
$maxBits The number of bits in an int.
$threshold At what point is no match declared (0.0 = perfection, 1.0 = very loose).

Public Methods

Method Description
__construct ( )
alphabet ( string $pattern ) : array Initialise the alphabet for the Bitap algorithm.
bitap ( string $text, string $pattern, integer $loc ) : integer Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
getDistance ( ) : integer
getMaxBits ( ) : integer
getThreshold ( ) : float
main ( string $text, string $pattern, integer $loc ) : integer Locate the best instance of 'pattern' in 'text' near 'loc'.
setDistance ( integer $distance )
setMaxBits ( integer $maxBits )
setThreshold ( float $threshold )

Protected Methods

Method Description
bitapScore ( integer $errors, integer $matchLoc, integer $patternLen, integer $searchLoc ) : float Compute and return the score for a match with e errors and x location.

Method Details

__construct() public method

public __construct ( )

alphabet() public method

Initialise the alphabet for the Bitap algorithm.
public alphabet ( string $pattern ) : array
$pattern string The text to encode.
return array Hash of character locations.

bitap() public method

Locate the best instance of 'pattern' in 'text' near 'loc' using the Bitap algorithm.
public bitap ( string $text, string $pattern, integer $loc ) : integer
$text string The text to search.
$pattern string The pattern to search for.
$loc integer The location to search around.
return integer Best match index or -1.

bitapScore() protected method

Accesses loc and pattern through being a closure.
protected bitapScore ( integer $errors, integer $matchLoc, integer $patternLen, integer $searchLoc ) : float
$errors integer Number of errors in match.
$matchLoc integer Location of match.
$patternLen integer Length of pattern to search.
$searchLoc integer The location to search around. TODO refactor param usage.
return float Overall score for match (0.0 = good, 1.0 = bad).

getDistance() public method

public getDistance ( ) : integer
return integer

getMaxBits() public method

public getMaxBits ( ) : integer
return integer

getThreshold() public method

public getThreshold ( ) : float
return float

main() public method

Locate the best instance of 'pattern' in 'text' near 'loc'.
public main ( string $text, string $pattern, integer $loc ) : integer
$text string The text to search.
$pattern string The pattern to search for.
$loc integer The location to search around.
return integer Best match index or -1.

setDistance() public method

public setDistance ( integer $distance )
$distance integer

setMaxBits() public method

public setMaxBits ( integer $maxBits )
$maxBits integer

setThreshold() public method

public setThreshold ( float $threshold )
$threshold float

Property Details

$distance protected_oe property

How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
protected $distance

$maxBits protected_oe property

The number of bits in an int.
protected $maxBits

$threshold protected_oe property

At what point is no match declared (0.0 = perfection, 1.0 = very loose).
protected $threshold