mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 08:52:39 +01:00
Use Damerau-Levenshtein to improve british spellings
Summary: Price transpositions very cheaply. We might need to edit these weights a bit, but this covers the two previous cases ("test", "alnd") and gets them right. Test Plan: Unit tests, various `arc x` tests. Reviewers: vrana Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D5034
This commit is contained in:
parent
e96db54125
commit
3136edf9de
2 changed files with 39 additions and 3 deletions
|
@ -196,9 +196,25 @@ class ArcanistConfiguration {
|
|||
array $options,
|
||||
$max_distance) {
|
||||
|
||||
// Adjust to the scaled edit costs we use below, so "2" roughly means
|
||||
// "2 edits".
|
||||
$max_distance = $max_distance * 3;
|
||||
|
||||
// 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
|
||||
// out of order ("alnd" for "land") than omit keys or press extra keys.
|
||||
$matrix = id(new PhutilEditDistanceMatrix())
|
||||
->setInsertCost(4)
|
||||
->setDeleteCost(4)
|
||||
->setReplaceCost(3)
|
||||
->setTransposeCost(2);
|
||||
|
||||
$distances = array();
|
||||
$commandv = str_split($command);
|
||||
foreach ($options as $option) {
|
||||
$distances[$option] = levenshtein($option, $command);
|
||||
$optionv = str_split($option);
|
||||
$matrix->setSequences($optionv, $commandv);
|
||||
$distances[$option] = $matrix->getEditDistance();
|
||||
}
|
||||
|
||||
asort($distances);
|
||||
|
@ -218,7 +234,7 @@ class ArcanistConfiguration {
|
|||
}
|
||||
|
||||
foreach ($distances as $option => $distance) {
|
||||
if (strlen($option) <= 2 * $distance) {
|
||||
if (strlen($option) < $distance) {
|
||||
unset($distances[$option]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ final class ArcanistBritishTestCase extends ArcanistTestCase {
|
|||
|
||||
public function testCompletion() {
|
||||
$this->assertCompletion(
|
||||
array('land', 'amend'),
|
||||
array('land'),
|
||||
'alnd',
|
||||
array('land', 'amend'));
|
||||
|
||||
|
@ -17,6 +17,26 @@ final class ArcanistBritishTestCase extends ArcanistTestCase {
|
|||
array(),
|
||||
'test',
|
||||
array('list', 'unit'));
|
||||
|
||||
$this->assertCompletion(
|
||||
array('list'),
|
||||
'lists',
|
||||
array('list'));
|
||||
|
||||
$this->assertCompletion(
|
||||
array('diff'),
|
||||
'dfif',
|
||||
array('diff'));
|
||||
|
||||
$this->assertCompletion(
|
||||
array('unit'),
|
||||
'uint',
|
||||
array('unit', 'lint', 'list'));
|
||||
|
||||
$this->assertCompletion(
|
||||
array('list', 'lint'),
|
||||
'nilt',
|
||||
array('unit', 'lint', 'list'));
|
||||
}
|
||||
|
||||
private function assertCompletion($expect, $input, $commands) {
|
||||
|
|
Loading…
Reference in a new issue