import "github.com/shogo82148/go-mecab"
error.go lattice.go mecab.go model.go node.go
type Error struct {
// contains filtered or unexported fields
}
Error is an error of MeCab.
type Lattice struct {
// contains filtered or unexported fields
}
Lattice is a lattice.
NewLattice creates new lattice.
BOSNode returns the Begin Of Sentence node.
Clear set empty string to the lattice.
Destroy frees the lattice.
EOSNode returns the End Of Sentence node.
IsAvailable returns the lattice is available.
Sentence returns the sentence in the lattice.
SetSentence set the sentence in the lattice.
type MeCab struct {
// contains filtered or unexported fields
}
MeCab is a morphological parser.
New returns new MeCab parser.
Destroy frees the MeCab parser.
Parse parses the string and returns the result as string
Code:
options := map[string]string{} if path := os.Getenv("MECABRC_PATH"); path != "" { options["rcfile"] = path } tagger, err := mecab.New(options) if err != nil { panic(err) } defer tagger.Destroy() result, err := tagger.Parse("こんにちは世界") if err != nil { panic(err) } fmt.Println(result)
Output:
こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世界 名詞,一般,*,*,*,*,世界,セカイ,セカイ EOS
ParseLattice parses the lattice and returns the result as string.
Code:
options := map[string]string{} if path := os.Getenv("MECABRC_PATH"); path != "" { options["rcfile"] = path } tagger, err := mecab.New(options) if err != nil { panic(err) } defer tagger.Destroy() lattice, err := mecab.NewLattice() if err != nil { panic(err) } lattice.SetSentence("こんにちは世界") err = tagger.ParseLattice(lattice) if err != nil { panic(err) } fmt.Println(lattice.String())
Output:
こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世界 名詞,一般,*,*,*,*,世界,セカイ,セカイ EOS
ParseToNode parses the string and returns the result as Node
Code:
options := map[string]string{}
if path := os.Getenv("MECABRC_PATH"); path != "" {
options["rcfile"] = path
}
tagger, err := mecab.New(options)
if err != nil {
panic(err)
}
defer tagger.Destroy()
// XXX: 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())
}
Output:
BOS/EOS,*,*,*,*,*,*,*,* こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世界 名詞,一般,*,*,*,*,世界,セカイ,セカイ BOS/EOS,*,*,*,*,*,*,*,*
ParseToString is alias of Parse
type Model struct {
// contains filtered or unexported fields
}
Model is a dictionary model of MeCab.
NewModel returns a new model.
Destroy frees the model.
NewLattice returns a new lattice.
NewMeCab returns a new mecab.
Swap replaces the model by the other model.
type Node struct {
// contains filtered or unexported fields
}
Node is a node in a lattice.
Alpha returns the forward accumulative log summation.
BNext resturns a node which begins same position
Beta returns the backward accumulative log summation.
CharType returns the character type.
Cost returns the best accumulative cost from bos node to this node.
ENext resturns a node which ends same position
Feature returns the feature.
ID returns the id of Node.
IsBest returns that if the Node is the best solution.
IsZero returns whether the node is zero.
LCAttr returns the right context attribute.
Length returns the length of the surface string.
Next returns the next Node.
Prev returns the previous Node.
Prob returns the marginal probability.
RCAttr returns the right context attribute.
RLength returns the length of the surface string including white space before the morph.
Stat returns the type of Node.
String returns Surface and Feature
Surface returns the surface string.
WCost returns word cost.
NodeStat is status of a node.
const ( // NormalNode is status for normal node. NormalNode NodeStat = 0 // UnknownNode is status for unknown node. UnknownNode NodeStat = 1 // BOSNode is status for BOS(Begin Of Sentence) node. BOSNode NodeStat = 2 // EOSNode is status for EOS(End Of Sentence) node. EOSNode NodeStat = 3 // EONNode is status for EON(End Of Node) node. EONNode NodeStat = 4 )
Package mecab imports 6 packages (graph) and is imported by 2 packages. Updated 2020-10-14. Refresh now. Tools for package owners.