Documentation ¶
Index ¶
- type Error
- type Lattice
- func (l Lattice) AddRequestType(t RequestType)
- func (l Lattice) BOSNode() Node
- func (l Lattice) Clear()
- func (l Lattice) Destroy()
- func (l Lattice) EOSNode() Node
- func (l Lattice) IsAvailable() bool
- func (l Lattice) Next() bool
- func (l Lattice) RequestType() RequestType
- func (l Lattice) Sentence() string
- func (l Lattice) SetRequestType(t RequestType)
- func (l Lattice) SetSentence(s string)
- func (l Lattice) String() string
- type MeCab
- type Model
- type Node
- func (node Node) Alpha() float32
- func (node Node) BNext() Node
- func (node Node) Beta() float32
- func (node Node) CharType() int
- func (node Node) Cost() int
- func (node Node) ENext() Node
- func (node Node) Feature() string
- func (node Node) ID() int
- func (node Node) IsBest() bool
- func (node Node) IsZero() bool
- func (node Node) LCAttr() int
- func (node Node) Length() int
- func (node Node) Next() Node
- func (node Node) PosID() int
- func (node Node) Prev() Node
- func (node Node) Prob() float32
- func (node Node) RCAttr() int
- func (node Node) RLength() int
- func (node Node) Stat() NodeStat
- func (node Node) String() string
- func (node Node) Surface() string
- func (node Node) WCost() int
- type NodeStat
- type RequestType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶ added in v0.0.4
type Error struct {
// contains filtered or unexported fields
}
Error is an error of MeCab.
type Lattice ¶
type Lattice struct {
// contains filtered or unexported fields
}
Lattice is a lattice.
func (Lattice) AddRequestType ¶ added in v0.0.8
func (l Lattice) AddRequestType(t RequestType)
AddRequestType adds the request type.
func (Lattice) IsAvailable ¶
IsAvailable returns the lattice is available.
func (Lattice) Next ¶ added in v0.0.8
Next obtains next-best result. The internal linked list structure is updated. You should set RequestTypeNBest in advance. Return false if no more results are available or RequestType is invalid.
func (Lattice) RequestType ¶ added in v0.0.8
func (l Lattice) RequestType() RequestType
RequestType returns the request type.
func (Lattice) SetRequestType ¶ added in v0.0.8
func (l Lattice) SetRequestType(t RequestType)
SetRequestType sets the request type.
func (Lattice) SetSentence ¶
SetSentence set the sentence in the lattice.
type MeCab ¶
type MeCab struct {
// contains filtered or unexported fields
}
MeCab is a morphological parser.
func (MeCab) Parse ¶
Parse parses the string and returns the result as string. Parse is not safe for concurrent use by multiple goroutines.
Example ¶
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
func (MeCab) ParseLattice ¶
ParseLattice parses the lattice and returns the result as string. ParseLattice is safe for concurrent use by multiple goroutines. Create a lattice for each goroutine.
Example ¶
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
Example (NBest) ¶
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("こんにちは世界") lattice.AddRequestType(mecab.RequestTypeNBest) err = tagger.ParseLattice(lattice) if err != nil { panic(err) } for i := 0; i < 5; i++ { fmt.Println(lattice.String()) if !lattice.Next() { break } }
Output: こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世界 名詞,一般,*,*,*,*,世界,セカイ,セカイ EOS こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世界 名詞,一般,*,*,*,*,世界,セカイ,セカイ EOS こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世 名詞,一般,*,*,*,*,世,ヨ,ヨ 界 名詞,接尾,一般,*,*,*,界,カイ,カイ EOS こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世 名詞,一般,*,*,*,*,世,ヨ,ヨ 界 名詞,固有名詞,地域,一般,*,*,界,サカイ,サカイ EOS こんにちは 感動詞,*,*,*,*,*,こんにちは,コンニチハ,コンニチワ 世 名詞,接尾,助数詞,*,*,*,世,セイ,セイ 界 名詞,接尾,一般,*,*,*,界,カイ,カイ EOS
func (MeCab) ParseToNode ¶
ParseToNode parses the string and returns the result as Node. ParseToNode is not safe for concurrent use by multiple goroutines.
Example ¶
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,*,*,*,*,*,*,*,*
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is a dictionary model of MeCab.
func (Model) NewLattice ¶
NewLattice returns a new lattice.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a node in a lattice.
type NodeStat ¶
type NodeStat int
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 )
type RequestType ¶ added in v0.0.8
type RequestType int
RequestType is a request type.
const ( // RequestTypeOneBest is a request type for one best result. RequestTypeOneBest RequestType = 1 // RequestTypeNBest is a request type for N-best results. RequestTypeNBest RequestType = 2 // RequestTypePartial enables a partial parsing mode. // When this flag is set, the input |sentence| needs to be written // in partial parsing format. RequestTypePartial RequestType = 4 // RequestTypeMarginalProb is a request type for marginal probability. // Set this flag if you want to obtain marginal probabilities. // Marginal probability is set in [Node.Prob]. // The parsing speed will get 3-5 times slower than the default mode. RequestTypeMarginalProb RequestType = 8 // RequestTypeMorphsToNBest is a request type for alternative results. // Set this flag if you want to obtain alternative results. // Not implemented. RequestTypeAlternative RequestType = 16 // RequestTypeAllMorphs is a request type for all morphs. RequestTypeAllMorphs RequestType = 32 // RequestTypeAllocateSentence is a request type for allocating sentence. // When this flag is set, tagger internally copies the body of passed // sentence into internal buffer. RequestTypeAllocateSentence RequestType = 64 )