GitXplorerGitXplorer
y

spacy-go

public
29 stars
3 forks
3 issues

Commits

List of commits on branch master.
Unverified
73110380c05ae2ae81c6f566abce82bb4a200db8

fix docs

yyash1994 committed 5 years ago
Unverified
4c9582cc4ef8e33b58ce8cf2d19c20ef85020dfc

improve coverage and update docs

yyash1994 committed 5 years ago
Unverified
439674913e3cae9f42e14ad354f73f7baa663335

add pattern matching to golang

yyash1994 committed 5 years ago
Unverified
ef6433fb7c02fbb302027d9a4ad9aa5c064cc2e8

add pattern matching api in python

yyash1994 committed 5 years ago
Unverified
dfd522c1df21ba9a13ad1f0415c94180666998c5

edit test case new model

yyash1994 committed 5 years ago
Unverified
204acf92a62be4f41f6a120585fdbf170d3f4961

edit test for new model

yyash1994 committed 5 years ago

README

The README file for this repository.

spaCy-Go

Build Status GitHub go.mod Go version Python 3.6 codecov

spacy-go is Golang interface for accessing linguistic annotations provided by spaCy using Google's gRPC. This module only supports basic functionalities like loading language models, linguistic annotation and similarity for text sentences.

Installation

Installing Golang library

spacy-go Golang library can be installed by following single command.

go get -v "github.com/yash1994/spacy-go"

Setting up python gRPC server

The $GOPATH environment variable lists places for Go to look for Go Workspaces. By default, Go assumes our GOPATH location is at $HOME/go, where $HOME is the root directory of our user account on our computer.

Before importing the golang library, these commands need to be executed (inside source package) to spin up the python gRPC server.

pip install -r $GOPATH/src/github.com/yash1994/spacy-go/requirements.txt

Install spacy language models with following command.

python3 -m spacy download en_core_web_sm

Connection between client and server is secured by TLS/SSL authentication. Use following command to generate unique pair of root certificate that is used to authenticate the server and private key that only the server has access to.

openssl req -newkey rsa:2048 -nodes -keyout $GOPATH/src/github.com/yash1994/spacy-go/server.key -x509 -days 365 -out $GOPATH/src/github.com/yash1994/spacy-go/server.crt -subj "/CN=localhost"

The following command will spin up python gRPC server at localhost:50051.

python3 $GOPATH/src/github.com/yash1994/spacy-go/api/server.py &

Usage

package main

import (
	"fmt"

	spacygo "github.com/yash1994/spacy-go"
)

func main() {

	// load language model
	var modelName string = "en_core_web_sm"
	r, err := spacygo.Load(modelName)

	if err != nil {
		return
	}

	fmt.Printf("%v \n", r.GetMessage())

	// annotate text
	var text string = "I propose to consider the question, 'Can machines think?"

	doc, err := spacygo.Nlp(text)

	// print annotated info : part-of-speech
	for i, token := range doc.GetTokens() {
		fmt.Printf("token %v '%v' part-of-speech tag: %v \n", i, token.GetText(), token.GetPos())
	}

	// calculate text similarity
	var texta string = "I like apples"
	var textb string = "I like oranges"

	textSimilarity, err := spacygo.Similarity(texta, textb)

	fmt.Printf("text similarity between %v and %v is %v", texta, textb, textSimilarity.GetSimilarity())
}

💫 APIs

Function Arguments Return Type Description
Load modelName string TextResponse, Error Load spaCy's Language Models for text annotations.
Nlp text string ParsedNLPRes, Error Annotate (parse, tag, ner) text using previously loaded model.
Similarity texta string, textb string TextSimilarity, Error Computes semantic similarity between two sentences using loaded language model.
PatternMatch Array of rule struct, text string Matches, Error Match sequences of tokens, based on pattern rules.

ToDos

  • [x] Extensive Test cases
  • [x] Error handling server side
  • [x] Add SSL and auth
  • [x] API Docs
  • [x] Similarity API