Skip to content

Instantly share code, notes, and snippets.

@kariyayo
Last active February 4, 2019 09:13
Show Gist options
  • Save kariyayo/21b2ceb0c6a91afb1c47a1e041397122 to your computer and use it in GitHub Desktop.
Save kariyayo/21b2ceb0c6a91afb1c47a1e041397122 to your computer and use it in GitHub Desktop.
すもも も もも も もも の うち
package main
import (
"fmt"
mecab "github.com/shogo82148/go-mecab"
)
func main() {
tagger, err := mecab.New(map[string]string{"output-format-type": "wakati"})
if err != nil {
panic(err)
}
defer tagger.Destroy()
// avoid GC problem with MeCab 0.996 (see https://github.com/taku910/mecab/pull/24)
tagger.Parse("")
node, err := tagger.ParseToNode("すもももももももものうち")
if err != nil {
panic(err)
}
for ; !node.IsZero(); node = node.Next() {
fmt.Printf("%s\t%s\n", node.Surface(), node.Feature())
}
}
@kariyayo
Copy link
Author

kariyayo commented Feb 3, 2019

$ export CGO_LDFLAGS="`mecab-config --libs`"
$ export CGO_CFLAGS="-I`mecab-config --inc-dir`"
$ go get github.com/shogo82148/go-mecab

@kariyayo
Copy link
Author

kariyayo commented Feb 4, 2019

$ go run word_frequency.go 
        BOS/EOS,*,*,*,*,*,*,*,*
すもも  名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も      助詞,係助詞,*,*,*,*,も,モ,モ
もも    名詞,一般,*,*,*,*,もも,モモ,モモ
も      助詞,係助詞,*,*,*,*,も,モ,モ
もも    名詞,一般,*,*,*,*,もも,モモ,モモ
の      助詞,連体化,*,*,*,*,の,ノ,ノ
うち    名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
        BOS/EOS,*,*,*,*,*,*,*,*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment