Changeset View
Changeset View
Standalone View
Standalone View
src/parser/argument/PhutilArgumentSpellingCorrector.php
Show All 21 Lines | public static function newCommandCorrector() { | ||||
// Adjust to the scaled edit costs we use below, so "2" roughly means | // Adjust to the scaled edit costs we use below, so "2" roughly means | ||||
// "2 edits". | // "2 edits". | ||||
$max_distance = $max_distance * 3; | $max_distance = $max_distance * 3; | ||||
// These costs are somewhat made up, but the theory is that it is far more | // These costs are somewhat made up, but the theory is that it is far more | ||||
// likely you will mis-strike a key ("lans" for "land") or press two keys | // likely you will mis-strike a key ("lans" for "land") or press two keys | ||||
// out of order ("alnd" for "land") than omit keys or press extra keys. | // out of order ("alnd" for "land") than omit keys or press extra keys. | ||||
$matrix = id(new PhutilEditDistanceMatrix()) | $matrix = (new PhutilEditDistanceMatrix()) | ||||
->setInsertCost(4) | ->setInsertCost(4) | ||||
->setDeleteCost(4) | ->setDeleteCost(4) | ||||
->setReplaceCost(3) | ->setReplaceCost(3) | ||||
->setTransposeCost(2); | ->setTransposeCost(2); | ||||
return id(new self()) | return (new self()) | ||||
->setEditDistanceMatrix($matrix) | ->setEditDistanceMatrix($matrix) | ||||
->setMode(self::MODE_COMMANDS) | ->setMode(self::MODE_COMMANDS) | ||||
->setMaximumDistance($max_distance); | ->setMaximumDistance($max_distance); | ||||
} | } | ||||
/** | /** | ||||
* Build a new corrector with parameters for correcting flags, like | * Build a new corrector with parameters for correcting flags, like | ||||
* fixing "--nolint" into "--no-lint". | * fixing "--nolint" into "--no-lint". | ||||
* | * | ||||
* @return PhutilArgumentSpellingCorrector Configured corrector. | * @return PhutilArgumentSpellingCorrector Configured corrector. | ||||
*/ | */ | ||||
public static function newFlagCorrector() { | public static function newFlagCorrector() { | ||||
// When correcting flag spelling, we're stricter than we are when | // When correcting flag spelling, we're stricter than we are when | ||||
// correcting command spelling: we allow only one inserted or deleted | // correcting command spelling: we allow only one inserted or deleted | ||||
// character. It is mainly to handle cases like "--no-lint" versus | // character. It is mainly to handle cases like "--no-lint" versus | ||||
// "--nolint" or "--reviewer" versus "--reviewers". | // "--nolint" or "--reviewer" versus "--reviewers". | ||||
$max_distance = 1; | $max_distance = 1; | ||||
$matrix = id(new PhutilEditDistanceMatrix()) | $matrix = (new PhutilEditDistanceMatrix()) | ||||
->setInsertCost(1) | ->setInsertCost(1) | ||||
->setDeleteCost(1) | ->setDeleteCost(1) | ||||
->setReplaceCost(10); | ->setReplaceCost(10); | ||||
return id(new self()) | return (new self()) | ||||
->setEditDistanceMatrix($matrix) | ->setEditDistanceMatrix($matrix) | ||||
->setMode(self::MODE_FLAGS) | ->setMode(self::MODE_FLAGS) | ||||
->setMaximumDistance($max_distance); | ->setMaximumDistance($max_distance); | ||||
} | } | ||||
public function setMode($mode) { | public function setMode($mode) { | ||||
$this->mode = $mode; | $this->mode = $mode; | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0