prose: github.com/jdkato/prose/tag Index | Examples | Files

package tag

import "github.com/jdkato/prose/tag"

Package tag implements functions for tagging parts of speech.

Index

Examples

Package Files

aptag.go tag.go

type AveragedPerceptron Uses

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

AveragedPerceptron is a Averaged Perceptron classifier.

func NewAveragedPerceptron Uses

func NewAveragedPerceptron(weights map[string]map[string]float64,
    tags map[string]string, classes []string) *AveragedPerceptron

NewAveragedPerceptron creates a new AveragedPerceptron model.

type PerceptronTagger Uses

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

PerceptronTagger is a port of Textblob's "fast and accurate" POS tagger. See https://github.com/sloria/textblob-aptagger for details.

func NewPerceptronTagger Uses

func NewPerceptronTagger() *PerceptronTagger

NewPerceptronTagger creates a new PerceptronTagger and loads the built-in AveragedPerceptron model.

func NewTrainedPerceptronTagger Uses

func NewTrainedPerceptronTagger(model *AveragedPerceptron) *PerceptronTagger

NewTrainedPerceptronTagger creates a new PerceptronTagger using the given model.

func (*PerceptronTagger) Classes Uses

func (pt *PerceptronTagger) Classes() []string

Classes returns the model's classes in the form

["EX", "NNPS", "WP$", ...]

func (*PerceptronTagger) Tag Uses

func (pt *PerceptronTagger) Tag(words []string) []Token

Tag takes a slice of words and returns a slice of tagged tokens.

func (*PerceptronTagger) TagMap Uses

func (pt *PerceptronTagger) TagMap() map[string]string

TagMap returns the model's classes in the form

{
  "four": "CD",
  "facilities": "NNS",
  ...
}

func (*PerceptronTagger) Train Uses

func (pt *PerceptronTagger) Train(sentences TupleSlice, iterations int)

Train an Averaged Perceptron model based on sentences.

func (*PerceptronTagger) Weights Uses

func (pt *PerceptronTagger) Weights() map[string]map[string]float64

Weights returns the model's weights in the form

{
  "i-1 suffix ity": {
    "MD": -0.816,
    "VB": -0.695,
    ...
   }
   ...
}

type Token Uses

type Token struct {
    Text string
    Tag  string
}

Token represents a tagged section of text.

type TupleSlice Uses

type TupleSlice [][][]string

TupleSlice is a slice of tuples in the form (words, tags).

func ReadTagged Uses

func ReadTagged(text, sep string) TupleSlice

ReadTagged converts pre-tagged input into a TupleSlice suitable for training.

Code:

tagged := "Pierre|NNP Vinken|NNP ,|, 61|CD years|NNS"
fmt.Println(ReadTagged(tagged, "|"))

Output:

[[[Pierre Vinken , 61 years] [NNP NNP , CD NNS]]]

func (TupleSlice) Len Uses

func (t TupleSlice) Len() int

Len returns the length of a Tuple.

func (TupleSlice) Swap Uses

func (t TupleSlice) Swap(i, j int)

Swap switches the ith and jth elements in a Tuple.

Package tag imports 7 packages (graph) and is imported by 8 packages. Updated 2017-10-12. Refresh now. Tools for package owners.