go-mecab: github.com/shogo82148/go-mecab Index | Examples | Files

package mecab

import "github.com/shogo82148/go-mecab"

Index

Examples

Package Files

lattice.go mecab.go model.go node.go

Constants

const (
    // NormalNode is status for normal node.
    NormalNode NodeStat = 0

    // UnknownNode is status for unknown node.
    UnknownNode = 1

    // BOSNode is status for BOS(Begin Of Sentence) node.
    BOSNode = 2

    // EOSNode is status for EOS(End Of Sentence) node.
    EOSNode = 3

    // EONNode is status for EON(End Of Node) node.
    EONNode = 4
)

type Lattice Uses

type Lattice struct {
    // contains filtered or unexported fields
}

Lattice is a lattice.

func NewLattice Uses

func NewLattice() (Lattice, error)

NewLattice creates new lattice.

func (Lattice) BOSNode Uses

func (l Lattice) BOSNode() Node

BOSNode returns the Begin Of Sentence node.

func (Lattice) Clear Uses

func (l Lattice) Clear()

Clear set empty string to the lattice.

func (Lattice) Destroy Uses

func (l Lattice) Destroy()

Destroy frees the lattice.

func (Lattice) EOSNode Uses

func (l Lattice) EOSNode() Node

EOSNode returns the End Of Sentence node.

func (Lattice) IsAvailable Uses

func (l Lattice) IsAvailable() bool

IsAvailable returns the lattice is available.

func (Lattice) Sentence Uses

func (l Lattice) Sentence() string

Sentence returns the sentence in the lattice.

func (Lattice) SetSentence Uses

func (l Lattice) SetSentence(s string)

SetSentence set the sentence in the lattice.

func (Lattice) String Uses

func (l Lattice) String() string

type MeCab Uses

type MeCab struct {
    // contains filtered or unexported fields
}

MeCab is a morphological parser.

func New Uses

func New(args map[string]string) (MeCab, error)

New returns new MeCab parser.

func (MeCab) Destroy Uses

func (m MeCab) Destroy()

Destroy frees the MeCab parser.

func (MeCab) Error Uses

func (m MeCab) Error() error

func (MeCab) Parse Uses

func (m MeCab) Parse(s string) (string, error)

Parse parses the string and returns the result as string

Code:

tagger, err := mecab.New(map[string]string{})
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 Uses

func (m MeCab) ParseLattice(lattice Lattice) error

ParseLattice parses the lattice and returns the result as string.

Code:

tagger, err := mecab.New(map[string]string{})
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

func (MeCab) ParseToNode Uses

func (m MeCab) ParseToNode(s string) (Node, error)

ParseToNode parses the string and returns the result as Node

Code:

tagger, err := mecab.New(map[string]string{})
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,*,*,*,*,*,*,*,*

func (MeCab) ParseToString Uses

func (m MeCab) ParseToString(s string) (string, error)

ParseToString is alias of Parse

type Model Uses

type Model struct {
    // contains filtered or unexported fields
}

Model is a dictionary model of MeCab.

func NewModel Uses

func NewModel(args map[string]string) (Model, error)

NewModel returns a new model.

func (Model) Destroy Uses

func (m Model) Destroy()

Destroy frees the model.

func (Model) NewLattice Uses

func (m Model) NewLattice() (Lattice, error)

NewLattice returns a new lattice.

func (Model) NewMeCab Uses

func (m Model) NewMeCab() (MeCab, error)

NewMeCab returns a new mecab.

func (Model) Swap Uses

func (m Model) Swap(m2 Model)

Swap replaces the model by the othor model.

type Node Uses

type Node struct {
    // contains filtered or unexported fields
}

Node is a node in a lattice.

func (Node) Alpha Uses

func (node Node) Alpha() float32

Alpha returns the forward accumulative log summation.

func (Node) BNext Uses

func (node Node) BNext() Node

BNext resturns a node which begins same position

func (Node) Beta Uses

func (node Node) Beta() float32

Beta returns the backward accumulative log summation.

func (Node) CharType Uses

func (node Node) CharType() int

CharType returns the character type.

func (Node) Cost Uses

func (node Node) Cost() int

Cost returns the best accumulative cost from bos node to this node.

func (Node) ENext Uses

func (node Node) ENext() Node

ENext resturns a node which ends same position

func (Node) Feature Uses

func (node Node) Feature() string

Feature returns the feature.

func (Node) ID Uses

func (node Node) ID() int

ID returns the id of Node.

func (Node) IsBest Uses

func (node Node) IsBest() bool

IsBest returns that if the Node is the best solution.

func (Node) IsZero Uses

func (node Node) IsZero() bool

IsZero returns whether the node is zero.

func (Node) LCAttr Uses

func (node Node) LCAttr() int

LCAttr returns the right context attribute.

func (Node) Length Uses

func (node Node) Length() int

Length returns the length of the surface string.

func (Node) Next Uses

func (node Node) Next() Node

Next returns the next Node.

func (Node) Prev Uses

func (node Node) Prev() Node

Prev returns the previous Node.

func (Node) Prob Uses

func (node Node) Prob() float32

Prob returns the marginal probability.

func (Node) RCAttr Uses

func (node Node) RCAttr() int

RCAttr returns the right context attribute.

func (Node) RLength Uses

func (node Node) RLength() int

RLength returns the length of the surface string including white space before the morph.

func (Node) Stat Uses

func (node Node) Stat() NodeStat

Stat returns the type of Node.

func (Node) String Uses

func (node Node) String() string

String returns Surface and Feature

func (Node) Surface Uses

func (node Node) Surface() string

Surface returns the surface string.

func (Node) WCost Uses

func (node Node) WCost() int

WCost returns word cost.

type NodeStat Uses

type NodeStat int

NodeStat is status of a node.

func (NodeStat) String Uses

func (stat NodeStat) String() string

Package mecab imports 6 packages (graph) and is imported by 1 packages. Updated 2019-05-19. Refresh now. Tools for package owners.