Skip to content

Commit

Permalink
Beginning of a reimplementation in Go.
Browse files Browse the repository at this point in the history
For now this is just an early proof of concept using my DAWGo library.
  • Loading branch information
rhcarvalho committed Jan 30, 2013
1 parent 58c692b commit 6babb94
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions shenmeci.go
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"github.com/rhcarvalho/DAWGo/dawg"
)

func segment(d *dawg.DAWG, sentence string) (words []string) {
var longestWord string
for len(sentence) > 0 {
prefixes := d.Prefixes(sentence)
if len(prefixes) > 0 {
longestWord = prefixes[len(prefixes)-1]
} else {
longestWord = sentence[:1]
}
words = append(words, longestWord)
sentence = sentence[len(longestWord):]
}
return
}

func main() {
d := dawg.New([]string{"go", "python", "ruby", "c", "cpp"})
fmt.Println(segment(d, "golangpythoncpp"))
}

0 comments on commit 6babb94

Please sign in to comment.