-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: abort all of a kind; CLI 'ais stop'; strings: Damerau-Levensthein
* fix do-abort() when given only a 'kind' * CLI: rewrite 'ais stop', add inline help, add confirmation * move some of the strings utils to CLI (where they belong) * add yet another canonical name: `xact.Cname` Signed-off-by: Alex Aizman <[email protected]>
- Loading branch information
1 parent
3db864b
commit 1acfbc5
Showing
19 changed files
with
204 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ type ( | |
// reporting: log, err | ||
String() string | ||
Name() string | ||
Cname() string | ||
|
||
// modifiers | ||
Finish() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Package cli provides easy-to-use commands to manage, monitor, and utilize AIS clusters. | ||
/* | ||
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package cli | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/NVIDIA/aistore/cmn/cos" | ||
) | ||
|
||
// based on https://en.wikipedia.org/wiki/Damerau–Levenshtein_distance | ||
func DamerauLevenstheinDistance(s, t string) int { | ||
distances := make([][]int, len(s)+1) | ||
for i := range distances { | ||
distances[i] = make([]int, len(t)+1) | ||
} | ||
|
||
// cost of dropping all characters is equal to a length | ||
for i := range distances { | ||
distances[i][0] = i | ||
} | ||
for j := range distances[0] { | ||
distances[0][j] = j | ||
} | ||
|
||
for j := 1; j <= len(t); j++ { | ||
for i := 1; i <= len(s); i++ { | ||
if s[i-1] == t[j-1] { | ||
distances[i][j] = distances[i-1][j-1] | ||
continue | ||
} | ||
|
||
// characters are different. Take character from s or from t or drop character at all | ||
distance := min(distances[i-1][j], distances[i][j-1], distances[i-1][j-1]) | ||
|
||
// check if error might be swap of subsequent characters | ||
if i >= 2 && j >= 2 && s[i-2] == t[j-1] && s[i-1] == t[j-2] { | ||
distance = min(distance, distances[i-2][j-2]) | ||
} | ||
distances[i][j] = distance + 1 | ||
} | ||
} | ||
return distances[len(s)][len(t)] | ||
} | ||
|
||
func strToSentence(str string) string { | ||
if str == "" { | ||
return "" | ||
} | ||
capitalized := capitalizeFirst(str) | ||
if !cos.IsLastB(capitalized, '.') { | ||
capitalized += "." | ||
} | ||
return capitalized | ||
} | ||
|
||
func capitalizeFirst(s string) string { | ||
return strings.ToUpper(s[:1]) + s[1:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Package test provides tests for common low-level types and utilities for all aistore projects | ||
/* | ||
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package test_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/NVIDIA/aistore/cmd/cli/cli" | ||
"github.com/NVIDIA/aistore/tools/tassert" | ||
) | ||
|
||
func TestWordsDistance(t *testing.T) { | ||
testCases := []struct{ expected, actual int }{ | ||
{0, cli.DamerauLevenstheinDistance("test", "test")}, | ||
{1, cli.DamerauLevenstheinDistance("tests", "test")}, | ||
{2, cli.DamerauLevenstheinDistance("cp", "copy")}, | ||
{1, cli.DamerauLevenstheinDistance("teet", "test")}, | ||
{1, cli.DamerauLevenstheinDistance("test", "tset")}, | ||
{3, cli.DamerauLevenstheinDistance("kitten", "sitting")}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tassert.Errorf(t, tc.expected == tc.actual, | ||
"expected Damerau–Levenshtein distance %d, got %d", tc.expected, tc.actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.