golac

package module
v0.0.0-...-1e8f3f0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document []Sentence

Document contains a result of lac.

func Decode

func Decode(input string) (Document, error)

Decode parse a json output generated by PaddleHub LAC.

type LocalExec

type LocalExec struct {
	LacCmd    string
	LacArgs   []string
	Command   string
	ClassPath string

	Module string
	Option string
	// contains filtered or unexported fields
}

LocalExec is responsible to run PaddleHub LAC process.

func NewLocalExec

func NewLocalExec(ctx context.Context) *LocalExec

NewLocalExec returns a pointer of LocalExec

func (*LocalExec) Run

func (c *LocalExec) Run(text string) (response string, err error)

Run Use PaddleHub lexical analysis model LAC for word segmentation.

type Sentence

type Sentence struct {
	Word []string `json:"word,omitempty"`
	Tag  []string `json:"tag,omitempty"`
}

Sentence

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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