Skip to content

Commit

Permalink
Fix packagist error
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten committed Feb 2, 2018
1 parent 6d756ae commit dac6144
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Oefenweb.nl <https://github.com/tersmitten>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Get text similarity level with Damerau-Levenshtein distance.

## License

BSD
MIT

#### Author Information

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"damerau", "levenshtein", "distance", "similarity"
],
"homepage": "http://github.com/Oefenweb/damerau-levenshtein",
"license": "BSD",
"license": "MIT",
"authors": [{
"name": "Ph4r05",
"homepage": "http://www.phpclasses.org/package/7021-PHP-Get-text-similarity-level-with-Damerau-Levenshtein.html"
Expand Down
29 changes: 12 additions & 17 deletions src/DamerauLevenshtein.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function __construct($firstString, $secondString, $insCost = 1, $delCost
public function getMatrix()
{
$this->setupMatrix();

return $this->matrix;
}

Expand Down Expand Up @@ -168,17 +169,14 @@ private function setupMatrix()
$this->matrix[$i][$j] = min($del, $ins, $sub);

// Transposition cost
if (($i > 1) && ($j > 1)) {
if ($i > 1 && $j > 1) {
// Last two
$ccOne = mb_substr($this->compOne, $i - 2, 1, 'UTF-8');
$ccTwo = mb_substr($this->compTwo, $j - 2, 1, 'UTF-8');

if ($this->compare($cOne, $ccTwo) == 0 && $this->compare($ccOne, $cTwo) == 0) {
// Transposition cost is computed as minimal of two
$this->matrix[$i][$j] = min(
$this->matrix[$i][$j],
$this->matrix[$i - 2][$j - 2] + $trans
);
$this->matrix[$i][$j] = min($this->matrix[$i][$j], $this->matrix[$i - 2][$j - 2] + $trans);
}
}
}
Expand All @@ -200,9 +198,6 @@ public function getMaximalDistance()
$oneSize = mb_strlen($this->compOne, 'UTF-8');
$twoSize = mb_strlen($this->compTwo, 'UTF-8');

// Max cost, result value
$maxCost = 0;

// Is substitution cheaper that delete + insert?
$subCost = min($this->subCost, $this->delCost + $this->insCost);

Expand Down Expand Up @@ -237,11 +232,11 @@ public function getRelativeDistance()
$this->setupMatrix();
}

return 1 - (($this->getSimilarity()) / $this->getMaximalDistance());
return 1 - ($this->getSimilarity() / $this->getMaximalDistance());
}

/**
* Compares two characters from string (this method may be overriden in child class).
* Compares two characters from string (this method may be overridden in child class).
*
* @param string $firstCharacter First character
* @param string $secondCharacter Second character
Expand All @@ -264,19 +259,19 @@ public function displayMatrix()
$oneSize = mb_strlen($this->compOne, 'UTF-8');
$twoSize = mb_strlen($this->compTwo, 'UTF-8');

$out = ' ' . $this->compOne . "\n";
$out = ' ' . $this->compOne . PHP_EOL;
for ($y = 0; $y <= $twoSize; $y += 1) {
if ($y - 1 < 0) {
$out .= ' ';
} else {
$out .= (mb_substr($this->compTwo, $y - 1, 1, 'UTF-8'));
$out .= mb_substr($this->compTwo, $y - 1, 1, 'UTF-8');
}

for ($x = 0; $x <= $oneSize; $x += 1) {
$out .= $this->matrix[$x][$y];
}

$out .= "\n";
$out .= PHP_EOL;
}

return $out;
Expand All @@ -300,7 +295,7 @@ public function getInsCost()
*/
public function setInsCost($insCost)
{
$this->calculated = ($insCost == $this->insCost) ? $this->calculated : false;
$this->calculated = $insCost == $this->insCost ? $this->calculated : false;
$this->insCost = $insCost;
}

Expand All @@ -322,7 +317,7 @@ public function getDelCost()
*/
public function setDelCost($delCost)
{
$this->calculated = ($delCost == $this->delCost) ? $this->calculated : false;
$this->calculated = $delCost == $this->delCost ? $this->calculated : false;
$this->delCost = $delCost;
}

Expand All @@ -344,7 +339,7 @@ public function getSubCost()
*/
public function setSubCost($subCost)
{
$this->calculated = ($subCost == $this->subCost) ? $this->calculated : false;
$this->calculated = $subCost == $this->subCost ? $this->calculated : false;
$this->subCost = $subCost;
}

Expand All @@ -366,7 +361,7 @@ public function getTransCost()
*/
public function setTransCost($transCost)
{
$this->calculated = ($transCost == $this->transCost) ? $this->calculated : false;
$this->calculated = $transCost == $this->transCost ? $this->calculated : false;
$this->transCost = $transCost;
}
}

0 comments on commit dac6144

Please sign in to comment.