-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa43541
commit e5b2a8e
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/knadh/dictmaker/search" | ||
"github.com/knadh/knphone" | ||
) | ||
|
||
// Kannada is the Kannada tokenizer that generates tsvectors for romanized (knphone algorithm) | ||
// Kannada strings | ||
type Kannada struct { | ||
ph *knphone.KNphone | ||
} | ||
|
||
// ID returns the ID of the tokenizer. | ||
func (kn *Kannada) ID() string { | ||
return "kannada" | ||
} | ||
|
||
// Name returns the name of the tokenizer. | ||
func (kn *Kannada) Name() string { | ||
return "Kannada" | ||
} | ||
|
||
// Tokenize tokenizes a Kannada string into Romanized (knphone) Postgres | ||
// tsquery string. | ||
func (kn *Kannada) Tokenize(in string) string { | ||
key0, key1, key2 := kn.ph.Encode(in) | ||
if key0 == "" { | ||
return "" | ||
} | ||
return fmt.Sprintf("%s | (%s & %s) ", key2, key1, key0) | ||
} | ||
|
||
// New returns a new instance of the Kannada tokenizer. | ||
func New() (search.Tokenizer, error) { | ||
return &Kannada{ | ||
ph: knphone.New(), | ||
}, nil | ||
} |