awsong / go-darts

Double-ARray Trie System for golang
Other
95 stars 24 forks source link

DAWG - usage issues. #1

Closed tbytes closed 12 years ago

tbytes commented 12 years ago

func main() {
d, err := darts.Import("../src/darts/darts.txt", "darts.lib", true) // fmt.Println(err) if err == nil {

    key := []byte("考察队员")
    r := d.CommonPrefixSearch(key, 0)
    fmt.Println(r)
    for i := 0; i < len(r); i++ {
        fmt.Println("kk ", string(key[:r[i].PrefixLen]))
    }

}

Produces:

input dict length: 109135 build out length 373050 18.472ms [] [Finished in 2.5s]

Without DAWG = True- it works just fine. ??

Just playing with it, interested in Double-Array Trie and DAWG specifically. Thank you.

awsong commented 12 years ago

DAWG doesn't work with byte now, only rune. Sorry I didn't pay attention.

If you change your line from key := []byte("考察队员") to key := []rune("考察队员") It will work fine.

Line 200 in dawg.go is the key why it doesn't work with byte. It doesn't even compile. You can run gofmt -tabs=false -tabwidth=4 -r='rune /_Keytype/ -> byte /_Keytype/' -w darts.go gofmt -tabs=false -tabwidth=4 -r='rune /_Keytype/ -> byte /_Keytype/' -w dawg.go and then try to compile. Don't have time to fix this right now. I'd very appreciate if you can find a solution.