assocentity

package module
v4.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 3 Imported by: 0

README

assocentity

Package assocentity returns the average distance from words to a given entity.

Features

  • Interfere at every step
  • pass aliases to entity
  • provides a default tokenzier

Installation

$ go get github.com/ndabAP/assocentity/v4

Prerequisites

Sign-up for a Cloud Natural Language API service account key and download the generated JSON file. This equals the credentialsFile at the example below. You can also create your own tokenizer.

Usage

import (
	"fmt"
	"log"

	"github.com/ndabAP/assocentity/v4/tokenize"
	"github.com/ndabAP/assocentity/v4"
)

const (
	credentialsFile = "google_nlp_service_account.json"
	sep             = " "
)

func main() {
	text := "Punchinello wanted Payne? He'd see the pain."
	entities := []string{"Punchinello", "Payne"}

    	// Create a NLP instance
	nlp, err := tokenize.NewNLP(credentialsFile, text, entities)
	if err != nil {
		log.Fatal(err)
	}

    	// Join merges the entities with a simple algorithm
	dj := tokenize.NewDefaultJoin(sep)
	if err = dj.Join(nlp); err != nil {
		log.Fatal(err)
	}

    	// Do calculates the average distances
	assocEntities, err := assocentity.Do(dj, nlp, entities)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(assocEntities) // map[wanted:1 ?:2 He:3 'd:4 see:5 the:6 pain:7 .:8]
}

Author

Julian Claus and contributors.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(j tokenize.Joiner, tokenizer tokenize.Tokenizer, entities []string) (map[string]float64, error)

Do returns the entity distances

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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