mecab

package module
v0.0.0-...-c8cfe04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2018 License: MIT Imports: 6 Imported by: 10

README

mecab-golang

CircleCI

A Golang wrapper for mecab.

Dependencies

mecab-golang needs mecab 0.99.

Please install it.

Getting started

Do the following before trying to go get github.com/bluele/mecab-golang.

$ export CGO_LDFLAGS="-L/path/to/lib -lmecab -lstdc++"
$ export CGO_CFLAGS="-I/path/to/include"
$ go get github.com/bluele/mecab-golang

If you installed mecab-config (check which mecab-config), do the following commands.

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

Examples

package main

import (
  "fmt"
  "github.com/bluele/mecab-golang"
  "strings"
)

func parseToNode(m *mecab.MeCab) {
  tg, err := m.NewTagger()
  if err != nil {
    panic(err)
  }
  defer tg.Destroy()
  lt, err := m.NewLattice("すもももももももものうち")
  if err != nil {
    panic(err)
  }
  defer lt.Destroy()

  node := tg.ParseToNode(lt)
  for {
    features := strings.Split(node.Feature(), ",")
    if features[0] == "名詞" {
      fmt.Println(fmt.Sprintf("%s %s", node.Surface(), node.Feature()))
    }
    if node.Next() != nil {
      break
    }
  }
}

func main() {
  m, err := mecab.New("-Owakati")
  if err != nil {
    panic(err)
  }
  defer m.Destroy()
  parseToNode(m)
}

Author

Jun Kimura

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StopIteration = errors.New("StopIteration")

Functions

This section is empty.

Types

type Lattice

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

func (*Lattice) Destroy

func (lt *Lattice) Destroy()

type MeCab

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

func New

func New(option ...string) (*MeCab, error)

func (*MeCab) Destroy

func (m *MeCab) Destroy()

func (*MeCab) NewLattice

func (m *MeCab) NewLattice(input string) (*Lattice, error)

func (*MeCab) NewTagger

func (m *MeCab) NewTagger() (*Tagger, error)

type Node

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

func (*Node) Alpha

func (node *Node) Alpha() float32

forward accumulative log summation.

func (*Node) Beta

func (node *Node) Beta() float32

backward accumulative log summation.

func (*Node) Char_type

func (node *Node) Char_type() int

character type

func (*Node) Cost

func (node *Node) Cost() int

best accumulative cost from bos node to this node.

func (*Node) Feature

func (node *Node) Feature() string

feature string

func (*Node) Id

func (node *Node) Id() int

unique node id

func (*Node) Isbest

func (node *Node) Isbest() int

set 1 if this node is best node.

func (*Node) LcAttr

func (node *Node) LcAttr() int

left attribute id

func (*Node) Length

func (node *Node) Length() int

length of the surface form.

func (*Node) Next

func (node *Node) Next() error

proceed to the next node. if current node is last, this method returns StopIteration error.

func (*Node) Posid

func (node *Node) Posid() int

unique part of speech id.

func (*Node) Prob

func (node *Node) Prob() float32

marginal probability.

func (*Node) RcAttr

func (node *Node) RcAttr() int

right attribute id

func (*Node) Rlength

func (node *Node) Rlength() int

length of the surface form including white space before the morph.

func (*Node) StartPos

func (node *Node) StartPos() int

start pos in the text.

func (*Node) Stat

func (node *Node) Stat() int

status of this model.

func (*Node) Surface

func (node *Node) Surface() string

surface string

func (*Node) Wcost

func (node *Node) Wcost() int

word cost.

type Tagger

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

func (*Tagger) Destroy

func (tg *Tagger) Destroy()

func (*Tagger) Parse

func (tg *Tagger) Parse(lt *Lattice) string

func (*Tagger) ParseToNode

func (tg *Tagger) ParseToNode(lt *Lattice) *Node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL