vulcangz / golac

golac is a Golang wrapper for Baidu PaddleHub LAC (Baidu's open-source lexical analysis tool for Chinese)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

golac

golac is a Golang wrapper for PaddleHub LAC.

Install

Download and install it:

go get github.com/vulcangz/golac

Make sure that you can run PaddleHub LAC on command line:

hub run lac --input_text "今天是个好日子"

Usage

A simple code for using golac is:

package main

import (
  "fmt"
	
  "github.com/vulcangz/golac" // exposes "golac"
)

func main() {
  text := `天气预报说今天要下雨`

  // LocalExec connector is responsible to run PaddleHub LAC process.
  c := golac.NewLocalExec(nil)
  c.Option = "--input_text"   // default option

  // LAC text
  doc, err := c.Run(text)
  if err != nil {
    fmt.Println(err.Error())
  }
  
  d, _ := golac.Decode(doc)
  for _, v := range d {
    for i := 0; i < len(v.Word); i++ {
      fmt.Printf("%s(%s) ", v.Word[i], v.Tag[i])
    }
  }
}

Output:

天气预报(n) 说(v) 今天(TIME) 要(v) 下雨(v)

LICENSE

MIT

About

golac is a Golang wrapper for Baidu PaddleHub LAC (Baidu's open-source lexical analysis tool for Chinese)

License:MIT License


Languages

Language:Go 100.0%