Back to godoc.org
github.com/shogo82148/go-mecab

package mecab

v0.0.3
Latest Go to latest
Published: Feb 26, 2020 | License: MIT | Module: github.com/shogo82148/go-mecab

Index

Examples

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

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

Lattice is a lattice.

func NewLattice

func NewLattice() (Lattice, error)

NewLattice creates new lattice.

func (Lattice) BOSNode

func (l Lattice) BOSNode() Node

BOSNode returns the Begin Of Sentence node.

func (Lattice) Clear

func (l Lattice) Clear()

Clear set empty string to the lattice.

func (Lattice) Destroy

func (l Lattice) Destroy()

Destroy frees the lattice.

func (Lattice) EOSNode

func (l Lattice) EOSNode() Node

EOSNode returns the End Of Sentence node.

func (Lattice) IsAvailable

func (l Lattice) IsAvailable() bool

IsAvailable returns the lattice is available.

func (Lattice) Sentence

func (l Lattice) Sentence() string

Sentence returns the sentence in the lattice.

func (Lattice) SetSentence

func (l Lattice) SetSentence(s string)

SetSentence set the sentence in the lattice.

func (Lattice) String

func (l Lattice) String() string

type MeCab

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

MeCab is a morphological parser.

func New

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

New returns new MeCab parser.

func (MeCab) Destroy

func (m MeCab) Destroy()

Destroy frees the MeCab parser.

func (MeCab) Error

func (m MeCab) Error() error

func (MeCab) Parse

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

Parse parses the string and returns the result as string

Example

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

func (m MeCab) ParseLattice(lattice Lattice) error

ParseLattice parses the lattice and returns the result as string.

Example

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

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

ParseToNode parses the string and returns the result as Node

Example

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

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

ParseToString is alias of Parse

type Model

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

Model is a dictionary model of MeCab.

func NewModel

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

NewModel returns a new model.

func (Model) Destroy

func (m Model) Destroy()

Destroy frees the model.

func (Model) NewLattice

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

NewLattice returns a new lattice.

func (Model) NewMeCab

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

NewMeCab returns a new mecab.

func (Model) Swap

func (m Model) Swap(m2 Model)

Swap replaces the model by the other model.

type Node

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

Node is a node in a lattice.

func (Node) Alpha

func (node Node) Alpha() float32

Alpha returns the forward accumulative log summation.

func (Node) BNext

func (node Node) BNext() Node

BNext resturns a node which begins same position

func (Node) Beta

func (node Node) Beta() float32

Beta returns the backward accumulative log summation.

func (Node) CharType

func (node Node) CharType() int

CharType returns the character type.

func (Node) Cost

func (node Node) Cost() int

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

func (Node) ENext

func (node Node) ENext() Node

ENext resturns a node which ends same position

func (Node) Feature

func (node Node) Feature() string

Feature returns the feature.

func (Node) ID

func (node Node) ID() int

ID returns the id of Node.

func (Node) IsBest

func (node Node) IsBest() bool

IsBest returns that if the Node is the best solution.

func (Node) IsZero

func (node Node) IsZero() bool

IsZero returns whether the node is zero.

func (Node) LCAttr

func (node Node) LCAttr() int

LCAttr returns the right context attribute.

func (Node) Length

func (node Node) Length() int

Length returns the length of the surface string.

func (Node) Next

func (node Node) Next() Node

Next returns the next Node.

func (Node) Prev

func (node Node) Prev() Node

Prev returns the previous Node.

func (Node) Prob

func (node Node) Prob() float32

Prob returns the marginal probability.

func (Node) RCAttr

func (node Node) RCAttr() int

RCAttr returns the right context attribute.

func (Node) RLength

func (node Node) RLength() int

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

func (Node) Stat

func (node Node) Stat() NodeStat

Stat returns the type of Node.

func (Node) String

func (node Node) String() string

String returns Surface and Feature

func (Node) Surface

func (node Node) Surface() string

Surface returns the surface string.

func (Node) WCost

func (node Node) WCost() int

WCost returns word cost.

type NodeStat

type NodeStat int

NodeStat is status of a node.

func (NodeStat) String

func (stat NodeStat) String() string
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier