本文整理汇总了Golang中github.com/anchepiece/suggest.Suggest.QueryAgainst方法的典型用法代码示例。如果您正苦于以下问题:Golang Suggest.QueryAgainst方法的具体用法?Golang Suggest.QueryAgainst怎么用?Golang Suggest.QueryAgainst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/anchepiece/suggest.Suggest
的用法示例。
在下文中一共展示了Suggest.QueryAgainst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: simpleExample
func simpleExample() {
suggester := suggest.Suggest{}
query := "fgerp"
commands := []string{"cat", "mkdir", "fgrep", "history"}
match, err := suggester.AutocorrectAgainst(query, commands)
if err == nil {
fmt.Println("Autocorrected to:", match) // "fgrep"
}
suggester.Commands = commands
if match, err := suggester.Autocorrect(query); err == nil {
fmt.Println("Also Autocorrected to:", match) // "fgrep"
}
query = "println"
commands = []string{"Fprint", "Fprintf", "Fprintln", "Sprintf", "Print", "Printf", "Println"}
suggester.Options.SimilarityMinimum = 8
fmt.Printf("Searching %v for %s\n", query, commands)
if result, err := suggester.QueryAgainst(query, commands); err == nil {
if !result.Success() {
fmt.Println("No close matches")
} else {
fmt.Println("Similar matches:", result.Matches) // [Println Fprintln]
fmt.Println("Autocorrect:", result.Autocorrect) // Println
}
}
os.Exit(0)
}
示例2: TestQueryAgainst
func TestQueryAgainst(t *testing.T) {
s := suggest.Suggest{}
for _, tt := range queryTests {
query := tt.query
result, err := s.QueryAgainst(query, tt.commands)
actual := result.Matches
if err != nil {
t.Errorf("TestQueryAgainst(%v) returned error %v", tt.query, err)
continue
}
if !reflect.DeepEqual(actual, tt.expected) {
t.Errorf("TestQueryAgainst(%q, %v) = %q, want %q", tt.query, tt.commands, actual, tt.expected)
}
}
}
示例3: simpleExample2
func simpleExample2() {
suggester := suggest.Suggest{}
query := "fgerp"
commands := []string{"cat", "mkdir", "fgrep", "history"}
suggester.Commands = commands
if match, err := suggester.Autocorrect("mkdri"); err == nil {
fmt.Println("Autocorrected to:", match) // "mkdir"
}
// Alternate autocorrect usage pattern
match, _ := suggester.AutocorrectAgainst(query, commands)
if match != "" {
fmt.Println("Autocorrected to:", match) // "fgrep"
}
// Alternate usage pattern
query = "printf"
commands = []string{"Fprint", "Fprintf", "Fprintln", "Sprintf", "Printf", "Println"}
suggester.Options.SimilarityMinimum = 8
fmt.Printf("Searching %v in %s\n", query, commands)
if result, err := suggester.QueryAgainst(query, commands); err == nil {
if !result.Success() {
fmt.Println("No close matches")
} else {
fmt.Println("Similar matches:", result.Matches)
// [Println Fprintln]
fmt.Println("Autocorrect:", result.Autocorrect)
// Println
}
}
}