GitXplorerGitXplorer
y

spacy-go

public
29 stars
3 forks
3 issues

Commits

List of commits on branch master.
Unverified
9c69c7f7915b7bb5c2545ab7034fad6e4a60600b

improve coverage

yyash1994 committed 5 years ago
Unverified
004a342ed74392b80c6dd00fc686aa4f1cdcdf9e

fix path issues with test and prod env

yyash1994 committed 5 years ago
Unverified
56029b6a1ab52d8fc64a3111047db18f43f998dc

fix ssl file path golang issue

yyash1994 committed 5 years ago
Unverified
8fe0f2127f40baa7c659709f8342918d42565737

fix ssl cert path issue

yyash1994 committed 5 years ago
Unverified
a92056379420a36db57d24c626be8b2e4f14f910

fix issue with ssl cert path

yyash1994 committed 5 years ago
Unverified
3cbaf0ec650e4cfbcfa7ad661914f8e00cc76f13

add coverage badge

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