├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── api ├── python_stubs │ ├── __init__.py │ ├── nlp_pb2.py │ └── nlp_pb2_grpc.py ├── server.py ├── server_test.py └── utils.py ├── docs ├── parsedNlpRes.md ├── patternMatches.md ├── textResponse.md └── textSimilarity.md ├── go-stubs └── nlp.pb.go ├── go.mod ├── go.sum ├── protos └── nlp.proto ├── requirements.txt ├── spacygo.go └── spacygo_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | api/python_stubs/__pycache__* 2 | api/__pycache__* 3 | .pytest_cache 4 | compile-protos.sh 5 | server* 6 | coverage.txt -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - language: python 4 | python: 3.6 5 | before_script: 6 | - python3 -m spacy download en 7 | - pip install pytest 8 | install: 9 | - pip install -r requirements.txt 10 | - openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt -subj "/CN=localhost" 11 | script: 12 | - python -m pytest api/server_test.py 13 | cache: pip 14 | - language: go 15 | node_js: 1.14 16 | before_install: 17 | - export GO111MODULE=on 18 | - source ~/virtualenv/python3.6/bin/activate 19 | - pip install -r requirements.txt 20 | - python3 -m spacy download en 21 | - openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt -subj "/CN=localhost" 22 | install: 23 | - go mod download 24 | script: 25 | - (python3 api/server.py &) && go test -v -coverprofile=coverage.txt -covermode=atomic 26 | after_success: 27 | - bash <(curl -s https://codecov.io/bash) 28 | notifications: 29 | email: false -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2020 YASH 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spaCy-Go 2 | 3 | [![Build Status](https://travis-ci.org/yash1994/spacy-go.svg?branch=master)](https://travis-ci.org/yash1994/spacy-go) 4 | ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/yash1994/spacy-go) 5 | [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) 6 | [![codecov](https://codecov.io/gh/yash1994/spacy-go/branch/master/graph/badge.svg)](https://codecov.io/gh/yash1994/spacy-go) 7 | 8 | spacy-go is Golang interface for accessing linguistic annotations provided by 9 | [spaCy](https://spacy.io) using Google's [gRPC](https://grpc.io/). This module only supports basic functionalities like loading language models, linguistic annotation and similarity for text sentences. 10 | 11 | ## Installation 12 | 13 | ### Installing Golang library 14 | 15 | spacy-go Golang library can be installed by following single command. 16 | 17 | ```bash 18 | go get -v "github.com/yash1994/spacy-go" 19 | ``` 20 | 21 | ### Setting up python gRPC server 22 | 23 | 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. 24 | 25 | Before importing the golang library, these commands need to be executed (inside source package) to spin up the python gRPC server. 26 | 27 | `pip install -r $GOPATH/src/github.com/yash1994/spacy-go/requirements.txt` 28 | 29 | Install spacy [language models](https://spacy.io/models) with following command. 30 | 31 | `python3 -m spacy download en_core_web_sm` 32 | 33 | 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. 34 | 35 | `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"` 36 | 37 | The following command will spin up python gRPC server at `localhost:50051`. 38 | 39 | `python3 $GOPATH/src/github.com/yash1994/spacy-go/api/server.py &` 40 | 41 | ## Usage 42 | 43 | ```Go 44 | package main 45 | 46 | import ( 47 | "fmt" 48 | 49 | spacygo "github.com/yash1994/spacy-go" 50 | ) 51 | 52 | func main() { 53 | 54 | // load language model 55 | var modelName string = "en_core_web_sm" 56 | r, err := spacygo.Load(modelName) 57 | 58 | if err != nil { 59 | return 60 | } 61 | 62 | fmt.Printf("%v \n", r.GetMessage()) 63 | 64 | // annotate text 65 | var text string = "I propose to consider the question, 'Can machines think?" 66 | 67 | doc, err := spacygo.Nlp(text) 68 | 69 | // print annotated info : part-of-speech 70 | for i, token := range doc.GetTokens() { 71 | fmt.Printf("token %v '%v' part-of-speech tag: %v \n", i, token.GetText(), token.GetPos()) 72 | } 73 | 74 | // calculate text similarity 75 | var texta string = "I like apples" 76 | var textb string = "I like oranges" 77 | 78 | textSimilarity, err := spacygo.Similarity(texta, textb) 79 | 80 | fmt.Printf("text similarity between %v and %v is %v", texta, textb, textSimilarity.GetSimilarity()) 81 | } 82 | ``` 83 | 84 | ## :dizzy: APIs 85 | 86 | | Function | Arguments | Return Type | Description | 87 | | -------- | --------- | ----------- | ----------- | 88 | | Load | modelName `string` | [`TextResponse`](docs/textResponse.md), `Error` | Load [spaCy's Language Models](https://spacy.io/usage/models) for text annotations. | 89 | | Nlp | text `string` | [`ParsedNLPRes`](docs/parsedNlpRes.md), `Error` | Annotate (parse, tag, ner) text using previously loaded model. | 90 | | Similarity | texta `string`, textb `string` | [`TextSimilarity`](docs/textSimilarity.md), `Error` | Computes semantic similarity between two sentences using loaded language model. | 91 | | PatternMatch | Array of rule `struct`, text `string` | [`Matches`](docs/patternMatches.md), `Error` | Match sequences of tokens, based on pattern rules. | 92 | 93 | ## ToDos 94 | * [x] Extensive Test cases 95 | * [x] Error handling server side 96 | * [x] Add SSL and auth 97 | * [x] API Docs 98 | * [x] Similarity API 99 | -------------------------------------------------------------------------------- /api/python_stubs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yash1994/spacy-go/73110380c05ae2ae81c6f566abce82bb4a200db8/api/python_stubs/__init__.py -------------------------------------------------------------------------------- /api/python_stubs/nlp_pb2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | # source: nlp.proto 4 | 5 | from google.protobuf import descriptor as _descriptor 6 | from google.protobuf import message as _message 7 | from google.protobuf import reflection as _reflection 8 | from google.protobuf import symbol_database as _symbol_database 9 | # @@protoc_insertion_point(imports) 10 | 11 | _sym_db = _symbol_database.Default() 12 | 13 | 14 | 15 | 16 | DESCRIPTOR = _descriptor.FileDescriptor( 17 | name='nlp.proto', 18 | package='nlp', 19 | syntax='proto3', 20 | serialized_options=None, 21 | serialized_pb=b'\n\tnlp.proto\x12\x03nlp\"\x1b\n\x0bTextRequest\x12\x0c\n\x04text\x18\x01 \x01(\t\"5\n\x15TextSimilarityRequest\x12\r\n\x05texta\x18\x01 \x01(\t\x12\r\n\x05textb\x18\x02 \x01(\t\"\x1f\n\x0cTextResponse\x12\x0f\n\x07message\x18\x01 \x01(\t\"$\n\x0eTextSimilarity\x12\x12\n\nsimilarity\x18\x01 \x01(\x02\"w\n\x03\x44oc\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x14\n\x0ctext_with_ws\x18\x02 \x01(\t\x12\x11\n\tis_tagged\x18\x03 \x01(\x08\x12\x11\n\tis_parsed\x18\x04 \x01(\x08\x12\x10\n\x08is_nered\x18\x05 \x01(\x08\x12\x14\n\x0cis_sentenced\x18\x06 \x01(\x08\"0\n\x03\x45nt\x12\r\n\x05start\x18\x01 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x05\x12\r\n\x05label\x18\x03 \x01(\t\"\"\n\x04Sent\x12\r\n\x05start\x18\x01 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x05\"(\n\nNoun_chunk\x12\r\n\x05start\x18\x01 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x05\"\xca\x04\n\x05Token\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x14\n\x0ctext_with_ws\x18\x02 \x01(\t\x12\x12\n\nwhitespace\x18\x03 \x01(\t\x12\x10\n\x08\x65nt_type\x18\x05 \x01(\t\x12\x0f\n\x07\x65nt_iob\x18\x06 \x01(\t\x12\r\n\x05lemma\x18\x07 \x01(\t\x12\x0c\n\x04norm\x18\x08 \x01(\t\x12\r\n\x05lower\x18\t \x01(\t\x12\r\n\x05shape\x18\n \x01(\t\x12\x0e\n\x06prefix\x18\x0b \x01(\t\x12\x0e\n\x06suffix\x18\x0c \x01(\t\x12\x0b\n\x03pos\x18\r \x01(\t\x12\x0b\n\x03tag\x18\x0e \x01(\t\x12\x0b\n\x03\x64\x65p\x18\x0f \x01(\t\x12\x10\n\x08is_alpha\x18\x10 \x01(\x08\x12\x10\n\x08is_ascii\x18\x11 \x01(\x08\x12\x10\n\x08is_digit\x18\x12 \x01(\x08\x12\x10\n\x08is_lower\x18\x13 \x01(\x08\x12\x10\n\x08is_upper\x18\x14 \x01(\x08\x12\x10\n\x08is_title\x18\x15 \x01(\x08\x12\x10\n\x08is_punct\x18\x16 \x01(\x08\x12\x15\n\ris_left_punct\x18\x17 \x01(\x08\x12\x16\n\x0eis_right_punct\x18\x18 \x01(\x08\x12\x10\n\x08is_space\x18\x19 \x01(\x08\x12\x12\n\nis_bracket\x18\x1a \x01(\x08\x12\x13\n\x0bis_currency\x18\x1b \x01(\x08\x12\x10\n\x08like_url\x18\x1c \x01(\x08\x12\x10\n\x08like_num\x18\x1d \x01(\x08\x12\x12\n\nlike_email\x18\x1e \x01(\x08\x12\x0e\n\x06is_oov\x18\x1f \x01(\x08\x12\x0f\n\x07is_stop\x18 \x01(\x08\x12\x15\n\ris_sent_start\x18! \x01(\x08\x12\x0c\n\x04head\x18\" \x01(\x05\"\xa8\x01\n\x0cParsedNLPRes\x12\r\n\x05model\x18\x01 \x01(\t\x12\x15\n\x03\x64oc\x18\x02 \x01(\x0b\x32\x08.nlp.Doc\x12\x16\n\x04\x65nts\x18\x03 \x03(\x0b\x32\x08.nlp.Ent\x12\x18\n\x05sents\x18\x04 \x03(\x0b\x32\t.nlp.Sent\x12$\n\x0bnoun_chunks\x18\x05 \x03(\x0b\x32\x0f.nlp.Noun_chunk\x12\x1a\n\x06tokens\x18\x06 \x03(\x0b\x32\n.nlp.Token\"%\n\x07Pattern\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t\"2\n\x04Rule\x12\n\n\x02id\x18\x01 \x01(\t\x12\x1e\n\x08patterns\x18\x02 \x03(\x0b\x32\x0c.nlp.Pattern\"/\n\x05Match\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05start\x18\x02 \x01(\x05\x12\x0b\n\x03\x65nd\x18\x03 \x01(\x05\"&\n\x07Matches\x12\x1b\n\x07matches\x18\x01 \x03(\x0b\x32\n.nlp.Match2\xa3\x03\n\x03Nlp\x12\x32\n\tLoadModel\x12\x10.nlp.TextRequest\x1a\x11.nlp.TextResponse\"\x00\x12\x33\n\nNlpProcess\x12\x10.nlp.TextRequest\x1a\x11.nlp.ParsedNLPRes\"\x00\x12\x42\n\rDocSimilarity\x12\x1a.nlp.TextSimilarityRequest\x1a\x13.nlp.TextSimilarity\"\x00\x12)\n\x07\x41\x64\x64Rule\x12\t.nlp.Rule\x1a\x11.nlp.TextResponse\"\x00\x12\x33\n\nRemoveRule\x12\x10.nlp.TextRequest\x1a\x11.nlp.TextResponse\"\x00\x12(\n\x07GetRule\x12\x10.nlp.TextRequest\x1a\t.nlp.Rule\"\x00\x12.\n\nGetMatches\x12\x10.nlp.TextRequest\x1a\x0c.nlp.Matches\"\x00\x12\x35\n\x0cResetMatcher\x12\x10.nlp.TextRequest\x1a\x11.nlp.TextResponse\"\x00\x62\x06proto3' 22 | ) 23 | 24 | 25 | 26 | 27 | _TEXTREQUEST = _descriptor.Descriptor( 28 | name='TextRequest', 29 | full_name='nlp.TextRequest', 30 | filename=None, 31 | file=DESCRIPTOR, 32 | containing_type=None, 33 | fields=[ 34 | _descriptor.FieldDescriptor( 35 | name='text', full_name='nlp.TextRequest.text', index=0, 36 | number=1, type=9, cpp_type=9, label=1, 37 | has_default_value=False, default_value=b"".decode('utf-8'), 38 | message_type=None, enum_type=None, containing_type=None, 39 | is_extension=False, extension_scope=None, 40 | serialized_options=None, file=DESCRIPTOR), 41 | ], 42 | extensions=[ 43 | ], 44 | nested_types=[], 45 | enum_types=[ 46 | ], 47 | serialized_options=None, 48 | is_extendable=False, 49 | syntax='proto3', 50 | extension_ranges=[], 51 | oneofs=[ 52 | ], 53 | serialized_start=18, 54 | serialized_end=45, 55 | ) 56 | 57 | 58 | _TEXTSIMILARITYREQUEST = _descriptor.Descriptor( 59 | name='TextSimilarityRequest', 60 | full_name='nlp.TextSimilarityRequest', 61 | filename=None, 62 | file=DESCRIPTOR, 63 | containing_type=None, 64 | fields=[ 65 | _descriptor.FieldDescriptor( 66 | name='texta', full_name='nlp.TextSimilarityRequest.texta', index=0, 67 | number=1, type=9, cpp_type=9, label=1, 68 | has_default_value=False, default_value=b"".decode('utf-8'), 69 | message_type=None, enum_type=None, containing_type=None, 70 | is_extension=False, extension_scope=None, 71 | serialized_options=None, file=DESCRIPTOR), 72 | _descriptor.FieldDescriptor( 73 | name='textb', full_name='nlp.TextSimilarityRequest.textb', index=1, 74 | number=2, type=9, cpp_type=9, label=1, 75 | has_default_value=False, default_value=b"".decode('utf-8'), 76 | message_type=None, enum_type=None, containing_type=None, 77 | is_extension=False, extension_scope=None, 78 | serialized_options=None, file=DESCRIPTOR), 79 | ], 80 | extensions=[ 81 | ], 82 | nested_types=[], 83 | enum_types=[ 84 | ], 85 | serialized_options=None, 86 | is_extendable=False, 87 | syntax='proto3', 88 | extension_ranges=[], 89 | oneofs=[ 90 | ], 91 | serialized_start=47, 92 | serialized_end=100, 93 | ) 94 | 95 | 96 | _TEXTRESPONSE = _descriptor.Descriptor( 97 | name='TextResponse', 98 | full_name='nlp.TextResponse', 99 | filename=None, 100 | file=DESCRIPTOR, 101 | containing_type=None, 102 | fields=[ 103 | _descriptor.FieldDescriptor( 104 | name='message', full_name='nlp.TextResponse.message', index=0, 105 | number=1, type=9, cpp_type=9, label=1, 106 | has_default_value=False, default_value=b"".decode('utf-8'), 107 | message_type=None, enum_type=None, containing_type=None, 108 | is_extension=False, extension_scope=None, 109 | serialized_options=None, file=DESCRIPTOR), 110 | ], 111 | extensions=[ 112 | ], 113 | nested_types=[], 114 | enum_types=[ 115 | ], 116 | serialized_options=None, 117 | is_extendable=False, 118 | syntax='proto3', 119 | extension_ranges=[], 120 | oneofs=[ 121 | ], 122 | serialized_start=102, 123 | serialized_end=133, 124 | ) 125 | 126 | 127 | _TEXTSIMILARITY = _descriptor.Descriptor( 128 | name='TextSimilarity', 129 | full_name='nlp.TextSimilarity', 130 | filename=None, 131 | file=DESCRIPTOR, 132 | containing_type=None, 133 | fields=[ 134 | _descriptor.FieldDescriptor( 135 | name='similarity', full_name='nlp.TextSimilarity.similarity', index=0, 136 | number=1, type=2, cpp_type=6, label=1, 137 | has_default_value=False, default_value=float(0), 138 | message_type=None, enum_type=None, containing_type=None, 139 | is_extension=False, extension_scope=None, 140 | serialized_options=None, file=DESCRIPTOR), 141 | ], 142 | extensions=[ 143 | ], 144 | nested_types=[], 145 | enum_types=[ 146 | ], 147 | serialized_options=None, 148 | is_extendable=False, 149 | syntax='proto3', 150 | extension_ranges=[], 151 | oneofs=[ 152 | ], 153 | serialized_start=135, 154 | serialized_end=171, 155 | ) 156 | 157 | 158 | _DOC = _descriptor.Descriptor( 159 | name='Doc', 160 | full_name='nlp.Doc', 161 | filename=None, 162 | file=DESCRIPTOR, 163 | containing_type=None, 164 | fields=[ 165 | _descriptor.FieldDescriptor( 166 | name='text', full_name='nlp.Doc.text', index=0, 167 | number=1, type=9, cpp_type=9, label=1, 168 | has_default_value=False, default_value=b"".decode('utf-8'), 169 | message_type=None, enum_type=None, containing_type=None, 170 | is_extension=False, extension_scope=None, 171 | serialized_options=None, file=DESCRIPTOR), 172 | _descriptor.FieldDescriptor( 173 | name='text_with_ws', full_name='nlp.Doc.text_with_ws', index=1, 174 | number=2, type=9, cpp_type=9, label=1, 175 | has_default_value=False, default_value=b"".decode('utf-8'), 176 | message_type=None, enum_type=None, containing_type=None, 177 | is_extension=False, extension_scope=None, 178 | serialized_options=None, file=DESCRIPTOR), 179 | _descriptor.FieldDescriptor( 180 | name='is_tagged', full_name='nlp.Doc.is_tagged', index=2, 181 | number=3, type=8, cpp_type=7, label=1, 182 | has_default_value=False, default_value=False, 183 | message_type=None, enum_type=None, containing_type=None, 184 | is_extension=False, extension_scope=None, 185 | serialized_options=None, file=DESCRIPTOR), 186 | _descriptor.FieldDescriptor( 187 | name='is_parsed', full_name='nlp.Doc.is_parsed', index=3, 188 | number=4, type=8, cpp_type=7, label=1, 189 | has_default_value=False, default_value=False, 190 | message_type=None, enum_type=None, containing_type=None, 191 | is_extension=False, extension_scope=None, 192 | serialized_options=None, file=DESCRIPTOR), 193 | _descriptor.FieldDescriptor( 194 | name='is_nered', full_name='nlp.Doc.is_nered', index=4, 195 | number=5, type=8, cpp_type=7, label=1, 196 | has_default_value=False, default_value=False, 197 | message_type=None, enum_type=None, containing_type=None, 198 | is_extension=False, extension_scope=None, 199 | serialized_options=None, file=DESCRIPTOR), 200 | _descriptor.FieldDescriptor( 201 | name='is_sentenced', full_name='nlp.Doc.is_sentenced', index=5, 202 | number=6, type=8, cpp_type=7, label=1, 203 | has_default_value=False, default_value=False, 204 | message_type=None, enum_type=None, containing_type=None, 205 | is_extension=False, extension_scope=None, 206 | serialized_options=None, file=DESCRIPTOR), 207 | ], 208 | extensions=[ 209 | ], 210 | nested_types=[], 211 | enum_types=[ 212 | ], 213 | serialized_options=None, 214 | is_extendable=False, 215 | syntax='proto3', 216 | extension_ranges=[], 217 | oneofs=[ 218 | ], 219 | serialized_start=173, 220 | serialized_end=292, 221 | ) 222 | 223 | 224 | _ENT = _descriptor.Descriptor( 225 | name='Ent', 226 | full_name='nlp.Ent', 227 | filename=None, 228 | file=DESCRIPTOR, 229 | containing_type=None, 230 | fields=[ 231 | _descriptor.FieldDescriptor( 232 | name='start', full_name='nlp.Ent.start', index=0, 233 | number=1, type=5, cpp_type=1, label=1, 234 | has_default_value=False, default_value=0, 235 | message_type=None, enum_type=None, containing_type=None, 236 | is_extension=False, extension_scope=None, 237 | serialized_options=None, file=DESCRIPTOR), 238 | _descriptor.FieldDescriptor( 239 | name='end', full_name='nlp.Ent.end', index=1, 240 | number=2, type=5, cpp_type=1, label=1, 241 | has_default_value=False, default_value=0, 242 | message_type=None, enum_type=None, containing_type=None, 243 | is_extension=False, extension_scope=None, 244 | serialized_options=None, file=DESCRIPTOR), 245 | _descriptor.FieldDescriptor( 246 | name='label', full_name='nlp.Ent.label', index=2, 247 | number=3, type=9, cpp_type=9, label=1, 248 | has_default_value=False, default_value=b"".decode('utf-8'), 249 | message_type=None, enum_type=None, containing_type=None, 250 | is_extension=False, extension_scope=None, 251 | serialized_options=None, file=DESCRIPTOR), 252 | ], 253 | extensions=[ 254 | ], 255 | nested_types=[], 256 | enum_types=[ 257 | ], 258 | serialized_options=None, 259 | is_extendable=False, 260 | syntax='proto3', 261 | extension_ranges=[], 262 | oneofs=[ 263 | ], 264 | serialized_start=294, 265 | serialized_end=342, 266 | ) 267 | 268 | 269 | _SENT = _descriptor.Descriptor( 270 | name='Sent', 271 | full_name='nlp.Sent', 272 | filename=None, 273 | file=DESCRIPTOR, 274 | containing_type=None, 275 | fields=[ 276 | _descriptor.FieldDescriptor( 277 | name='start', full_name='nlp.Sent.start', index=0, 278 | number=1, type=5, cpp_type=1, label=1, 279 | has_default_value=False, default_value=0, 280 | message_type=None, enum_type=None, containing_type=None, 281 | is_extension=False, extension_scope=None, 282 | serialized_options=None, file=DESCRIPTOR), 283 | _descriptor.FieldDescriptor( 284 | name='end', full_name='nlp.Sent.end', index=1, 285 | number=2, type=5, cpp_type=1, label=1, 286 | has_default_value=False, default_value=0, 287 | message_type=None, enum_type=None, containing_type=None, 288 | is_extension=False, extension_scope=None, 289 | serialized_options=None, file=DESCRIPTOR), 290 | ], 291 | extensions=[ 292 | ], 293 | nested_types=[], 294 | enum_types=[ 295 | ], 296 | serialized_options=None, 297 | is_extendable=False, 298 | syntax='proto3', 299 | extension_ranges=[], 300 | oneofs=[ 301 | ], 302 | serialized_start=344, 303 | serialized_end=378, 304 | ) 305 | 306 | 307 | _NOUN_CHUNK = _descriptor.Descriptor( 308 | name='Noun_chunk', 309 | full_name='nlp.Noun_chunk', 310 | filename=None, 311 | file=DESCRIPTOR, 312 | containing_type=None, 313 | fields=[ 314 | _descriptor.FieldDescriptor( 315 | name='start', full_name='nlp.Noun_chunk.start', index=0, 316 | number=1, type=5, cpp_type=1, label=1, 317 | has_default_value=False, default_value=0, 318 | message_type=None, enum_type=None, containing_type=None, 319 | is_extension=False, extension_scope=None, 320 | serialized_options=None, file=DESCRIPTOR), 321 | _descriptor.FieldDescriptor( 322 | name='end', full_name='nlp.Noun_chunk.end', index=1, 323 | number=2, type=5, cpp_type=1, label=1, 324 | has_default_value=False, default_value=0, 325 | message_type=None, enum_type=None, containing_type=None, 326 | is_extension=False, extension_scope=None, 327 | serialized_options=None, file=DESCRIPTOR), 328 | ], 329 | extensions=[ 330 | ], 331 | nested_types=[], 332 | enum_types=[ 333 | ], 334 | serialized_options=None, 335 | is_extendable=False, 336 | syntax='proto3', 337 | extension_ranges=[], 338 | oneofs=[ 339 | ], 340 | serialized_start=380, 341 | serialized_end=420, 342 | ) 343 | 344 | 345 | _TOKEN = _descriptor.Descriptor( 346 | name='Token', 347 | full_name='nlp.Token', 348 | filename=None, 349 | file=DESCRIPTOR, 350 | containing_type=None, 351 | fields=[ 352 | _descriptor.FieldDescriptor( 353 | name='text', full_name='nlp.Token.text', index=0, 354 | number=1, type=9, cpp_type=9, label=1, 355 | has_default_value=False, default_value=b"".decode('utf-8'), 356 | message_type=None, enum_type=None, containing_type=None, 357 | is_extension=False, extension_scope=None, 358 | serialized_options=None, file=DESCRIPTOR), 359 | _descriptor.FieldDescriptor( 360 | name='text_with_ws', full_name='nlp.Token.text_with_ws', index=1, 361 | number=2, type=9, cpp_type=9, label=1, 362 | has_default_value=False, default_value=b"".decode('utf-8'), 363 | message_type=None, enum_type=None, containing_type=None, 364 | is_extension=False, extension_scope=None, 365 | serialized_options=None, file=DESCRIPTOR), 366 | _descriptor.FieldDescriptor( 367 | name='whitespace', full_name='nlp.Token.whitespace', index=2, 368 | number=3, type=9, cpp_type=9, label=1, 369 | has_default_value=False, default_value=b"".decode('utf-8'), 370 | message_type=None, enum_type=None, containing_type=None, 371 | is_extension=False, extension_scope=None, 372 | serialized_options=None, file=DESCRIPTOR), 373 | _descriptor.FieldDescriptor( 374 | name='ent_type', full_name='nlp.Token.ent_type', index=3, 375 | number=5, type=9, cpp_type=9, label=1, 376 | has_default_value=False, default_value=b"".decode('utf-8'), 377 | message_type=None, enum_type=None, containing_type=None, 378 | is_extension=False, extension_scope=None, 379 | serialized_options=None, file=DESCRIPTOR), 380 | _descriptor.FieldDescriptor( 381 | name='ent_iob', full_name='nlp.Token.ent_iob', index=4, 382 | number=6, type=9, cpp_type=9, label=1, 383 | has_default_value=False, default_value=b"".decode('utf-8'), 384 | message_type=None, enum_type=None, containing_type=None, 385 | is_extension=False, extension_scope=None, 386 | serialized_options=None, file=DESCRIPTOR), 387 | _descriptor.FieldDescriptor( 388 | name='lemma', full_name='nlp.Token.lemma', index=5, 389 | number=7, type=9, cpp_type=9, label=1, 390 | has_default_value=False, default_value=b"".decode('utf-8'), 391 | message_type=None, enum_type=None, containing_type=None, 392 | is_extension=False, extension_scope=None, 393 | serialized_options=None, file=DESCRIPTOR), 394 | _descriptor.FieldDescriptor( 395 | name='norm', full_name='nlp.Token.norm', index=6, 396 | number=8, type=9, cpp_type=9, label=1, 397 | has_default_value=False, default_value=b"".decode('utf-8'), 398 | message_type=None, enum_type=None, containing_type=None, 399 | is_extension=False, extension_scope=None, 400 | serialized_options=None, file=DESCRIPTOR), 401 | _descriptor.FieldDescriptor( 402 | name='lower', full_name='nlp.Token.lower', index=7, 403 | number=9, type=9, cpp_type=9, label=1, 404 | has_default_value=False, default_value=b"".decode('utf-8'), 405 | message_type=None, enum_type=None, containing_type=None, 406 | is_extension=False, extension_scope=None, 407 | serialized_options=None, file=DESCRIPTOR), 408 | _descriptor.FieldDescriptor( 409 | name='shape', full_name='nlp.Token.shape', index=8, 410 | number=10, type=9, cpp_type=9, label=1, 411 | has_default_value=False, default_value=b"".decode('utf-8'), 412 | message_type=None, enum_type=None, containing_type=None, 413 | is_extension=False, extension_scope=None, 414 | serialized_options=None, file=DESCRIPTOR), 415 | _descriptor.FieldDescriptor( 416 | name='prefix', full_name='nlp.Token.prefix', index=9, 417 | number=11, type=9, cpp_type=9, label=1, 418 | has_default_value=False, default_value=b"".decode('utf-8'), 419 | message_type=None, enum_type=None, containing_type=None, 420 | is_extension=False, extension_scope=None, 421 | serialized_options=None, file=DESCRIPTOR), 422 | _descriptor.FieldDescriptor( 423 | name='suffix', full_name='nlp.Token.suffix', index=10, 424 | number=12, type=9, cpp_type=9, label=1, 425 | has_default_value=False, default_value=b"".decode('utf-8'), 426 | message_type=None, enum_type=None, containing_type=None, 427 | is_extension=False, extension_scope=None, 428 | serialized_options=None, file=DESCRIPTOR), 429 | _descriptor.FieldDescriptor( 430 | name='pos', full_name='nlp.Token.pos', index=11, 431 | number=13, type=9, cpp_type=9, label=1, 432 | has_default_value=False, default_value=b"".decode('utf-8'), 433 | message_type=None, enum_type=None, containing_type=None, 434 | is_extension=False, extension_scope=None, 435 | serialized_options=None, file=DESCRIPTOR), 436 | _descriptor.FieldDescriptor( 437 | name='tag', full_name='nlp.Token.tag', index=12, 438 | number=14, type=9, cpp_type=9, label=1, 439 | has_default_value=False, default_value=b"".decode('utf-8'), 440 | message_type=None, enum_type=None, containing_type=None, 441 | is_extension=False, extension_scope=None, 442 | serialized_options=None, file=DESCRIPTOR), 443 | _descriptor.FieldDescriptor( 444 | name='dep', full_name='nlp.Token.dep', index=13, 445 | number=15, type=9, cpp_type=9, label=1, 446 | has_default_value=False, default_value=b"".decode('utf-8'), 447 | message_type=None, enum_type=None, containing_type=None, 448 | is_extension=False, extension_scope=None, 449 | serialized_options=None, file=DESCRIPTOR), 450 | _descriptor.FieldDescriptor( 451 | name='is_alpha', full_name='nlp.Token.is_alpha', index=14, 452 | number=16, type=8, cpp_type=7, label=1, 453 | has_default_value=False, default_value=False, 454 | message_type=None, enum_type=None, containing_type=None, 455 | is_extension=False, extension_scope=None, 456 | serialized_options=None, file=DESCRIPTOR), 457 | _descriptor.FieldDescriptor( 458 | name='is_ascii', full_name='nlp.Token.is_ascii', index=15, 459 | number=17, type=8, cpp_type=7, label=1, 460 | has_default_value=False, default_value=False, 461 | message_type=None, enum_type=None, containing_type=None, 462 | is_extension=False, extension_scope=None, 463 | serialized_options=None, file=DESCRIPTOR), 464 | _descriptor.FieldDescriptor( 465 | name='is_digit', full_name='nlp.Token.is_digit', index=16, 466 | number=18, type=8, cpp_type=7, label=1, 467 | has_default_value=False, default_value=False, 468 | message_type=None, enum_type=None, containing_type=None, 469 | is_extension=False, extension_scope=None, 470 | serialized_options=None, file=DESCRIPTOR), 471 | _descriptor.FieldDescriptor( 472 | name='is_lower', full_name='nlp.Token.is_lower', index=17, 473 | number=19, type=8, cpp_type=7, label=1, 474 | has_default_value=False, default_value=False, 475 | message_type=None, enum_type=None, containing_type=None, 476 | is_extension=False, extension_scope=None, 477 | serialized_options=None, file=DESCRIPTOR), 478 | _descriptor.FieldDescriptor( 479 | name='is_upper', full_name='nlp.Token.is_upper', index=18, 480 | number=20, type=8, cpp_type=7, label=1, 481 | has_default_value=False, default_value=False, 482 | message_type=None, enum_type=None, containing_type=None, 483 | is_extension=False, extension_scope=None, 484 | serialized_options=None, file=DESCRIPTOR), 485 | _descriptor.FieldDescriptor( 486 | name='is_title', full_name='nlp.Token.is_title', index=19, 487 | number=21, type=8, cpp_type=7, label=1, 488 | has_default_value=False, default_value=False, 489 | message_type=None, enum_type=None, containing_type=None, 490 | is_extension=False, extension_scope=None, 491 | serialized_options=None, file=DESCRIPTOR), 492 | _descriptor.FieldDescriptor( 493 | name='is_punct', full_name='nlp.Token.is_punct', index=20, 494 | number=22, type=8, cpp_type=7, label=1, 495 | has_default_value=False, default_value=False, 496 | message_type=None, enum_type=None, containing_type=None, 497 | is_extension=False, extension_scope=None, 498 | serialized_options=None, file=DESCRIPTOR), 499 | _descriptor.FieldDescriptor( 500 | name='is_left_punct', full_name='nlp.Token.is_left_punct', index=21, 501 | number=23, type=8, cpp_type=7, label=1, 502 | has_default_value=False, default_value=False, 503 | message_type=None, enum_type=None, containing_type=None, 504 | is_extension=False, extension_scope=None, 505 | serialized_options=None, file=DESCRIPTOR), 506 | _descriptor.FieldDescriptor( 507 | name='is_right_punct', full_name='nlp.Token.is_right_punct', index=22, 508 | number=24, type=8, cpp_type=7, label=1, 509 | has_default_value=False, default_value=False, 510 | message_type=None, enum_type=None, containing_type=None, 511 | is_extension=False, extension_scope=None, 512 | serialized_options=None, file=DESCRIPTOR), 513 | _descriptor.FieldDescriptor( 514 | name='is_space', full_name='nlp.Token.is_space', index=23, 515 | number=25, type=8, cpp_type=7, label=1, 516 | has_default_value=False, default_value=False, 517 | message_type=None, enum_type=None, containing_type=None, 518 | is_extension=False, extension_scope=None, 519 | serialized_options=None, file=DESCRIPTOR), 520 | _descriptor.FieldDescriptor( 521 | name='is_bracket', full_name='nlp.Token.is_bracket', index=24, 522 | number=26, type=8, cpp_type=7, label=1, 523 | has_default_value=False, default_value=False, 524 | message_type=None, enum_type=None, containing_type=None, 525 | is_extension=False, extension_scope=None, 526 | serialized_options=None, file=DESCRIPTOR), 527 | _descriptor.FieldDescriptor( 528 | name='is_currency', full_name='nlp.Token.is_currency', index=25, 529 | number=27, type=8, cpp_type=7, label=1, 530 | has_default_value=False, default_value=False, 531 | message_type=None, enum_type=None, containing_type=None, 532 | is_extension=False, extension_scope=None, 533 | serialized_options=None, file=DESCRIPTOR), 534 | _descriptor.FieldDescriptor( 535 | name='like_url', full_name='nlp.Token.like_url', index=26, 536 | number=28, type=8, cpp_type=7, label=1, 537 | has_default_value=False, default_value=False, 538 | message_type=None, enum_type=None, containing_type=None, 539 | is_extension=False, extension_scope=None, 540 | serialized_options=None, file=DESCRIPTOR), 541 | _descriptor.FieldDescriptor( 542 | name='like_num', full_name='nlp.Token.like_num', index=27, 543 | number=29, type=8, cpp_type=7, label=1, 544 | has_default_value=False, default_value=False, 545 | message_type=None, enum_type=None, containing_type=None, 546 | is_extension=False, extension_scope=None, 547 | serialized_options=None, file=DESCRIPTOR), 548 | _descriptor.FieldDescriptor( 549 | name='like_email', full_name='nlp.Token.like_email', index=28, 550 | number=30, type=8, cpp_type=7, label=1, 551 | has_default_value=False, default_value=False, 552 | message_type=None, enum_type=None, containing_type=None, 553 | is_extension=False, extension_scope=None, 554 | serialized_options=None, file=DESCRIPTOR), 555 | _descriptor.FieldDescriptor( 556 | name='is_oov', full_name='nlp.Token.is_oov', index=29, 557 | number=31, type=8, cpp_type=7, label=1, 558 | has_default_value=False, default_value=False, 559 | message_type=None, enum_type=None, containing_type=None, 560 | is_extension=False, extension_scope=None, 561 | serialized_options=None, file=DESCRIPTOR), 562 | _descriptor.FieldDescriptor( 563 | name='is_stop', full_name='nlp.Token.is_stop', index=30, 564 | number=32, type=8, cpp_type=7, label=1, 565 | has_default_value=False, default_value=False, 566 | message_type=None, enum_type=None, containing_type=None, 567 | is_extension=False, extension_scope=None, 568 | serialized_options=None, file=DESCRIPTOR), 569 | _descriptor.FieldDescriptor( 570 | name='is_sent_start', full_name='nlp.Token.is_sent_start', index=31, 571 | number=33, type=8, cpp_type=7, label=1, 572 | has_default_value=False, default_value=False, 573 | message_type=None, enum_type=None, containing_type=None, 574 | is_extension=False, extension_scope=None, 575 | serialized_options=None, file=DESCRIPTOR), 576 | _descriptor.FieldDescriptor( 577 | name='head', full_name='nlp.Token.head', index=32, 578 | number=34, type=5, cpp_type=1, label=1, 579 | has_default_value=False, default_value=0, 580 | message_type=None, enum_type=None, containing_type=None, 581 | is_extension=False, extension_scope=None, 582 | serialized_options=None, file=DESCRIPTOR), 583 | ], 584 | extensions=[ 585 | ], 586 | nested_types=[], 587 | enum_types=[ 588 | ], 589 | serialized_options=None, 590 | is_extendable=False, 591 | syntax='proto3', 592 | extension_ranges=[], 593 | oneofs=[ 594 | ], 595 | serialized_start=423, 596 | serialized_end=1009, 597 | ) 598 | 599 | 600 | _PARSEDNLPRES = _descriptor.Descriptor( 601 | name='ParsedNLPRes', 602 | full_name='nlp.ParsedNLPRes', 603 | filename=None, 604 | file=DESCRIPTOR, 605 | containing_type=None, 606 | fields=[ 607 | _descriptor.FieldDescriptor( 608 | name='model', full_name='nlp.ParsedNLPRes.model', index=0, 609 | number=1, type=9, cpp_type=9, label=1, 610 | has_default_value=False, default_value=b"".decode('utf-8'), 611 | message_type=None, enum_type=None, containing_type=None, 612 | is_extension=False, extension_scope=None, 613 | serialized_options=None, file=DESCRIPTOR), 614 | _descriptor.FieldDescriptor( 615 | name='doc', full_name='nlp.ParsedNLPRes.doc', index=1, 616 | number=2, type=11, cpp_type=10, label=1, 617 | has_default_value=False, default_value=None, 618 | message_type=None, enum_type=None, containing_type=None, 619 | is_extension=False, extension_scope=None, 620 | serialized_options=None, file=DESCRIPTOR), 621 | _descriptor.FieldDescriptor( 622 | name='ents', full_name='nlp.ParsedNLPRes.ents', index=2, 623 | number=3, type=11, cpp_type=10, label=3, 624 | has_default_value=False, default_value=[], 625 | message_type=None, enum_type=None, containing_type=None, 626 | is_extension=False, extension_scope=None, 627 | serialized_options=None, file=DESCRIPTOR), 628 | _descriptor.FieldDescriptor( 629 | name='sents', full_name='nlp.ParsedNLPRes.sents', index=3, 630 | number=4, type=11, cpp_type=10, label=3, 631 | has_default_value=False, default_value=[], 632 | message_type=None, enum_type=None, containing_type=None, 633 | is_extension=False, extension_scope=None, 634 | serialized_options=None, file=DESCRIPTOR), 635 | _descriptor.FieldDescriptor( 636 | name='noun_chunks', full_name='nlp.ParsedNLPRes.noun_chunks', index=4, 637 | number=5, type=11, cpp_type=10, label=3, 638 | has_default_value=False, default_value=[], 639 | message_type=None, enum_type=None, containing_type=None, 640 | is_extension=False, extension_scope=None, 641 | serialized_options=None, file=DESCRIPTOR), 642 | _descriptor.FieldDescriptor( 643 | name='tokens', full_name='nlp.ParsedNLPRes.tokens', index=5, 644 | number=6, type=11, cpp_type=10, label=3, 645 | has_default_value=False, default_value=[], 646 | message_type=None, enum_type=None, containing_type=None, 647 | is_extension=False, extension_scope=None, 648 | serialized_options=None, file=DESCRIPTOR), 649 | ], 650 | extensions=[ 651 | ], 652 | nested_types=[], 653 | enum_types=[ 654 | ], 655 | serialized_options=None, 656 | is_extendable=False, 657 | syntax='proto3', 658 | extension_ranges=[], 659 | oneofs=[ 660 | ], 661 | serialized_start=1012, 662 | serialized_end=1180, 663 | ) 664 | 665 | 666 | _PATTERN = _descriptor.Descriptor( 667 | name='Pattern', 668 | full_name='nlp.Pattern', 669 | filename=None, 670 | file=DESCRIPTOR, 671 | containing_type=None, 672 | fields=[ 673 | _descriptor.FieldDescriptor( 674 | name='key', full_name='nlp.Pattern.key', index=0, 675 | number=1, type=9, cpp_type=9, label=1, 676 | has_default_value=False, default_value=b"".decode('utf-8'), 677 | message_type=None, enum_type=None, containing_type=None, 678 | is_extension=False, extension_scope=None, 679 | serialized_options=None, file=DESCRIPTOR), 680 | _descriptor.FieldDescriptor( 681 | name='value', full_name='nlp.Pattern.value', index=1, 682 | number=2, type=9, cpp_type=9, label=1, 683 | has_default_value=False, default_value=b"".decode('utf-8'), 684 | message_type=None, enum_type=None, containing_type=None, 685 | is_extension=False, extension_scope=None, 686 | serialized_options=None, file=DESCRIPTOR), 687 | ], 688 | extensions=[ 689 | ], 690 | nested_types=[], 691 | enum_types=[ 692 | ], 693 | serialized_options=None, 694 | is_extendable=False, 695 | syntax='proto3', 696 | extension_ranges=[], 697 | oneofs=[ 698 | ], 699 | serialized_start=1182, 700 | serialized_end=1219, 701 | ) 702 | 703 | 704 | _RULE = _descriptor.Descriptor( 705 | name='Rule', 706 | full_name='nlp.Rule', 707 | filename=None, 708 | file=DESCRIPTOR, 709 | containing_type=None, 710 | fields=[ 711 | _descriptor.FieldDescriptor( 712 | name='id', full_name='nlp.Rule.id', index=0, 713 | number=1, type=9, cpp_type=9, label=1, 714 | has_default_value=False, default_value=b"".decode('utf-8'), 715 | message_type=None, enum_type=None, containing_type=None, 716 | is_extension=False, extension_scope=None, 717 | serialized_options=None, file=DESCRIPTOR), 718 | _descriptor.FieldDescriptor( 719 | name='patterns', full_name='nlp.Rule.patterns', index=1, 720 | number=2, type=11, cpp_type=10, label=3, 721 | has_default_value=False, default_value=[], 722 | message_type=None, enum_type=None, containing_type=None, 723 | is_extension=False, extension_scope=None, 724 | serialized_options=None, file=DESCRIPTOR), 725 | ], 726 | extensions=[ 727 | ], 728 | nested_types=[], 729 | enum_types=[ 730 | ], 731 | serialized_options=None, 732 | is_extendable=False, 733 | syntax='proto3', 734 | extension_ranges=[], 735 | oneofs=[ 736 | ], 737 | serialized_start=1221, 738 | serialized_end=1271, 739 | ) 740 | 741 | 742 | _MATCH = _descriptor.Descriptor( 743 | name='Match', 744 | full_name='nlp.Match', 745 | filename=None, 746 | file=DESCRIPTOR, 747 | containing_type=None, 748 | fields=[ 749 | _descriptor.FieldDescriptor( 750 | name='id', full_name='nlp.Match.id', index=0, 751 | number=1, type=9, cpp_type=9, label=1, 752 | has_default_value=False, default_value=b"".decode('utf-8'), 753 | message_type=None, enum_type=None, containing_type=None, 754 | is_extension=False, extension_scope=None, 755 | serialized_options=None, file=DESCRIPTOR), 756 | _descriptor.FieldDescriptor( 757 | name='start', full_name='nlp.Match.start', index=1, 758 | number=2, type=5, cpp_type=1, label=1, 759 | has_default_value=False, default_value=0, 760 | message_type=None, enum_type=None, containing_type=None, 761 | is_extension=False, extension_scope=None, 762 | serialized_options=None, file=DESCRIPTOR), 763 | _descriptor.FieldDescriptor( 764 | name='end', full_name='nlp.Match.end', index=2, 765 | number=3, type=5, cpp_type=1, label=1, 766 | has_default_value=False, default_value=0, 767 | message_type=None, enum_type=None, containing_type=None, 768 | is_extension=False, extension_scope=None, 769 | serialized_options=None, file=DESCRIPTOR), 770 | ], 771 | extensions=[ 772 | ], 773 | nested_types=[], 774 | enum_types=[ 775 | ], 776 | serialized_options=None, 777 | is_extendable=False, 778 | syntax='proto3', 779 | extension_ranges=[], 780 | oneofs=[ 781 | ], 782 | serialized_start=1273, 783 | serialized_end=1320, 784 | ) 785 | 786 | 787 | _MATCHES = _descriptor.Descriptor( 788 | name='Matches', 789 | full_name='nlp.Matches', 790 | filename=None, 791 | file=DESCRIPTOR, 792 | containing_type=None, 793 | fields=[ 794 | _descriptor.FieldDescriptor( 795 | name='matches', full_name='nlp.Matches.matches', index=0, 796 | number=1, type=11, cpp_type=10, label=3, 797 | has_default_value=False, default_value=[], 798 | message_type=None, enum_type=None, containing_type=None, 799 | is_extension=False, extension_scope=None, 800 | serialized_options=None, file=DESCRIPTOR), 801 | ], 802 | extensions=[ 803 | ], 804 | nested_types=[], 805 | enum_types=[ 806 | ], 807 | serialized_options=None, 808 | is_extendable=False, 809 | syntax='proto3', 810 | extension_ranges=[], 811 | oneofs=[ 812 | ], 813 | serialized_start=1322, 814 | serialized_end=1360, 815 | ) 816 | 817 | _PARSEDNLPRES.fields_by_name['doc'].message_type = _DOC 818 | _PARSEDNLPRES.fields_by_name['ents'].message_type = _ENT 819 | _PARSEDNLPRES.fields_by_name['sents'].message_type = _SENT 820 | _PARSEDNLPRES.fields_by_name['noun_chunks'].message_type = _NOUN_CHUNK 821 | _PARSEDNLPRES.fields_by_name['tokens'].message_type = _TOKEN 822 | _RULE.fields_by_name['patterns'].message_type = _PATTERN 823 | _MATCHES.fields_by_name['matches'].message_type = _MATCH 824 | DESCRIPTOR.message_types_by_name['TextRequest'] = _TEXTREQUEST 825 | DESCRIPTOR.message_types_by_name['TextSimilarityRequest'] = _TEXTSIMILARITYREQUEST 826 | DESCRIPTOR.message_types_by_name['TextResponse'] = _TEXTRESPONSE 827 | DESCRIPTOR.message_types_by_name['TextSimilarity'] = _TEXTSIMILARITY 828 | DESCRIPTOR.message_types_by_name['Doc'] = _DOC 829 | DESCRIPTOR.message_types_by_name['Ent'] = _ENT 830 | DESCRIPTOR.message_types_by_name['Sent'] = _SENT 831 | DESCRIPTOR.message_types_by_name['Noun_chunk'] = _NOUN_CHUNK 832 | DESCRIPTOR.message_types_by_name['Token'] = _TOKEN 833 | DESCRIPTOR.message_types_by_name['ParsedNLPRes'] = _PARSEDNLPRES 834 | DESCRIPTOR.message_types_by_name['Pattern'] = _PATTERN 835 | DESCRIPTOR.message_types_by_name['Rule'] = _RULE 836 | DESCRIPTOR.message_types_by_name['Match'] = _MATCH 837 | DESCRIPTOR.message_types_by_name['Matches'] = _MATCHES 838 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 839 | 840 | TextRequest = _reflection.GeneratedProtocolMessageType('TextRequest', (_message.Message,), { 841 | 'DESCRIPTOR' : _TEXTREQUEST, 842 | '__module__' : 'nlp_pb2' 843 | # @@protoc_insertion_point(class_scope:nlp.TextRequest) 844 | }) 845 | _sym_db.RegisterMessage(TextRequest) 846 | 847 | TextSimilarityRequest = _reflection.GeneratedProtocolMessageType('TextSimilarityRequest', (_message.Message,), { 848 | 'DESCRIPTOR' : _TEXTSIMILARITYREQUEST, 849 | '__module__' : 'nlp_pb2' 850 | # @@protoc_insertion_point(class_scope:nlp.TextSimilarityRequest) 851 | }) 852 | _sym_db.RegisterMessage(TextSimilarityRequest) 853 | 854 | TextResponse = _reflection.GeneratedProtocolMessageType('TextResponse', (_message.Message,), { 855 | 'DESCRIPTOR' : _TEXTRESPONSE, 856 | '__module__' : 'nlp_pb2' 857 | # @@protoc_insertion_point(class_scope:nlp.TextResponse) 858 | }) 859 | _sym_db.RegisterMessage(TextResponse) 860 | 861 | TextSimilarity = _reflection.GeneratedProtocolMessageType('TextSimilarity', (_message.Message,), { 862 | 'DESCRIPTOR' : _TEXTSIMILARITY, 863 | '__module__' : 'nlp_pb2' 864 | # @@protoc_insertion_point(class_scope:nlp.TextSimilarity) 865 | }) 866 | _sym_db.RegisterMessage(TextSimilarity) 867 | 868 | Doc = _reflection.GeneratedProtocolMessageType('Doc', (_message.Message,), { 869 | 'DESCRIPTOR' : _DOC, 870 | '__module__' : 'nlp_pb2' 871 | # @@protoc_insertion_point(class_scope:nlp.Doc) 872 | }) 873 | _sym_db.RegisterMessage(Doc) 874 | 875 | Ent = _reflection.GeneratedProtocolMessageType('Ent', (_message.Message,), { 876 | 'DESCRIPTOR' : _ENT, 877 | '__module__' : 'nlp_pb2' 878 | # @@protoc_insertion_point(class_scope:nlp.Ent) 879 | }) 880 | _sym_db.RegisterMessage(Ent) 881 | 882 | Sent = _reflection.GeneratedProtocolMessageType('Sent', (_message.Message,), { 883 | 'DESCRIPTOR' : _SENT, 884 | '__module__' : 'nlp_pb2' 885 | # @@protoc_insertion_point(class_scope:nlp.Sent) 886 | }) 887 | _sym_db.RegisterMessage(Sent) 888 | 889 | Noun_chunk = _reflection.GeneratedProtocolMessageType('Noun_chunk', (_message.Message,), { 890 | 'DESCRIPTOR' : _NOUN_CHUNK, 891 | '__module__' : 'nlp_pb2' 892 | # @@protoc_insertion_point(class_scope:nlp.Noun_chunk) 893 | }) 894 | _sym_db.RegisterMessage(Noun_chunk) 895 | 896 | Token = _reflection.GeneratedProtocolMessageType('Token', (_message.Message,), { 897 | 'DESCRIPTOR' : _TOKEN, 898 | '__module__' : 'nlp_pb2' 899 | # @@protoc_insertion_point(class_scope:nlp.Token) 900 | }) 901 | _sym_db.RegisterMessage(Token) 902 | 903 | ParsedNLPRes = _reflection.GeneratedProtocolMessageType('ParsedNLPRes', (_message.Message,), { 904 | 'DESCRIPTOR' : _PARSEDNLPRES, 905 | '__module__' : 'nlp_pb2' 906 | # @@protoc_insertion_point(class_scope:nlp.ParsedNLPRes) 907 | }) 908 | _sym_db.RegisterMessage(ParsedNLPRes) 909 | 910 | Pattern = _reflection.GeneratedProtocolMessageType('Pattern', (_message.Message,), { 911 | 'DESCRIPTOR' : _PATTERN, 912 | '__module__' : 'nlp_pb2' 913 | # @@protoc_insertion_point(class_scope:nlp.Pattern) 914 | }) 915 | _sym_db.RegisterMessage(Pattern) 916 | 917 | Rule = _reflection.GeneratedProtocolMessageType('Rule', (_message.Message,), { 918 | 'DESCRIPTOR' : _RULE, 919 | '__module__' : 'nlp_pb2' 920 | # @@protoc_insertion_point(class_scope:nlp.Rule) 921 | }) 922 | _sym_db.RegisterMessage(Rule) 923 | 924 | Match = _reflection.GeneratedProtocolMessageType('Match', (_message.Message,), { 925 | 'DESCRIPTOR' : _MATCH, 926 | '__module__' : 'nlp_pb2' 927 | # @@protoc_insertion_point(class_scope:nlp.Match) 928 | }) 929 | _sym_db.RegisterMessage(Match) 930 | 931 | Matches = _reflection.GeneratedProtocolMessageType('Matches', (_message.Message,), { 932 | 'DESCRIPTOR' : _MATCHES, 933 | '__module__' : 'nlp_pb2' 934 | # @@protoc_insertion_point(class_scope:nlp.Matches) 935 | }) 936 | _sym_db.RegisterMessage(Matches) 937 | 938 | 939 | 940 | _NLP = _descriptor.ServiceDescriptor( 941 | name='Nlp', 942 | full_name='nlp.Nlp', 943 | file=DESCRIPTOR, 944 | index=0, 945 | serialized_options=None, 946 | serialized_start=1363, 947 | serialized_end=1782, 948 | methods=[ 949 | _descriptor.MethodDescriptor( 950 | name='LoadModel', 951 | full_name='nlp.Nlp.LoadModel', 952 | index=0, 953 | containing_service=None, 954 | input_type=_TEXTREQUEST, 955 | output_type=_TEXTRESPONSE, 956 | serialized_options=None, 957 | ), 958 | _descriptor.MethodDescriptor( 959 | name='NlpProcess', 960 | full_name='nlp.Nlp.NlpProcess', 961 | index=1, 962 | containing_service=None, 963 | input_type=_TEXTREQUEST, 964 | output_type=_PARSEDNLPRES, 965 | serialized_options=None, 966 | ), 967 | _descriptor.MethodDescriptor( 968 | name='DocSimilarity', 969 | full_name='nlp.Nlp.DocSimilarity', 970 | index=2, 971 | containing_service=None, 972 | input_type=_TEXTSIMILARITYREQUEST, 973 | output_type=_TEXTSIMILARITY, 974 | serialized_options=None, 975 | ), 976 | _descriptor.MethodDescriptor( 977 | name='AddRule', 978 | full_name='nlp.Nlp.AddRule', 979 | index=3, 980 | containing_service=None, 981 | input_type=_RULE, 982 | output_type=_TEXTRESPONSE, 983 | serialized_options=None, 984 | ), 985 | _descriptor.MethodDescriptor( 986 | name='RemoveRule', 987 | full_name='nlp.Nlp.RemoveRule', 988 | index=4, 989 | containing_service=None, 990 | input_type=_TEXTREQUEST, 991 | output_type=_TEXTRESPONSE, 992 | serialized_options=None, 993 | ), 994 | _descriptor.MethodDescriptor( 995 | name='GetRule', 996 | full_name='nlp.Nlp.GetRule', 997 | index=5, 998 | containing_service=None, 999 | input_type=_TEXTREQUEST, 1000 | output_type=_RULE, 1001 | serialized_options=None, 1002 | ), 1003 | _descriptor.MethodDescriptor( 1004 | name='GetMatches', 1005 | full_name='nlp.Nlp.GetMatches', 1006 | index=6, 1007 | containing_service=None, 1008 | input_type=_TEXTREQUEST, 1009 | output_type=_MATCHES, 1010 | serialized_options=None, 1011 | ), 1012 | _descriptor.MethodDescriptor( 1013 | name='ResetMatcher', 1014 | full_name='nlp.Nlp.ResetMatcher', 1015 | index=7, 1016 | containing_service=None, 1017 | input_type=_TEXTREQUEST, 1018 | output_type=_TEXTRESPONSE, 1019 | serialized_options=None, 1020 | ), 1021 | ]) 1022 | _sym_db.RegisterServiceDescriptor(_NLP) 1023 | 1024 | DESCRIPTOR.services_by_name['Nlp'] = _NLP 1025 | 1026 | # @@protoc_insertion_point(module_scope) 1027 | -------------------------------------------------------------------------------- /api/python_stubs/nlp_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | import python_stubs.nlp_pb2 as nlp__pb2 5 | 6 | 7 | class NlpStub(object): 8 | """Missing associated documentation comment in .proto file""" 9 | 10 | def __init__(self, channel): 11 | """Constructor. 12 | 13 | Args: 14 | channel: A grpc.Channel. 15 | """ 16 | self.LoadModel = channel.unary_unary( 17 | '/nlp.Nlp/LoadModel', 18 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 19 | response_deserializer=nlp__pb2.TextResponse.FromString, 20 | ) 21 | self.NlpProcess = channel.unary_unary( 22 | '/nlp.Nlp/NlpProcess', 23 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 24 | response_deserializer=nlp__pb2.ParsedNLPRes.FromString, 25 | ) 26 | self.DocSimilarity = channel.unary_unary( 27 | '/nlp.Nlp/DocSimilarity', 28 | request_serializer=nlp__pb2.TextSimilarityRequest.SerializeToString, 29 | response_deserializer=nlp__pb2.TextSimilarity.FromString, 30 | ) 31 | self.AddRule = channel.unary_unary( 32 | '/nlp.Nlp/AddRule', 33 | request_serializer=nlp__pb2.Rule.SerializeToString, 34 | response_deserializer=nlp__pb2.TextResponse.FromString, 35 | ) 36 | self.RemoveRule = channel.unary_unary( 37 | '/nlp.Nlp/RemoveRule', 38 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 39 | response_deserializer=nlp__pb2.TextResponse.FromString, 40 | ) 41 | self.GetRule = channel.unary_unary( 42 | '/nlp.Nlp/GetRule', 43 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 44 | response_deserializer=nlp__pb2.Rule.FromString, 45 | ) 46 | self.GetMatches = channel.unary_unary( 47 | '/nlp.Nlp/GetMatches', 48 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 49 | response_deserializer=nlp__pb2.Matches.FromString, 50 | ) 51 | self.ResetMatcher = channel.unary_unary( 52 | '/nlp.Nlp/ResetMatcher', 53 | request_serializer=nlp__pb2.TextRequest.SerializeToString, 54 | response_deserializer=nlp__pb2.TextResponse.FromString, 55 | ) 56 | 57 | 58 | class NlpServicer(object): 59 | """Missing associated documentation comment in .proto file""" 60 | 61 | def LoadModel(self, request, context): 62 | """Missing associated documentation comment in .proto file""" 63 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 64 | context.set_details('Method not implemented!') 65 | raise NotImplementedError('Method not implemented!') 66 | 67 | def NlpProcess(self, request, context): 68 | """Missing associated documentation comment in .proto file""" 69 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 70 | context.set_details('Method not implemented!') 71 | raise NotImplementedError('Method not implemented!') 72 | 73 | def DocSimilarity(self, request, context): 74 | """Missing associated documentation comment in .proto file""" 75 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 76 | context.set_details('Method not implemented!') 77 | raise NotImplementedError('Method not implemented!') 78 | 79 | def AddRule(self, request, context): 80 | """Missing associated documentation comment in .proto file""" 81 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 82 | context.set_details('Method not implemented!') 83 | raise NotImplementedError('Method not implemented!') 84 | 85 | def RemoveRule(self, request, context): 86 | """Missing associated documentation comment in .proto file""" 87 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 88 | context.set_details('Method not implemented!') 89 | raise NotImplementedError('Method not implemented!') 90 | 91 | def GetRule(self, request, context): 92 | """Missing associated documentation comment in .proto file""" 93 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 94 | context.set_details('Method not implemented!') 95 | raise NotImplementedError('Method not implemented!') 96 | 97 | def GetMatches(self, request, context): 98 | """Missing associated documentation comment in .proto file""" 99 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 100 | context.set_details('Method not implemented!') 101 | raise NotImplementedError('Method not implemented!') 102 | 103 | def ResetMatcher(self, request, context): 104 | """Missing associated documentation comment in .proto file""" 105 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 106 | context.set_details('Method not implemented!') 107 | raise NotImplementedError('Method not implemented!') 108 | 109 | 110 | def add_NlpServicer_to_server(servicer, server): 111 | rpc_method_handlers = { 112 | 'LoadModel': grpc.unary_unary_rpc_method_handler( 113 | servicer.LoadModel, 114 | request_deserializer=nlp__pb2.TextRequest.FromString, 115 | response_serializer=nlp__pb2.TextResponse.SerializeToString, 116 | ), 117 | 'NlpProcess': grpc.unary_unary_rpc_method_handler( 118 | servicer.NlpProcess, 119 | request_deserializer=nlp__pb2.TextRequest.FromString, 120 | response_serializer=nlp__pb2.ParsedNLPRes.SerializeToString, 121 | ), 122 | 'DocSimilarity': grpc.unary_unary_rpc_method_handler( 123 | servicer.DocSimilarity, 124 | request_deserializer=nlp__pb2.TextSimilarityRequest.FromString, 125 | response_serializer=nlp__pb2.TextSimilarity.SerializeToString, 126 | ), 127 | 'AddRule': grpc.unary_unary_rpc_method_handler( 128 | servicer.AddRule, 129 | request_deserializer=nlp__pb2.Rule.FromString, 130 | response_serializer=nlp__pb2.TextResponse.SerializeToString, 131 | ), 132 | 'RemoveRule': grpc.unary_unary_rpc_method_handler( 133 | servicer.RemoveRule, 134 | request_deserializer=nlp__pb2.TextRequest.FromString, 135 | response_serializer=nlp__pb2.TextResponse.SerializeToString, 136 | ), 137 | 'GetRule': grpc.unary_unary_rpc_method_handler( 138 | servicer.GetRule, 139 | request_deserializer=nlp__pb2.TextRequest.FromString, 140 | response_serializer=nlp__pb2.Rule.SerializeToString, 141 | ), 142 | 'GetMatches': grpc.unary_unary_rpc_method_handler( 143 | servicer.GetMatches, 144 | request_deserializer=nlp__pb2.TextRequest.FromString, 145 | response_serializer=nlp__pb2.Matches.SerializeToString, 146 | ), 147 | 'ResetMatcher': grpc.unary_unary_rpc_method_handler( 148 | servicer.ResetMatcher, 149 | request_deserializer=nlp__pb2.TextRequest.FromString, 150 | response_serializer=nlp__pb2.TextResponse.SerializeToString, 151 | ), 152 | } 153 | generic_handler = grpc.method_handlers_generic_handler( 154 | 'nlp.Nlp', rpc_method_handlers) 155 | server.add_generic_rpc_handlers((generic_handler,)) 156 | 157 | 158 | # This class is part of an EXPERIMENTAL API. 159 | class Nlp(object): 160 | """Missing associated documentation comment in .proto file""" 161 | 162 | @staticmethod 163 | def LoadModel(request, 164 | target, 165 | options=(), 166 | channel_credentials=None, 167 | call_credentials=None, 168 | compression=None, 169 | wait_for_ready=None, 170 | timeout=None, 171 | metadata=None): 172 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/LoadModel', 173 | nlp__pb2.TextRequest.SerializeToString, 174 | nlp__pb2.TextResponse.FromString, 175 | options, channel_credentials, 176 | call_credentials, compression, wait_for_ready, timeout, metadata) 177 | 178 | @staticmethod 179 | def NlpProcess(request, 180 | target, 181 | options=(), 182 | channel_credentials=None, 183 | call_credentials=None, 184 | compression=None, 185 | wait_for_ready=None, 186 | timeout=None, 187 | metadata=None): 188 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/NlpProcess', 189 | nlp__pb2.TextRequest.SerializeToString, 190 | nlp__pb2.ParsedNLPRes.FromString, 191 | options, channel_credentials, 192 | call_credentials, compression, wait_for_ready, timeout, metadata) 193 | 194 | @staticmethod 195 | def DocSimilarity(request, 196 | target, 197 | options=(), 198 | channel_credentials=None, 199 | call_credentials=None, 200 | compression=None, 201 | wait_for_ready=None, 202 | timeout=None, 203 | metadata=None): 204 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/DocSimilarity', 205 | nlp__pb2.TextSimilarityRequest.SerializeToString, 206 | nlp__pb2.TextSimilarity.FromString, 207 | options, channel_credentials, 208 | call_credentials, compression, wait_for_ready, timeout, metadata) 209 | 210 | @staticmethod 211 | def AddRule(request, 212 | target, 213 | options=(), 214 | channel_credentials=None, 215 | call_credentials=None, 216 | compression=None, 217 | wait_for_ready=None, 218 | timeout=None, 219 | metadata=None): 220 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/AddRule', 221 | nlp__pb2.Rule.SerializeToString, 222 | nlp__pb2.TextResponse.FromString, 223 | options, channel_credentials, 224 | call_credentials, compression, wait_for_ready, timeout, metadata) 225 | 226 | @staticmethod 227 | def RemoveRule(request, 228 | target, 229 | options=(), 230 | channel_credentials=None, 231 | call_credentials=None, 232 | compression=None, 233 | wait_for_ready=None, 234 | timeout=None, 235 | metadata=None): 236 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/RemoveRule', 237 | nlp__pb2.TextRequest.SerializeToString, 238 | nlp__pb2.TextResponse.FromString, 239 | options, channel_credentials, 240 | call_credentials, compression, wait_for_ready, timeout, metadata) 241 | 242 | @staticmethod 243 | def GetRule(request, 244 | target, 245 | options=(), 246 | channel_credentials=None, 247 | call_credentials=None, 248 | compression=None, 249 | wait_for_ready=None, 250 | timeout=None, 251 | metadata=None): 252 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/GetRule', 253 | nlp__pb2.TextRequest.SerializeToString, 254 | nlp__pb2.Rule.FromString, 255 | options, channel_credentials, 256 | call_credentials, compression, wait_for_ready, timeout, metadata) 257 | 258 | @staticmethod 259 | def GetMatches(request, 260 | target, 261 | options=(), 262 | channel_credentials=None, 263 | call_credentials=None, 264 | compression=None, 265 | wait_for_ready=None, 266 | timeout=None, 267 | metadata=None): 268 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/GetMatches', 269 | nlp__pb2.TextRequest.SerializeToString, 270 | nlp__pb2.Matches.FromString, 271 | options, channel_credentials, 272 | call_credentials, compression, wait_for_ready, timeout, metadata) 273 | 274 | @staticmethod 275 | def ResetMatcher(request, 276 | target, 277 | options=(), 278 | channel_credentials=None, 279 | call_credentials=None, 280 | compression=None, 281 | wait_for_ready=None, 282 | timeout=None, 283 | metadata=None): 284 | return grpc.experimental.unary_unary(request, target, '/nlp.Nlp/ResetMatcher', 285 | nlp__pb2.TextRequest.SerializeToString, 286 | nlp__pb2.TextResponse.FromString, 287 | options, channel_credentials, 288 | call_credentials, compression, wait_for_ready, timeout, metadata) 289 | -------------------------------------------------------------------------------- /api/server.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import grpc 4 | import time 5 | import spacy 6 | import utils 7 | from python_stubs import nlp_pb2 8 | from python_stubs import nlp_pb2_grpc 9 | 10 | from spacy.matcher import Matcher 11 | 12 | from concurrent import futures 13 | 14 | 15 | class NlpService(nlp_pb2_grpc.NlpServicer): 16 | def __init__(self): 17 | self.modelName = None 18 | self.nlp = None 19 | self.matcher = None 20 | 21 | def LoadModel(self, request, context): 22 | self.modelName = request.text 23 | self.nlp = spacy.load(request.text) 24 | response = nlp_pb2.TextResponse() 25 | response.message = "Model loaded '{}'".format(request.text) 26 | return response 27 | 28 | def NlpProcess(self, request, context): 29 | doc = self.nlp(request.text) 30 | response = utils.doc2proto(doc, self.modelName) 31 | return response 32 | 33 | def DocSimilarity(self, request, context): 34 | docA = self.nlp(request.texta) 35 | docB = self.nlp(request.textb) 36 | response = nlp_pb2.TextSimilarity() 37 | response.similarity = docA.similarity(docB) 38 | return response 39 | 40 | def AddRule(self, request, context): 41 | if self.matcher == None: 42 | self.matcher = Matcher(self.nlp.vocab) 43 | matcher_id = request.id 44 | patterns = [{pat.key: pat.value} for pat in request.patterns] 45 | self.matcher.add(matcher_id, None, patterns) 46 | response = nlp_pb2.TextResponse() 47 | response.message = "Rule with id '{}' added to matcher.".format(matcher_id) 48 | return response 49 | 50 | def RemoveRule(self, request, context): 51 | if self.matcher == None: 52 | return nlp_pb2.TextResponse(message="No rules exists with matcher") 53 | self.matcher.remove(request.text) 54 | return nlp_pb2.TextResponse( 55 | message="Rule with id '{}' removed from matcher.".format(request.text) 56 | ) 57 | 58 | def GetRule(self, request, context): 59 | if self.matcher == None: 60 | return nlp_pb2.TextResponse(message="No rules exists with matcher") 61 | _, patterns = self.matcher.get(request.text) 62 | return nlp_pb2.Rule( 63 | id=request.text, 64 | patterns=[ 65 | nlp_pb2.Pattern(key=list(pat.keys())[0], value=list(pat.values())[0]) 66 | for pat in patterns[0] 67 | ], 68 | ) 69 | 70 | def GetMatches(self, request, context): 71 | doc = self.nlp(request.text) 72 | matches = self.matcher(doc) 73 | reponse = nlp_pb2.Matches( 74 | matches=[nlp_pb2.Match(id=str(i[0]), start=i[1], end=i[2]) for i in matches] 75 | ) 76 | return reponse 77 | 78 | def ResetMatcher(self, request, context): 79 | self.matcher = None 80 | return nlp_pb2.TextResponse(message="Matcher object reset successful.") 81 | 82 | 83 | def serve(server_address): 84 | 85 | private_key_path = os.path.join( 86 | os.environ["GOPATH"], "src/github.com/yash1994/spacy-go/server.key" 87 | ) 88 | certificate_chain_path = os.path.join( 89 | os.environ["GOPATH"], "src/github.com/yash1994/spacy-go/server.crt" 90 | ) 91 | 92 | if not os.path.exists(private_key_path): 93 | private_key_path = "server.key" 94 | 95 | if not os.path.exists(certificate_chain_path): 96 | certificate_chain_path = "server.crt" 97 | 98 | with open(private_key_path, "rb") as f: 99 | private_key = f.read() 100 | with open(certificate_chain_path, "rb") as f: 101 | certificate_chain = f.read() 102 | 103 | server_credentials = grpc.ssl_server_credentials( 104 | ((private_key, certificate_chain,),) 105 | ) 106 | 107 | server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) 108 | nlp_pb2_grpc.add_NlpServicer_to_server(NlpService(), server) 109 | server.add_secure_port(server_address, server_credentials) 110 | server.start() 111 | try: 112 | while True: 113 | time.sleep(10000) 114 | except KeyboardInterrupt: 115 | server.stop(0) 116 | 117 | 118 | if __name__ == "__main__": 119 | 120 | if len(sys.argv) != 2: 121 | server_address = "localhost:50051" 122 | print("Default Server Address: {}".format(server_address)) 123 | else: 124 | server_address = sys.argv[1] 125 | print("Custom Server Address: {}".format(server_address)) 126 | 127 | serve(server_address) 128 | -------------------------------------------------------------------------------- /api/server_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from python_stubs.nlp_pb2 import TextRequest, TextSimilarityRequest, Rule, Pattern 4 | 5 | 6 | @pytest.fixture(scope="module") 7 | def grpc_add_to_server(): 8 | from python_stubs.nlp_pb2_grpc import add_NlpServicer_to_server 9 | 10 | return add_NlpServicer_to_server 11 | 12 | 13 | @pytest.fixture(scope="module") 14 | def grpc_servicer(): 15 | from server import NlpService 16 | 17 | return NlpService() 18 | 19 | 20 | @pytest.fixture(scope="module") 21 | def grpc_stub_cls(grpc_channel): 22 | from python_stubs.nlp_pb2_grpc import NlpStub 23 | 24 | return NlpStub(grpc_channel) 25 | 26 | 27 | def test_load_model(grpc_stub_cls): 28 | request = TextRequest() 29 | request.text = "en_core_web_sm" 30 | response = grpc_stub_cls.LoadModel(request) 31 | 32 | assert response.message == "Model loaded 'en_core_web_sm'" 33 | 34 | 35 | def test_nlp_process(grpc_stub_cls): 36 | request = TextRequest() 37 | request.text = "This is a text." 38 | response = grpc_stub_cls.NlpProcess(request) 39 | assert response.doc.text == "This is a text." 40 | assert response.tokens[0].pos == "DET" 41 | assert response.tokens[0].dep == "nsubj" 42 | assert response.tokens[3].pos == "NOUN" 43 | assert response.tokens[3].is_alpha == True 44 | 45 | 46 | def test_doc_similarity(grpc_stub_cls): 47 | request = TextSimilarityRequest() 48 | request.texta = "I like apples" 49 | request.textb = "I like oranges" 50 | response = grpc_stub_cls.DocSimilarity(request) 51 | assert pytest.approx(response.similarity, 0.2) == 0.90 52 | 53 | 54 | def test_add_matcher(grpc_stub_cls): 55 | patterns = [{"LOWER": "hello"}, {"LOWER": "world"}] 56 | rule_id = "HelloWorld" 57 | request = Rule( 58 | id=rule_id, 59 | patterns=[ 60 | Pattern(key=list(pat.keys())[0], value=list(pat.values())[0]) 61 | for pat in patterns 62 | ], 63 | ) 64 | response = grpc_stub_cls.AddRule(request) 65 | assert response.message == "Rule with id '{}' added to matcher.".format(rule_id) 66 | 67 | 68 | def test_remove_matcher(grpc_stub_cls): 69 | request = TextRequest(text="HelloWorld") 70 | response = grpc_stub_cls.RemoveRule(request) 71 | assert response.message == "Rule with id 'HelloWorld' removed from matcher." 72 | 73 | 74 | def test_get_matcher(grpc_stub_cls): 75 | patterns = [{"LOWER": "hello"}, {"LOWER": "world"}] 76 | rule_id = "HelloWorld" 77 | request = Rule( 78 | id=rule_id, 79 | patterns=[ 80 | Pattern(key=list(pat.keys())[0], value=list(pat.values())[0]) 81 | for pat in patterns 82 | ], 83 | ) 84 | 85 | _ = grpc_stub_cls.AddRule(request) 86 | 87 | response = grpc_stub_cls.GetRule(TextRequest(text=rule_id)) 88 | 89 | assert request.SerializeToString() == response.SerializeToString() 90 | 91 | 92 | def test_get_matches(grpc_stub_cls): 93 | patterns = [{"ORTH": "Google"}, {"ORTH": "Maps"}] 94 | rule_id = "GoogleMaps" 95 | request = Rule( 96 | id=rule_id, 97 | patterns=[ 98 | Pattern(key=list(pat.keys())[0], value=list(pat.values())[0]) 99 | for pat in patterns 100 | ], 101 | ) 102 | 103 | _ = grpc_stub_cls.AddRule(request) 104 | 105 | response = grpc_stub_cls.GetMatches(TextRequest(text="HELLO WORLD on Google Maps.")) 106 | 107 | assert response.matches[0].start == 0 108 | assert response.matches[0].end == 2 109 | assert response.matches[1].start == 3 110 | assert response.matches[1].end == 5 111 | 112 | 113 | def test_reset_matcher(grpc_stub_cls): 114 | request = TextRequest(text="") 115 | response = grpc_stub_cls.ResetMatcher(request) 116 | 117 | assert response.message == "Matcher object reset successful." -------------------------------------------------------------------------------- /api/utils.py: -------------------------------------------------------------------------------- 1 | from python_stubs import nlp_pb2 2 | 3 | def doc2proto(doc, model): 4 | proto = nlp_pb2.ParsedNLPRes() 5 | proto.model = model 6 | 7 | protoDoc = nlp_pb2.Doc() 8 | protoDoc.text = doc.text 9 | protoDoc.text_with_ws = doc.text_with_ws 10 | protoDoc.is_tagged = doc.is_tagged 11 | protoDoc.is_parsed = doc.is_parsed 12 | protoDoc.is_nered = doc.is_nered 13 | protoDoc.is_sentenced = doc.is_sentenced 14 | 15 | if doc.ents: 16 | protoEnts = [] 17 | for ent in doc.ents: 18 | protoEnt = nlp_pb2.Ent() 19 | protoEnt.start = ent.start 20 | protoEnt.end = ent.end 21 | protoEnt.label = ent.label_ 22 | protoEnts.append(protoEnt) 23 | else: 24 | protoEnts = [] 25 | 26 | if doc.is_sentenced: 27 | protoSents = [] 28 | for sent in doc.sents: 29 | protoSent = nlp_pb2.Sent() 30 | protoSent.start = sent.start 31 | protoSent.end = sent.end 32 | protoSents.append(protoSent) 33 | else: 34 | protoSents = [] 35 | 36 | if doc.is_tagged and doc.is_parsed: 37 | protoNounChunks = [] 38 | for chunk in doc.noun_chunks: 39 | protoNounChunk = nlp_pb2.Noun_chunk() 40 | protoNounChunk.start = chunk.start 41 | protoNounChunk.end = chunk.end 42 | protoNounChunks.append(protoNounChunk) 43 | else: 44 | protoNounChunks = [] 45 | 46 | protoTokens = [] 47 | for token in doc: 48 | protoToken = nlp_pb2.Token() 49 | protoToken.text = token.text 50 | protoToken.text_with_ws = token.text_with_ws 51 | protoToken.whitespace = token.whitespace_ 52 | protoToken.ent_type = token.ent_type_ 53 | protoToken.ent_iob = token.ent_iob_ 54 | protoToken.lemma = token.lemma_ 55 | protoToken.norm = token.norm_ 56 | protoToken.lower = token.lower_ 57 | protoToken.shape = token.shape_ 58 | protoToken.prefix = token.prefix_ 59 | protoToken.suffix = token.suffix_ 60 | protoToken.pos = token.pos_ 61 | protoToken.tag = token.tag_ 62 | protoToken.dep = token.dep_ 63 | protoToken.is_alpha = token.is_alpha 64 | protoToken.is_ascii = token.is_ascii 65 | protoToken.is_digit = token.is_digit 66 | protoToken.is_lower = token.is_lower 67 | protoToken.is_upper = token.is_upper 68 | protoToken.is_title = token.is_title 69 | protoToken.is_punct = token.is_punct 70 | protoToken.is_left_punct = token.is_left_punct 71 | protoToken.is_right_punct = token.is_right_punct 72 | protoToken.is_space = token.is_space 73 | protoToken.is_bracket = token.is_bracket 74 | protoToken.is_currency = token.is_currency 75 | protoToken.like_url = token.like_url 76 | protoToken.like_num = token.like_num 77 | protoToken.like_email = token.like_email 78 | protoToken.is_oov = token.is_oov 79 | protoToken.is_stop = token.is_stop 80 | protoToken.is_sent_start = token.is_sent_start if token.is_sent_start is not None else False 81 | protoToken.head = token.head.i 82 | protoTokens.append(protoToken) 83 | 84 | proto.doc.MergeFrom(protoDoc) 85 | proto.ents.MergeFrom(protoEnts) 86 | proto.sents.MergeFrom(protoSents) 87 | proto.noun_chunks.MergeFrom(protoNounChunks) 88 | proto.tokens.MergeFrom(protoTokens) 89 | 90 | return proto -------------------------------------------------------------------------------- /docs/parsedNlpRes.md: -------------------------------------------------------------------------------- 1 | # ParsedNLPRes 2 | 3 | ParsedNLPRes is type of `struct` returned when `Nlp` method is called. 4 | 5 | ## Attributes and Access Methods 6 | 7 | | Name | Type | Access Method | Return Type | Description | 8 | | ---- | -----| ------------- | ----------- | ----------- | 9 | | `Model` | `string` | `GetModel()` | `string` | Contains name of loaded language model. | 10 | | `Doc` | `Doc` | `GetDoc()` | [`Doc`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#doc) | Contains `Doc` of type `struct`. | 11 | | `Ents` | `Array` | `GetEnts()` | `Array` of [`Ent`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#ent) | Contains `Array` of type [`Ent`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#ent) (list of entities from nered text). | 12 | | `Sents` | `Array` | `GetSents()` | `Array` of [`Sent`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#sent) | Contains `Array` of type [`Sent`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#sent) (list of sentences from processed text). | 13 | | `NounChunks` | `Array` | `GetNounChunks()` | `Array` of [`NounChunk`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#nounchunk) | Contains `Array` of type [`NounChunk`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#nounchunk) ((list of Noun Chunks from processed text)). | 14 | | `Tokens` | `Array` | `GetTokens()` | `Array` of [`Token`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#token) | Contains `Array` of type [`Token`](https://github.com/yash1994/spacy-go/blob/master/docs/parsedNlpRes.md#token) (list of tokens from processed text). | 15 | 16 | # Doc 17 | 18 | Doc is type of `struct` returned when `GetModel()` method is called on `ParsedNLPRes`. 19 | 20 | ## Attributes and Access Methods 21 | 22 | | Name | Type | Access Method | Return Type | Description | 23 | | ---- | -----| ------------- | ----------- | ----------- | 24 | | `Text` | `string` | `GetText()` | `string` | A unicode representation of the document text. | 25 | | `TextWithWs` | `string` | `GetTextWithWs()` | `string` | An alias of Doc.Text, provided for duck-type compatibility with Span and Token. | 26 | | `IsTagged` | `bool` | `GetIsTagged()` | `bool` | A flag indicating that the document has been part-of-speech tagged. Returns True if the Doc is empty. | 27 | | `IsParsed` | `bool` | `GetIsParsed()` | `bool` | A flag indicating that the document has been part-of-speech tagged. Returns True if the Doc is empty.A flag indicating that the document has been syntactically parsed. Returns True if the Doc is empty. | 28 | | `IsNered` | `bool` | `GetIsNered()` | `bool` | A flag indicating that named entities have been set. Will return True if the Doc is empty, or if any of the tokens has an entity tag set, even if the others are unknown. | 29 | | `IsSentenced` | `bool` | `GetIsSentenced()` | `bool` | A flag indicating that sentence boundaries have been applied to the document. Returns True if the Doc is empty. | 30 | 31 | # Ent 32 | 33 | Ent is type of `struct` returned as array element when `GetEnts()` method is called on `ParsedNLPRes`. 34 | 35 | ## Attributes and Access Methods 36 | 37 | | Name | Type | Access Method | Return Type | Description | 38 | | ---- | -----| ------------- | ----------- | ----------- | 39 | | `Start` | `int32` | `GetStart()` | `int32` | Starting index of entity in processed text. | 40 | | `End` | `int32` | `GetEnd()` | `int32` | Ending index of entity in processed text. | 41 | | `Label` | `string` | `GetLabel()` | `string` | Entity label. | 42 | 43 | # Sent 44 | 45 | Sent is type of `struct` returned as array element when `GetSents()` method is called on `ParsedNLPRes`. 46 | 47 | ## Attributes and Access Methods 48 | 49 | | Name | Type | Access Method | Return Type | Description | 50 | | ---- | -----| ------------- | ----------- | ----------- | 51 | | `Start` | `int32` | `GetStart()` | `int32` | Starting index of sentence in processed text. | 52 | | `End` | `int32` | `GetEnd()` | `int32` | Ending index of sentence in processed text. | 53 | 54 | # NounChunk 55 | 56 | NounChunk is type of `struct` returned as array element when `GetNounChunks()` method is called on `ParsedNLPRes`. 57 | 58 | ## Attributes and Access Methods 59 | 60 | | Name | Type | Access Method | Return Type | Description | 61 | | ---- | -----| ------------- | ----------- | ----------- | 62 | | `Start` | `int32` | `GetStart()` | `int32` | Starting index of Noun Chunk in processed text. | 63 | | `End` | `int32` | `GetEnd()` | `int32` | Ending index of Noun Chunk in processed text. | 64 | 65 | # Token 66 | 67 | Token is type of `struct` returned as array element when `GetTokens()` method is called on `ParsedNLPRes`. 68 | 69 | ## Attributes and Access Methods 70 | 71 | | Name | Type | Access Method | Return Type | Description | 72 | | ---- | -----| ------------- | ----------- | ----------- | 73 | | `Text` | `string` | `GetText()` | `string` | Verbatim text content. | 74 | | `TextWithWs` | `string` | `GetTextWithWs()` | `string` | Text content, with trailing space character if present. | 75 | | `Whitespace` | `string` | `GetWhitespace()` | `string` | Trailing space character if present. | 76 | | `EntType` | `string` | `GetEntType()` | `string` | Named entity type. | 77 | | `EntIob` | `string` | `GetEntIob()` | `string` | Named entity type. | 78 | | `Lemma` | `string` | `GetLemma()` | `string` | Base form of the token, with no inflectional suffixes. | 79 | | `Norm` | `string` | `GetNorm()` | `string` | The token’s norm, i.e. a normalized form of the token text. | 80 | | `Lower` | `string` | `GetLower()` | `string` | Lowercase form of the token. | 81 | | `Shape` | `string` | `GetShape()` | `string` | Transform of the tokens’s string, to show orthographic features. Alphabetic characters are replaced by x or X, and numeric characters are replaced by d, and sequences of the same character are truncated after length 4. For example,"Xxxx"or"dd". | 82 | | `Prefix` | `string` | `GetPrefix()` | `string` | A length-N substring from the start of the token. | 83 | | `Suffix` | `string` | `GetSuffix()` | `string` | Hash value of a length-N substring from the end of the token. | 84 | | `Pos` | `string` | `GetPos()` | `string` | Coarse-grained part-of-speech from the Universal POS tag set. | 85 | | `Tag` | `string` | `GetTag()` | `string` | Fine-grained part-of-speech. | 86 | | `Dep` | `string` | `GetDep()` | `string` | Syntactic dependency relation. | 87 | | `IsAlpha` | `bool` | `GetIsAlpha()` | `bool` | Does the token consist of alphabetic characters? | 88 | | `IsAscii` | `bool` | `GetIsAscii()` | `bool` | Does the token consist of ASCII characters? | 89 | | `IsDigit` | `bool` | `GetIsDigit()` | `bool` | Does the token consist of digits? | 90 | | `IsLower` | `bool` | `GetIsLower()` | `bool` | Is the token in lowercase? | 91 | | `IsUpper` | `bool` | `GetIsUpper()` | `bool` | Is the token in uppercase? | 92 | | `IsTitle` | `bool` | `GetIsTitle()` | `bool` | Is the token in titlecase? | 93 | | `IsPunct` | `bool` | `GetIsPunct()` | `bool` | Is the token punctuation? | 94 | | `IsLeftPunct` | `bool` | `GetIsLeftPunct()` | `bool` | Is the token a left punctuation mark, e.g. '(' ? | 95 | | `IsRightPunct` | `bool` | `GetIsRightPunct()` | `bool` | Is the token a right punctuation mark, e.g. ')' ? | 96 | | `IsSpace` | `bool` | `GetIsSpace()` | `bool` | Does the token consist of whitespace characters? | 97 | | `IsBracket` | `bool` | `GetIsBracket()` | `bool` | Is the token a bracket? | 98 | | `IsCurrency` | `bool` | `GetIsCurrency()` | `bool` | Is the token a currency symbol? | 99 | | `LikeUrl` | `bool` | `GetLikeUrl()` | `bool` | Does the token resemble a URL? | 100 | | `LikeNum` | `bool` | `GetLikeNum()` | `bool` | Does the token represent a number? e.g. “10.9”, “10”, “ten”, etc. | 101 | | `LikeEmail` | `bool` | `GetLikeEmail()` | `bool` | Does the token resemble an email address? | 102 | | `IsOov` | `bool` | `GetIsOov()` | `bool` | Does the token have a word vector? | 103 | | `IsStop` | `bool` | `GetIsStop()` | `bool` | Is the token part of a “stop list”? | 104 | | `IsSentStart` | `bool` | `GetIsSentStart()` | `bool` | A boolean value indicating whether the token starts a sentence. | 105 | | `Head` | `int32` | `GetHead()` | `int32` | The syntactic parent, or “governor”, of this token. | 106 | -------------------------------------------------------------------------------- /docs/patternMatches.md: -------------------------------------------------------------------------------- 1 | # PatternMatches 2 | 3 | Matches is type of `struct` returned when `PatternMatch` method is called. 4 | 5 | ## Attributes and Access Methods 6 | 7 | | Name | Type | Access Method | Return Type | Description | 8 | | ---- | -----| ------------- | ----------- | ----------- | 9 | | `Matches` | `Array` | `GetMatches()` | `Array` of [`Match`](https://github.com/yash1994/spacy-go/blob/master/docs/patternMatches.md#match) | Contains `Array` of type [`Match`](https://github.com/yash1994/spacy-go/blob/master/docs/patternMatches.md#match) (list of matched tokens). | 10 | 11 | # Match 12 | 13 | Match is type of `struct` returned as array element when `GetMatches()` method is called on `Matches`. 14 | 15 | ## Attributes and Access Methods 16 | 17 | | Name | Type | Access Method | Return Type | Description | 18 | | ---- | -----| ------------- | ----------- | ----------- | 19 | | `Start` | `int32` | `GetStart()` | `int32` | Starting index of matched token in processed text. | 20 | | `End` | `int32` | `GetEnd()` | `int32` | Ending index of matched token in processed text. | 21 | | `Id` | `string` | `GetId()` | `string` | Unique match id for matched pattern in text. | -------------------------------------------------------------------------------- /docs/textResponse.md: -------------------------------------------------------------------------------- 1 | # TextResponse 2 | 3 | TextResponse is type of `struct` returned when `Load` method is called. 4 | 5 | ## Attributes and Access Methods 6 | 7 | | Name | Type | Access Method | Return Type | Description | 8 | | ---- | -----| ------------- | ----------- | ----------- | 9 | | `message` | `string` | `GetMessage()` | `string` | Holds message from gRPC NLP server for model getting loaded i.e. "Model loaded 'en_core_web_sm'" | -------------------------------------------------------------------------------- /docs/textSimilarity.md: -------------------------------------------------------------------------------- 1 | # TextSimilarity 2 | 3 | TextSimilarity is type of `struct` returned when `Similarity` method is called. 4 | 5 | ## Attributes and Access Methods 6 | 7 | | Name | Type | Access Method | Return Type | Description | 8 | | ---- | -----| ------------- | ----------- | ----------- | 9 | | `Similarity` | `float64` | `GetSimilarity()` | `float64` | Semantic similarity float value. | -------------------------------------------------------------------------------- /go-stubs/nlp.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.23.0-devel 4 | // protoc v3.12.0 5 | // source: nlp.proto 6 | 7 | package nlp 8 | 9 | import ( 10 | context "context" 11 | proto "github.com/golang/protobuf/proto" 12 | grpc "google.golang.org/grpc" 13 | codes "google.golang.org/grpc/codes" 14 | status "google.golang.org/grpc/status" 15 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 16 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 17 | reflect "reflect" 18 | sync "sync" 19 | ) 20 | 21 | const ( 22 | // Verify that this generated code is sufficiently up-to-date. 23 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 24 | // Verify that runtime/protoimpl is sufficiently up-to-date. 25 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 26 | ) 27 | 28 | // This is a compile-time assertion that a sufficiently up-to-date version 29 | // of the legacy proto package is being used. 30 | const _ = proto.ProtoPackageIsVersion4 31 | 32 | type TextRequest struct { 33 | state protoimpl.MessageState 34 | sizeCache protoimpl.SizeCache 35 | unknownFields protoimpl.UnknownFields 36 | 37 | Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` 38 | } 39 | 40 | func (x *TextRequest) Reset() { 41 | *x = TextRequest{} 42 | if protoimpl.UnsafeEnabled { 43 | mi := &file_nlp_proto_msgTypes[0] 44 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 45 | ms.StoreMessageInfo(mi) 46 | } 47 | } 48 | 49 | func (x *TextRequest) String() string { 50 | return protoimpl.X.MessageStringOf(x) 51 | } 52 | 53 | func (*TextRequest) ProtoMessage() {} 54 | 55 | func (x *TextRequest) ProtoReflect() protoreflect.Message { 56 | mi := &file_nlp_proto_msgTypes[0] 57 | if protoimpl.UnsafeEnabled && x != nil { 58 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 59 | if ms.LoadMessageInfo() == nil { 60 | ms.StoreMessageInfo(mi) 61 | } 62 | return ms 63 | } 64 | return mi.MessageOf(x) 65 | } 66 | 67 | // Deprecated: Use TextRequest.ProtoReflect.Descriptor instead. 68 | func (*TextRequest) Descriptor() ([]byte, []int) { 69 | return file_nlp_proto_rawDescGZIP(), []int{0} 70 | } 71 | 72 | func (x *TextRequest) GetText() string { 73 | if x != nil { 74 | return x.Text 75 | } 76 | return "" 77 | } 78 | 79 | type TextSimilarityRequest struct { 80 | state protoimpl.MessageState 81 | sizeCache protoimpl.SizeCache 82 | unknownFields protoimpl.UnknownFields 83 | 84 | Texta string `protobuf:"bytes,1,opt,name=texta,proto3" json:"texta,omitempty"` 85 | Textb string `protobuf:"bytes,2,opt,name=textb,proto3" json:"textb,omitempty"` 86 | } 87 | 88 | func (x *TextSimilarityRequest) Reset() { 89 | *x = TextSimilarityRequest{} 90 | if protoimpl.UnsafeEnabled { 91 | mi := &file_nlp_proto_msgTypes[1] 92 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 93 | ms.StoreMessageInfo(mi) 94 | } 95 | } 96 | 97 | func (x *TextSimilarityRequest) String() string { 98 | return protoimpl.X.MessageStringOf(x) 99 | } 100 | 101 | func (*TextSimilarityRequest) ProtoMessage() {} 102 | 103 | func (x *TextSimilarityRequest) ProtoReflect() protoreflect.Message { 104 | mi := &file_nlp_proto_msgTypes[1] 105 | if protoimpl.UnsafeEnabled && x != nil { 106 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 107 | if ms.LoadMessageInfo() == nil { 108 | ms.StoreMessageInfo(mi) 109 | } 110 | return ms 111 | } 112 | return mi.MessageOf(x) 113 | } 114 | 115 | // Deprecated: Use TextSimilarityRequest.ProtoReflect.Descriptor instead. 116 | func (*TextSimilarityRequest) Descriptor() ([]byte, []int) { 117 | return file_nlp_proto_rawDescGZIP(), []int{1} 118 | } 119 | 120 | func (x *TextSimilarityRequest) GetTexta() string { 121 | if x != nil { 122 | return x.Texta 123 | } 124 | return "" 125 | } 126 | 127 | func (x *TextSimilarityRequest) GetTextb() string { 128 | if x != nil { 129 | return x.Textb 130 | } 131 | return "" 132 | } 133 | 134 | type TextResponse struct { 135 | state protoimpl.MessageState 136 | sizeCache protoimpl.SizeCache 137 | unknownFields protoimpl.UnknownFields 138 | 139 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` 140 | } 141 | 142 | func (x *TextResponse) Reset() { 143 | *x = TextResponse{} 144 | if protoimpl.UnsafeEnabled { 145 | mi := &file_nlp_proto_msgTypes[2] 146 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 147 | ms.StoreMessageInfo(mi) 148 | } 149 | } 150 | 151 | func (x *TextResponse) String() string { 152 | return protoimpl.X.MessageStringOf(x) 153 | } 154 | 155 | func (*TextResponse) ProtoMessage() {} 156 | 157 | func (x *TextResponse) ProtoReflect() protoreflect.Message { 158 | mi := &file_nlp_proto_msgTypes[2] 159 | if protoimpl.UnsafeEnabled && x != nil { 160 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 161 | if ms.LoadMessageInfo() == nil { 162 | ms.StoreMessageInfo(mi) 163 | } 164 | return ms 165 | } 166 | return mi.MessageOf(x) 167 | } 168 | 169 | // Deprecated: Use TextResponse.ProtoReflect.Descriptor instead. 170 | func (*TextResponse) Descriptor() ([]byte, []int) { 171 | return file_nlp_proto_rawDescGZIP(), []int{2} 172 | } 173 | 174 | func (x *TextResponse) GetMessage() string { 175 | if x != nil { 176 | return x.Message 177 | } 178 | return "" 179 | } 180 | 181 | type TextSimilarity struct { 182 | state protoimpl.MessageState 183 | sizeCache protoimpl.SizeCache 184 | unknownFields protoimpl.UnknownFields 185 | 186 | Similarity float32 `protobuf:"fixed32,1,opt,name=similarity,proto3" json:"similarity,omitempty"` 187 | } 188 | 189 | func (x *TextSimilarity) Reset() { 190 | *x = TextSimilarity{} 191 | if protoimpl.UnsafeEnabled { 192 | mi := &file_nlp_proto_msgTypes[3] 193 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 194 | ms.StoreMessageInfo(mi) 195 | } 196 | } 197 | 198 | func (x *TextSimilarity) String() string { 199 | return protoimpl.X.MessageStringOf(x) 200 | } 201 | 202 | func (*TextSimilarity) ProtoMessage() {} 203 | 204 | func (x *TextSimilarity) ProtoReflect() protoreflect.Message { 205 | mi := &file_nlp_proto_msgTypes[3] 206 | if protoimpl.UnsafeEnabled && x != nil { 207 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 208 | if ms.LoadMessageInfo() == nil { 209 | ms.StoreMessageInfo(mi) 210 | } 211 | return ms 212 | } 213 | return mi.MessageOf(x) 214 | } 215 | 216 | // Deprecated: Use TextSimilarity.ProtoReflect.Descriptor instead. 217 | func (*TextSimilarity) Descriptor() ([]byte, []int) { 218 | return file_nlp_proto_rawDescGZIP(), []int{3} 219 | } 220 | 221 | func (x *TextSimilarity) GetSimilarity() float32 { 222 | if x != nil { 223 | return x.Similarity 224 | } 225 | return 0 226 | } 227 | 228 | type Doc struct { 229 | state protoimpl.MessageState 230 | sizeCache protoimpl.SizeCache 231 | unknownFields protoimpl.UnknownFields 232 | 233 | Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` 234 | TextWithWs string `protobuf:"bytes,2,opt,name=text_with_ws,json=textWithWs,proto3" json:"text_with_ws,omitempty"` 235 | IsTagged bool `protobuf:"varint,3,opt,name=is_tagged,json=isTagged,proto3" json:"is_tagged,omitempty"` 236 | IsParsed bool `protobuf:"varint,4,opt,name=is_parsed,json=isParsed,proto3" json:"is_parsed,omitempty"` 237 | IsNered bool `protobuf:"varint,5,opt,name=is_nered,json=isNered,proto3" json:"is_nered,omitempty"` 238 | IsSentenced bool `protobuf:"varint,6,opt,name=is_sentenced,json=isSentenced,proto3" json:"is_sentenced,omitempty"` 239 | } 240 | 241 | func (x *Doc) Reset() { 242 | *x = Doc{} 243 | if protoimpl.UnsafeEnabled { 244 | mi := &file_nlp_proto_msgTypes[4] 245 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 246 | ms.StoreMessageInfo(mi) 247 | } 248 | } 249 | 250 | func (x *Doc) String() string { 251 | return protoimpl.X.MessageStringOf(x) 252 | } 253 | 254 | func (*Doc) ProtoMessage() {} 255 | 256 | func (x *Doc) ProtoReflect() protoreflect.Message { 257 | mi := &file_nlp_proto_msgTypes[4] 258 | if protoimpl.UnsafeEnabled && x != nil { 259 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 260 | if ms.LoadMessageInfo() == nil { 261 | ms.StoreMessageInfo(mi) 262 | } 263 | return ms 264 | } 265 | return mi.MessageOf(x) 266 | } 267 | 268 | // Deprecated: Use Doc.ProtoReflect.Descriptor instead. 269 | func (*Doc) Descriptor() ([]byte, []int) { 270 | return file_nlp_proto_rawDescGZIP(), []int{4} 271 | } 272 | 273 | func (x *Doc) GetText() string { 274 | if x != nil { 275 | return x.Text 276 | } 277 | return "" 278 | } 279 | 280 | func (x *Doc) GetTextWithWs() string { 281 | if x != nil { 282 | return x.TextWithWs 283 | } 284 | return "" 285 | } 286 | 287 | func (x *Doc) GetIsTagged() bool { 288 | if x != nil { 289 | return x.IsTagged 290 | } 291 | return false 292 | } 293 | 294 | func (x *Doc) GetIsParsed() bool { 295 | if x != nil { 296 | return x.IsParsed 297 | } 298 | return false 299 | } 300 | 301 | func (x *Doc) GetIsNered() bool { 302 | if x != nil { 303 | return x.IsNered 304 | } 305 | return false 306 | } 307 | 308 | func (x *Doc) GetIsSentenced() bool { 309 | if x != nil { 310 | return x.IsSentenced 311 | } 312 | return false 313 | } 314 | 315 | type Ent struct { 316 | state protoimpl.MessageState 317 | sizeCache protoimpl.SizeCache 318 | unknownFields protoimpl.UnknownFields 319 | 320 | Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"` 321 | End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"` 322 | Label string `protobuf:"bytes,3,opt,name=label,proto3" json:"label,omitempty"` 323 | } 324 | 325 | func (x *Ent) Reset() { 326 | *x = Ent{} 327 | if protoimpl.UnsafeEnabled { 328 | mi := &file_nlp_proto_msgTypes[5] 329 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 330 | ms.StoreMessageInfo(mi) 331 | } 332 | } 333 | 334 | func (x *Ent) String() string { 335 | return protoimpl.X.MessageStringOf(x) 336 | } 337 | 338 | func (*Ent) ProtoMessage() {} 339 | 340 | func (x *Ent) ProtoReflect() protoreflect.Message { 341 | mi := &file_nlp_proto_msgTypes[5] 342 | if protoimpl.UnsafeEnabled && x != nil { 343 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 344 | if ms.LoadMessageInfo() == nil { 345 | ms.StoreMessageInfo(mi) 346 | } 347 | return ms 348 | } 349 | return mi.MessageOf(x) 350 | } 351 | 352 | // Deprecated: Use Ent.ProtoReflect.Descriptor instead. 353 | func (*Ent) Descriptor() ([]byte, []int) { 354 | return file_nlp_proto_rawDescGZIP(), []int{5} 355 | } 356 | 357 | func (x *Ent) GetStart() int32 { 358 | if x != nil { 359 | return x.Start 360 | } 361 | return 0 362 | } 363 | 364 | func (x *Ent) GetEnd() int32 { 365 | if x != nil { 366 | return x.End 367 | } 368 | return 0 369 | } 370 | 371 | func (x *Ent) GetLabel() string { 372 | if x != nil { 373 | return x.Label 374 | } 375 | return "" 376 | } 377 | 378 | type Sent struct { 379 | state protoimpl.MessageState 380 | sizeCache protoimpl.SizeCache 381 | unknownFields protoimpl.UnknownFields 382 | 383 | Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"` 384 | End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"` 385 | } 386 | 387 | func (x *Sent) Reset() { 388 | *x = Sent{} 389 | if protoimpl.UnsafeEnabled { 390 | mi := &file_nlp_proto_msgTypes[6] 391 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 392 | ms.StoreMessageInfo(mi) 393 | } 394 | } 395 | 396 | func (x *Sent) String() string { 397 | return protoimpl.X.MessageStringOf(x) 398 | } 399 | 400 | func (*Sent) ProtoMessage() {} 401 | 402 | func (x *Sent) ProtoReflect() protoreflect.Message { 403 | mi := &file_nlp_proto_msgTypes[6] 404 | if protoimpl.UnsafeEnabled && x != nil { 405 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 406 | if ms.LoadMessageInfo() == nil { 407 | ms.StoreMessageInfo(mi) 408 | } 409 | return ms 410 | } 411 | return mi.MessageOf(x) 412 | } 413 | 414 | // Deprecated: Use Sent.ProtoReflect.Descriptor instead. 415 | func (*Sent) Descriptor() ([]byte, []int) { 416 | return file_nlp_proto_rawDescGZIP(), []int{6} 417 | } 418 | 419 | func (x *Sent) GetStart() int32 { 420 | if x != nil { 421 | return x.Start 422 | } 423 | return 0 424 | } 425 | 426 | func (x *Sent) GetEnd() int32 { 427 | if x != nil { 428 | return x.End 429 | } 430 | return 0 431 | } 432 | 433 | type NounChunk struct { 434 | state protoimpl.MessageState 435 | sizeCache protoimpl.SizeCache 436 | unknownFields protoimpl.UnknownFields 437 | 438 | Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"` 439 | End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"` 440 | } 441 | 442 | func (x *NounChunk) Reset() { 443 | *x = NounChunk{} 444 | if protoimpl.UnsafeEnabled { 445 | mi := &file_nlp_proto_msgTypes[7] 446 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 447 | ms.StoreMessageInfo(mi) 448 | } 449 | } 450 | 451 | func (x *NounChunk) String() string { 452 | return protoimpl.X.MessageStringOf(x) 453 | } 454 | 455 | func (*NounChunk) ProtoMessage() {} 456 | 457 | func (x *NounChunk) ProtoReflect() protoreflect.Message { 458 | mi := &file_nlp_proto_msgTypes[7] 459 | if protoimpl.UnsafeEnabled && x != nil { 460 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 461 | if ms.LoadMessageInfo() == nil { 462 | ms.StoreMessageInfo(mi) 463 | } 464 | return ms 465 | } 466 | return mi.MessageOf(x) 467 | } 468 | 469 | // Deprecated: Use NounChunk.ProtoReflect.Descriptor instead. 470 | func (*NounChunk) Descriptor() ([]byte, []int) { 471 | return file_nlp_proto_rawDescGZIP(), []int{7} 472 | } 473 | 474 | func (x *NounChunk) GetStart() int32 { 475 | if x != nil { 476 | return x.Start 477 | } 478 | return 0 479 | } 480 | 481 | func (x *NounChunk) GetEnd() int32 { 482 | if x != nil { 483 | return x.End 484 | } 485 | return 0 486 | } 487 | 488 | type Token struct { 489 | state protoimpl.MessageState 490 | sizeCache protoimpl.SizeCache 491 | unknownFields protoimpl.UnknownFields 492 | 493 | Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` 494 | TextWithWs string `protobuf:"bytes,2,opt,name=text_with_ws,json=textWithWs,proto3" json:"text_with_ws,omitempty"` 495 | Whitespace string `protobuf:"bytes,3,opt,name=whitespace,proto3" json:"whitespace,omitempty"` 496 | EntType string `protobuf:"bytes,5,opt,name=ent_type,json=entType,proto3" json:"ent_type,omitempty"` 497 | EntIob string `protobuf:"bytes,6,opt,name=ent_iob,json=entIob,proto3" json:"ent_iob,omitempty"` 498 | Lemma string `protobuf:"bytes,7,opt,name=lemma,proto3" json:"lemma,omitempty"` 499 | Norm string `protobuf:"bytes,8,opt,name=norm,proto3" json:"norm,omitempty"` 500 | Lower string `protobuf:"bytes,9,opt,name=lower,proto3" json:"lower,omitempty"` 501 | Shape string `protobuf:"bytes,10,opt,name=shape,proto3" json:"shape,omitempty"` 502 | Prefix string `protobuf:"bytes,11,opt,name=prefix,proto3" json:"prefix,omitempty"` 503 | Suffix string `protobuf:"bytes,12,opt,name=suffix,proto3" json:"suffix,omitempty"` 504 | Pos string `protobuf:"bytes,13,opt,name=pos,proto3" json:"pos,omitempty"` 505 | Tag string `protobuf:"bytes,14,opt,name=tag,proto3" json:"tag,omitempty"` 506 | Dep string `protobuf:"bytes,15,opt,name=dep,proto3" json:"dep,omitempty"` 507 | IsAlpha bool `protobuf:"varint,16,opt,name=is_alpha,json=isAlpha,proto3" json:"is_alpha,omitempty"` 508 | IsAscii bool `protobuf:"varint,17,opt,name=is_ascii,json=isAscii,proto3" json:"is_ascii,omitempty"` 509 | IsDigit bool `protobuf:"varint,18,opt,name=is_digit,json=isDigit,proto3" json:"is_digit,omitempty"` 510 | IsLower bool `protobuf:"varint,19,opt,name=is_lower,json=isLower,proto3" json:"is_lower,omitempty"` 511 | IsUpper bool `protobuf:"varint,20,opt,name=is_upper,json=isUpper,proto3" json:"is_upper,omitempty"` 512 | IsTitle bool `protobuf:"varint,21,opt,name=is_title,json=isTitle,proto3" json:"is_title,omitempty"` 513 | IsPunct bool `protobuf:"varint,22,opt,name=is_punct,json=isPunct,proto3" json:"is_punct,omitempty"` 514 | IsLeftPunct bool `protobuf:"varint,23,opt,name=is_left_punct,json=isLeftPunct,proto3" json:"is_left_punct,omitempty"` 515 | IsRightPunct bool `protobuf:"varint,24,opt,name=is_right_punct,json=isRightPunct,proto3" json:"is_right_punct,omitempty"` 516 | IsSpace bool `protobuf:"varint,25,opt,name=is_space,json=isSpace,proto3" json:"is_space,omitempty"` 517 | IsBracket bool `protobuf:"varint,26,opt,name=is_bracket,json=isBracket,proto3" json:"is_bracket,omitempty"` 518 | IsCurrency bool `protobuf:"varint,27,opt,name=is_currency,json=isCurrency,proto3" json:"is_currency,omitempty"` 519 | LikeUrl bool `protobuf:"varint,28,opt,name=like_url,json=likeUrl,proto3" json:"like_url,omitempty"` 520 | LikeNum bool `protobuf:"varint,29,opt,name=like_num,json=likeNum,proto3" json:"like_num,omitempty"` 521 | LikeEmail bool `protobuf:"varint,30,opt,name=like_email,json=likeEmail,proto3" json:"like_email,omitempty"` 522 | IsOov bool `protobuf:"varint,31,opt,name=is_oov,json=isOov,proto3" json:"is_oov,omitempty"` 523 | IsStop bool `protobuf:"varint,32,opt,name=is_stop,json=isStop,proto3" json:"is_stop,omitempty"` 524 | IsSentStart bool `protobuf:"varint,33,opt,name=is_sent_start,json=isSentStart,proto3" json:"is_sent_start,omitempty"` 525 | Head int32 `protobuf:"varint,34,opt,name=head,proto3" json:"head,omitempty"` 526 | } 527 | 528 | func (x *Token) Reset() { 529 | *x = Token{} 530 | if protoimpl.UnsafeEnabled { 531 | mi := &file_nlp_proto_msgTypes[8] 532 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 533 | ms.StoreMessageInfo(mi) 534 | } 535 | } 536 | 537 | func (x *Token) String() string { 538 | return protoimpl.X.MessageStringOf(x) 539 | } 540 | 541 | func (*Token) ProtoMessage() {} 542 | 543 | func (x *Token) ProtoReflect() protoreflect.Message { 544 | mi := &file_nlp_proto_msgTypes[8] 545 | if protoimpl.UnsafeEnabled && x != nil { 546 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 547 | if ms.LoadMessageInfo() == nil { 548 | ms.StoreMessageInfo(mi) 549 | } 550 | return ms 551 | } 552 | return mi.MessageOf(x) 553 | } 554 | 555 | // Deprecated: Use Token.ProtoReflect.Descriptor instead. 556 | func (*Token) Descriptor() ([]byte, []int) { 557 | return file_nlp_proto_rawDescGZIP(), []int{8} 558 | } 559 | 560 | func (x *Token) GetText() string { 561 | if x != nil { 562 | return x.Text 563 | } 564 | return "" 565 | } 566 | 567 | func (x *Token) GetTextWithWs() string { 568 | if x != nil { 569 | return x.TextWithWs 570 | } 571 | return "" 572 | } 573 | 574 | func (x *Token) GetWhitespace() string { 575 | if x != nil { 576 | return x.Whitespace 577 | } 578 | return "" 579 | } 580 | 581 | func (x *Token) GetEntType() string { 582 | if x != nil { 583 | return x.EntType 584 | } 585 | return "" 586 | } 587 | 588 | func (x *Token) GetEntIob() string { 589 | if x != nil { 590 | return x.EntIob 591 | } 592 | return "" 593 | } 594 | 595 | func (x *Token) GetLemma() string { 596 | if x != nil { 597 | return x.Lemma 598 | } 599 | return "" 600 | } 601 | 602 | func (x *Token) GetNorm() string { 603 | if x != nil { 604 | return x.Norm 605 | } 606 | return "" 607 | } 608 | 609 | func (x *Token) GetLower() string { 610 | if x != nil { 611 | return x.Lower 612 | } 613 | return "" 614 | } 615 | 616 | func (x *Token) GetShape() string { 617 | if x != nil { 618 | return x.Shape 619 | } 620 | return "" 621 | } 622 | 623 | func (x *Token) GetPrefix() string { 624 | if x != nil { 625 | return x.Prefix 626 | } 627 | return "" 628 | } 629 | 630 | func (x *Token) GetSuffix() string { 631 | if x != nil { 632 | return x.Suffix 633 | } 634 | return "" 635 | } 636 | 637 | func (x *Token) GetPos() string { 638 | if x != nil { 639 | return x.Pos 640 | } 641 | return "" 642 | } 643 | 644 | func (x *Token) GetTag() string { 645 | if x != nil { 646 | return x.Tag 647 | } 648 | return "" 649 | } 650 | 651 | func (x *Token) GetDep() string { 652 | if x != nil { 653 | return x.Dep 654 | } 655 | return "" 656 | } 657 | 658 | func (x *Token) GetIsAlpha() bool { 659 | if x != nil { 660 | return x.IsAlpha 661 | } 662 | return false 663 | } 664 | 665 | func (x *Token) GetIsAscii() bool { 666 | if x != nil { 667 | return x.IsAscii 668 | } 669 | return false 670 | } 671 | 672 | func (x *Token) GetIsDigit() bool { 673 | if x != nil { 674 | return x.IsDigit 675 | } 676 | return false 677 | } 678 | 679 | func (x *Token) GetIsLower() bool { 680 | if x != nil { 681 | return x.IsLower 682 | } 683 | return false 684 | } 685 | 686 | func (x *Token) GetIsUpper() bool { 687 | if x != nil { 688 | return x.IsUpper 689 | } 690 | return false 691 | } 692 | 693 | func (x *Token) GetIsTitle() bool { 694 | if x != nil { 695 | return x.IsTitle 696 | } 697 | return false 698 | } 699 | 700 | func (x *Token) GetIsPunct() bool { 701 | if x != nil { 702 | return x.IsPunct 703 | } 704 | return false 705 | } 706 | 707 | func (x *Token) GetIsLeftPunct() bool { 708 | if x != nil { 709 | return x.IsLeftPunct 710 | } 711 | return false 712 | } 713 | 714 | func (x *Token) GetIsRightPunct() bool { 715 | if x != nil { 716 | return x.IsRightPunct 717 | } 718 | return false 719 | } 720 | 721 | func (x *Token) GetIsSpace() bool { 722 | if x != nil { 723 | return x.IsSpace 724 | } 725 | return false 726 | } 727 | 728 | func (x *Token) GetIsBracket() bool { 729 | if x != nil { 730 | return x.IsBracket 731 | } 732 | return false 733 | } 734 | 735 | func (x *Token) GetIsCurrency() bool { 736 | if x != nil { 737 | return x.IsCurrency 738 | } 739 | return false 740 | } 741 | 742 | func (x *Token) GetLikeUrl() bool { 743 | if x != nil { 744 | return x.LikeUrl 745 | } 746 | return false 747 | } 748 | 749 | func (x *Token) GetLikeNum() bool { 750 | if x != nil { 751 | return x.LikeNum 752 | } 753 | return false 754 | } 755 | 756 | func (x *Token) GetLikeEmail() bool { 757 | if x != nil { 758 | return x.LikeEmail 759 | } 760 | return false 761 | } 762 | 763 | func (x *Token) GetIsOov() bool { 764 | if x != nil { 765 | return x.IsOov 766 | } 767 | return false 768 | } 769 | 770 | func (x *Token) GetIsStop() bool { 771 | if x != nil { 772 | return x.IsStop 773 | } 774 | return false 775 | } 776 | 777 | func (x *Token) GetIsSentStart() bool { 778 | if x != nil { 779 | return x.IsSentStart 780 | } 781 | return false 782 | } 783 | 784 | func (x *Token) GetHead() int32 { 785 | if x != nil { 786 | return x.Head 787 | } 788 | return 0 789 | } 790 | 791 | type ParsedNLPRes struct { 792 | state protoimpl.MessageState 793 | sizeCache protoimpl.SizeCache 794 | unknownFields protoimpl.UnknownFields 795 | 796 | Model string `protobuf:"bytes,1,opt,name=model,proto3" json:"model,omitempty"` 797 | Doc *Doc `protobuf:"bytes,2,opt,name=doc,proto3" json:"doc,omitempty"` 798 | Ents []*Ent `protobuf:"bytes,3,rep,name=ents,proto3" json:"ents,omitempty"` 799 | Sents []*Sent `protobuf:"bytes,4,rep,name=sents,proto3" json:"sents,omitempty"` 800 | NounChunks []*NounChunk `protobuf:"bytes,5,rep,name=noun_chunks,json=nounChunks,proto3" json:"noun_chunks,omitempty"` 801 | Tokens []*Token `protobuf:"bytes,6,rep,name=tokens,proto3" json:"tokens,omitempty"` 802 | } 803 | 804 | func (x *ParsedNLPRes) Reset() { 805 | *x = ParsedNLPRes{} 806 | if protoimpl.UnsafeEnabled { 807 | mi := &file_nlp_proto_msgTypes[9] 808 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 809 | ms.StoreMessageInfo(mi) 810 | } 811 | } 812 | 813 | func (x *ParsedNLPRes) String() string { 814 | return protoimpl.X.MessageStringOf(x) 815 | } 816 | 817 | func (*ParsedNLPRes) ProtoMessage() {} 818 | 819 | func (x *ParsedNLPRes) ProtoReflect() protoreflect.Message { 820 | mi := &file_nlp_proto_msgTypes[9] 821 | if protoimpl.UnsafeEnabled && x != nil { 822 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 823 | if ms.LoadMessageInfo() == nil { 824 | ms.StoreMessageInfo(mi) 825 | } 826 | return ms 827 | } 828 | return mi.MessageOf(x) 829 | } 830 | 831 | // Deprecated: Use ParsedNLPRes.ProtoReflect.Descriptor instead. 832 | func (*ParsedNLPRes) Descriptor() ([]byte, []int) { 833 | return file_nlp_proto_rawDescGZIP(), []int{9} 834 | } 835 | 836 | func (x *ParsedNLPRes) GetModel() string { 837 | if x != nil { 838 | return x.Model 839 | } 840 | return "" 841 | } 842 | 843 | func (x *ParsedNLPRes) GetDoc() *Doc { 844 | if x != nil { 845 | return x.Doc 846 | } 847 | return nil 848 | } 849 | 850 | func (x *ParsedNLPRes) GetEnts() []*Ent { 851 | if x != nil { 852 | return x.Ents 853 | } 854 | return nil 855 | } 856 | 857 | func (x *ParsedNLPRes) GetSents() []*Sent { 858 | if x != nil { 859 | return x.Sents 860 | } 861 | return nil 862 | } 863 | 864 | func (x *ParsedNLPRes) GetNounChunks() []*NounChunk { 865 | if x != nil { 866 | return x.NounChunks 867 | } 868 | return nil 869 | } 870 | 871 | func (x *ParsedNLPRes) GetTokens() []*Token { 872 | if x != nil { 873 | return x.Tokens 874 | } 875 | return nil 876 | } 877 | 878 | type Pattern struct { 879 | state protoimpl.MessageState 880 | sizeCache protoimpl.SizeCache 881 | unknownFields protoimpl.UnknownFields 882 | 883 | Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` 884 | Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` 885 | } 886 | 887 | func (x *Pattern) Reset() { 888 | *x = Pattern{} 889 | if protoimpl.UnsafeEnabled { 890 | mi := &file_nlp_proto_msgTypes[10] 891 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 892 | ms.StoreMessageInfo(mi) 893 | } 894 | } 895 | 896 | func (x *Pattern) String() string { 897 | return protoimpl.X.MessageStringOf(x) 898 | } 899 | 900 | func (*Pattern) ProtoMessage() {} 901 | 902 | func (x *Pattern) ProtoReflect() protoreflect.Message { 903 | mi := &file_nlp_proto_msgTypes[10] 904 | if protoimpl.UnsafeEnabled && x != nil { 905 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 906 | if ms.LoadMessageInfo() == nil { 907 | ms.StoreMessageInfo(mi) 908 | } 909 | return ms 910 | } 911 | return mi.MessageOf(x) 912 | } 913 | 914 | // Deprecated: Use Pattern.ProtoReflect.Descriptor instead. 915 | func (*Pattern) Descriptor() ([]byte, []int) { 916 | return file_nlp_proto_rawDescGZIP(), []int{10} 917 | } 918 | 919 | func (x *Pattern) GetKey() string { 920 | if x != nil { 921 | return x.Key 922 | } 923 | return "" 924 | } 925 | 926 | func (x *Pattern) GetValue() string { 927 | if x != nil { 928 | return x.Value 929 | } 930 | return "" 931 | } 932 | 933 | type Rule struct { 934 | state protoimpl.MessageState 935 | sizeCache protoimpl.SizeCache 936 | unknownFields protoimpl.UnknownFields 937 | 938 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 939 | Patterns []*Pattern `protobuf:"bytes,2,rep,name=patterns,proto3" json:"patterns,omitempty"` 940 | } 941 | 942 | func (x *Rule) Reset() { 943 | *x = Rule{} 944 | if protoimpl.UnsafeEnabled { 945 | mi := &file_nlp_proto_msgTypes[11] 946 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 947 | ms.StoreMessageInfo(mi) 948 | } 949 | } 950 | 951 | func (x *Rule) String() string { 952 | return protoimpl.X.MessageStringOf(x) 953 | } 954 | 955 | func (*Rule) ProtoMessage() {} 956 | 957 | func (x *Rule) ProtoReflect() protoreflect.Message { 958 | mi := &file_nlp_proto_msgTypes[11] 959 | if protoimpl.UnsafeEnabled && x != nil { 960 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 961 | if ms.LoadMessageInfo() == nil { 962 | ms.StoreMessageInfo(mi) 963 | } 964 | return ms 965 | } 966 | return mi.MessageOf(x) 967 | } 968 | 969 | // Deprecated: Use Rule.ProtoReflect.Descriptor instead. 970 | func (*Rule) Descriptor() ([]byte, []int) { 971 | return file_nlp_proto_rawDescGZIP(), []int{11} 972 | } 973 | 974 | func (x *Rule) GetId() string { 975 | if x != nil { 976 | return x.Id 977 | } 978 | return "" 979 | } 980 | 981 | func (x *Rule) GetPatterns() []*Pattern { 982 | if x != nil { 983 | return x.Patterns 984 | } 985 | return nil 986 | } 987 | 988 | type Match struct { 989 | state protoimpl.MessageState 990 | sizeCache protoimpl.SizeCache 991 | unknownFields protoimpl.UnknownFields 992 | 993 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 994 | Start int32 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` 995 | End int32 `protobuf:"varint,3,opt,name=end,proto3" json:"end,omitempty"` 996 | } 997 | 998 | func (x *Match) Reset() { 999 | *x = Match{} 1000 | if protoimpl.UnsafeEnabled { 1001 | mi := &file_nlp_proto_msgTypes[12] 1002 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 1003 | ms.StoreMessageInfo(mi) 1004 | } 1005 | } 1006 | 1007 | func (x *Match) String() string { 1008 | return protoimpl.X.MessageStringOf(x) 1009 | } 1010 | 1011 | func (*Match) ProtoMessage() {} 1012 | 1013 | func (x *Match) ProtoReflect() protoreflect.Message { 1014 | mi := &file_nlp_proto_msgTypes[12] 1015 | if protoimpl.UnsafeEnabled && x != nil { 1016 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 1017 | if ms.LoadMessageInfo() == nil { 1018 | ms.StoreMessageInfo(mi) 1019 | } 1020 | return ms 1021 | } 1022 | return mi.MessageOf(x) 1023 | } 1024 | 1025 | // Deprecated: Use Match.ProtoReflect.Descriptor instead. 1026 | func (*Match) Descriptor() ([]byte, []int) { 1027 | return file_nlp_proto_rawDescGZIP(), []int{12} 1028 | } 1029 | 1030 | func (x *Match) GetId() string { 1031 | if x != nil { 1032 | return x.Id 1033 | } 1034 | return "" 1035 | } 1036 | 1037 | func (x *Match) GetStart() int32 { 1038 | if x != nil { 1039 | return x.Start 1040 | } 1041 | return 0 1042 | } 1043 | 1044 | func (x *Match) GetEnd() int32 { 1045 | if x != nil { 1046 | return x.End 1047 | } 1048 | return 0 1049 | } 1050 | 1051 | type Matches struct { 1052 | state protoimpl.MessageState 1053 | sizeCache protoimpl.SizeCache 1054 | unknownFields protoimpl.UnknownFields 1055 | 1056 | Matches []*Match `protobuf:"bytes,1,rep,name=matches,proto3" json:"matches,omitempty"` 1057 | } 1058 | 1059 | func (x *Matches) Reset() { 1060 | *x = Matches{} 1061 | if protoimpl.UnsafeEnabled { 1062 | mi := &file_nlp_proto_msgTypes[13] 1063 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 1064 | ms.StoreMessageInfo(mi) 1065 | } 1066 | } 1067 | 1068 | func (x *Matches) String() string { 1069 | return protoimpl.X.MessageStringOf(x) 1070 | } 1071 | 1072 | func (*Matches) ProtoMessage() {} 1073 | 1074 | func (x *Matches) ProtoReflect() protoreflect.Message { 1075 | mi := &file_nlp_proto_msgTypes[13] 1076 | if protoimpl.UnsafeEnabled && x != nil { 1077 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 1078 | if ms.LoadMessageInfo() == nil { 1079 | ms.StoreMessageInfo(mi) 1080 | } 1081 | return ms 1082 | } 1083 | return mi.MessageOf(x) 1084 | } 1085 | 1086 | // Deprecated: Use Matches.ProtoReflect.Descriptor instead. 1087 | func (*Matches) Descriptor() ([]byte, []int) { 1088 | return file_nlp_proto_rawDescGZIP(), []int{13} 1089 | } 1090 | 1091 | func (x *Matches) GetMatches() []*Match { 1092 | if x != nil { 1093 | return x.Matches 1094 | } 1095 | return nil 1096 | } 1097 | 1098 | var File_nlp_proto protoreflect.FileDescriptor 1099 | 1100 | var file_nlp_proto_rawDesc = []byte{ 1101 | 0x0a, 0x09, 0x6e, 0x6c, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x6e, 0x6c, 0x70, 1102 | 0x22, 0x21, 0x0a, 0x0b, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 1103 | 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 1104 | 0x65, 0x78, 0x74, 0x22, 0x43, 0x0a, 0x15, 0x54, 0x65, 0x78, 0x74, 0x53, 0x69, 0x6d, 0x69, 0x6c, 1105 | 0x61, 0x72, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 1106 | 0x74, 0x65, 0x78, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x65, 0x78, 1107 | 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x65, 0x78, 0x74, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 1108 | 0x09, 0x52, 0x05, 0x74, 0x65, 0x78, 0x74, 0x62, 0x22, 0x28, 0x0a, 0x0c, 0x54, 0x65, 0x78, 0x74, 1109 | 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 1110 | 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 1111 | 0x67, 0x65, 0x22, 0x30, 0x0a, 0x0e, 0x54, 0x65, 0x78, 0x74, 0x53, 0x69, 0x6d, 0x69, 0x6c, 0x61, 1112 | 0x72, 0x69, 0x74, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x69, 0x6d, 0x69, 0x6c, 0x61, 0x72, 0x69, 1113 | 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x73, 0x69, 0x6d, 0x69, 0x6c, 0x61, 1114 | 0x72, 0x69, 0x74, 0x79, 0x22, 0xb3, 0x01, 0x0a, 0x03, 0x44, 0x6f, 0x63, 0x12, 0x12, 0x0a, 0x04, 1115 | 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 1116 | 0x12, 0x20, 0x0a, 0x0c, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x5f, 0x77, 0x73, 1117 | 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x57, 0x69, 0x74, 0x68, 1118 | 0x57, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x73, 0x5f, 0x74, 0x61, 0x67, 0x67, 0x65, 0x64, 0x18, 1119 | 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x54, 0x61, 0x67, 0x67, 0x65, 0x64, 0x12, 1120 | 0x1b, 0x0a, 0x09, 0x69, 0x73, 0x5f, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 1121 | 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x50, 0x61, 0x72, 0x73, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 1122 | 0x69, 0x73, 0x5f, 0x6e, 0x65, 0x72, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 1123 | 0x69, 0x73, 0x4e, 0x65, 0x72, 0x65, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x73, 0x5f, 0x73, 0x65, 1124 | 0x6e, 0x74, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 1125 | 0x73, 0x53, 0x65, 0x6e, 0x74, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x22, 0x43, 0x0a, 0x03, 0x45, 0x6e, 1126 | 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 1127 | 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 1128 | 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x61, 0x62, 1129 | 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x22, 1130 | 0x2e, 0x0a, 0x04, 0x53, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 1131 | 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 1132 | 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x22, 1133 | 0x34, 0x0a, 0x0a, 0x4e, 0x6f, 0x75, 0x6e, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x12, 0x14, 0x0a, 1134 | 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 1135 | 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 1136 | 0x52, 0x03, 0x65, 0x6e, 0x64, 0x22, 0xec, 0x06, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 1137 | 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 1138 | 0x65, 0x78, 0x74, 0x12, 0x20, 0x0a, 0x0c, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x77, 0x69, 0x74, 0x68, 1139 | 0x5f, 0x77, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x57, 1140 | 0x69, 0x74, 0x68, 0x57, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x77, 0x68, 0x69, 0x74, 0x65, 0x73, 0x70, 1141 | 0x61, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x77, 0x68, 0x69, 0x74, 0x65, 1142 | 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 1143 | 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 1144 | 0x12, 0x17, 0x0a, 0x07, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x6f, 0x62, 0x18, 0x06, 0x20, 0x01, 0x28, 1145 | 0x09, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x49, 0x6f, 0x62, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x6d, 1146 | 0x6d, 0x61, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x12, 1147 | 0x12, 0x0a, 0x04, 0x6e, 0x6f, 0x72, 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 1148 | 0x6f, 0x72, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 1149 | 0x28, 0x09, 0x52, 0x05, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x68, 0x61, 1150 | 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x68, 0x61, 0x70, 0x65, 0x12, 1151 | 0x16, 0x0a, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 1152 | 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x75, 0x66, 0x66, 0x69, 1153 | 0x78, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x75, 0x66, 0x66, 0x69, 0x78, 0x12, 1154 | 0x10, 0x0a, 0x03, 0x70, 0x6f, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x70, 0x6f, 1155 | 0x73, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 1156 | 0x74, 0x61, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x64, 0x65, 0x70, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 1157 | 0x52, 0x03, 0x64, 0x65, 0x70, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x61, 0x6c, 0x70, 0x68, 1158 | 0x61, 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x41, 0x6c, 0x70, 0x68, 0x61, 1159 | 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x61, 0x73, 0x63, 0x69, 0x69, 0x18, 0x11, 0x20, 0x01, 1160 | 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x41, 0x73, 0x63, 0x69, 0x69, 0x12, 0x19, 0x0a, 0x08, 0x69, 1161 | 0x73, 0x5f, 0x64, 0x69, 0x67, 0x69, 0x74, 0x18, 0x12, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 1162 | 0x73, 0x44, 0x69, 0x67, 0x69, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x6c, 0x6f, 0x77, 1163 | 0x65, 0x72, 0x18, 0x13, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x4c, 0x6f, 0x77, 0x65, 1164 | 0x72, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x75, 0x70, 0x70, 0x65, 0x72, 0x18, 0x14, 0x20, 1165 | 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x55, 0x70, 0x70, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 1166 | 0x69, 0x73, 0x5f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x15, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 1167 | 0x69, 0x73, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x70, 0x75, 1168 | 0x6e, 0x63, 0x74, 0x18, 0x16, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x50, 0x75, 0x6e, 1169 | 0x63, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x69, 0x73, 0x5f, 0x6c, 0x65, 0x66, 0x74, 0x5f, 0x70, 0x75, 1170 | 0x6e, 0x63, 0x74, 0x18, 0x17, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x73, 0x4c, 0x65, 0x66, 1171 | 0x74, 0x50, 0x75, 0x6e, 0x63, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x69, 0x73, 0x5f, 0x72, 0x69, 0x67, 1172 | 0x68, 0x74, 0x5f, 0x70, 0x75, 0x6e, 0x63, 0x74, 0x18, 0x18, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 1173 | 0x69, 0x73, 0x52, 0x69, 0x67, 0x68, 0x74, 0x50, 0x75, 0x6e, 0x63, 0x74, 0x12, 0x19, 0x0a, 0x08, 1174 | 0x69, 0x73, 0x5f, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x19, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 1175 | 0x69, 0x73, 0x53, 0x70, 0x61, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x62, 0x72, 1176 | 0x61, 0x63, 0x6b, 0x65, 0x74, 0x18, 0x1a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x42, 1177 | 0x72, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x63, 0x75, 0x72, 1178 | 0x72, 0x65, 0x6e, 0x63, 0x79, 0x18, 0x1b, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x43, 1179 | 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6b, 0x65, 0x5f, 1180 | 0x75, 0x72, 0x6c, 0x18, 0x1c, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6c, 0x69, 0x6b, 0x65, 0x55, 1181 | 0x72, 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x69, 0x6b, 0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x18, 0x1d, 1182 | 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6c, 0x69, 0x6b, 0x65, 0x4e, 0x75, 0x6d, 0x12, 0x1d, 0x0a, 1183 | 0x0a, 0x6c, 0x69, 0x6b, 0x65, 0x5f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x1e, 0x20, 0x01, 0x28, 1184 | 0x08, 0x52, 0x09, 0x6c, 0x69, 0x6b, 0x65, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x15, 0x0a, 0x06, 1185 | 0x69, 0x73, 0x5f, 0x6f, 0x6f, 0x76, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x69, 0x73, 1186 | 0x4f, 0x6f, 0x76, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x73, 0x5f, 0x73, 0x74, 0x6f, 0x70, 0x18, 0x20, 1187 | 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x22, 0x0a, 0x0d, 1188 | 0x69, 0x73, 0x5f, 0x73, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x21, 0x20, 1189 | 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x73, 0x53, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x72, 0x74, 1190 | 0x12, 0x12, 0x0a, 0x04, 0x68, 0x65, 0x61, 0x64, 0x18, 0x22, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 1191 | 0x68, 0x65, 0x61, 0x64, 0x22, 0xd5, 0x01, 0x0a, 0x0c, 0x50, 0x61, 0x72, 0x73, 0x65, 0x64, 0x4e, 1192 | 0x4c, 0x50, 0x52, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x01, 1193 | 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x1a, 0x0a, 0x03, 0x64, 1194 | 0x6f, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x44, 1195 | 0x6f, 0x63, 0x52, 0x03, 0x64, 0x6f, 0x63, 0x12, 0x1c, 0x0a, 0x04, 0x65, 0x6e, 0x74, 0x73, 0x18, 1196 | 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x45, 0x6e, 0x74, 0x52, 1197 | 0x04, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 1198 | 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x53, 0x65, 0x6e, 0x74, 0x52, 1199 | 0x05, 0x73, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x30, 0x0a, 0x0b, 0x6e, 0x6f, 0x75, 0x6e, 0x5f, 0x63, 1200 | 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x6e, 0x6c, 1201 | 0x70, 0x2e, 0x4e, 0x6f, 0x75, 0x6e, 0x5f, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x52, 0x0a, 0x6e, 0x6f, 1202 | 0x75, 0x6e, 0x43, 0x68, 0x75, 0x6e, 0x6b, 0x73, 0x12, 0x22, 0x0a, 0x06, 0x74, 0x6f, 0x6b, 0x65, 1203 | 0x6e, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 1204 | 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x06, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x22, 0x31, 0x0a, 0x07, 1205 | 0x50, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 1206 | 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 1207 | 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 1208 | 0x40, 0x0a, 0x04, 0x52, 0x75, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 1209 | 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x28, 0x0a, 0x08, 0x70, 0x61, 0x74, 0x74, 0x65, 1210 | 0x72, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 1211 | 0x50, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x52, 0x08, 0x70, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 1212 | 0x73, 0x22, 0x3f, 0x0a, 0x05, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 1213 | 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 1214 | 0x61, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 1215 | 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 1216 | 0x6e, 0x64, 0x22, 0x2f, 0x0a, 0x07, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x24, 0x0a, 1217 | 0x07, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 1218 | 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x07, 0x6d, 0x61, 0x74, 0x63, 1219 | 0x68, 0x65, 0x73, 0x32, 0xa3, 0x03, 0x0a, 0x03, 0x4e, 0x6c, 0x70, 0x12, 0x32, 0x0a, 0x09, 0x4c, 1220 | 0x6f, 0x61, 0x64, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x10, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 1221 | 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6e, 0x6c, 0x70, 1222 | 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 1223 | 0x33, 0x0a, 0x0a, 0x4e, 0x6c, 0x70, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x12, 0x10, 0x2e, 1224 | 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 1225 | 0x11, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x64, 0x4e, 0x4c, 0x50, 0x52, 1226 | 0x65, 0x73, 0x22, 0x00, 0x12, 0x42, 0x0a, 0x0d, 0x44, 0x6f, 0x63, 0x53, 0x69, 0x6d, 0x69, 0x6c, 1227 | 0x61, 0x72, 0x69, 0x74, 0x79, 0x12, 0x1a, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 1228 | 0x53, 0x69, 0x6d, 0x69, 0x6c, 0x61, 0x72, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 1229 | 0x74, 0x1a, 0x13, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x53, 0x69, 0x6d, 0x69, 1230 | 0x6c, 0x61, 0x72, 0x69, 0x74, 0x79, 0x22, 0x00, 0x12, 0x29, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x52, 1231 | 0x75, 0x6c, 0x65, 0x12, 0x09, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x52, 0x75, 0x6c, 0x65, 0x1a, 0x11, 1232 | 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 1233 | 0x65, 0x22, 0x00, 0x12, 0x33, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x52, 0x75, 0x6c, 1234 | 0x65, 0x12, 0x10, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 1235 | 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 1236 | 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x28, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x52, 1237 | 0x75, 0x6c, 0x65, 0x12, 0x10, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 1238 | 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x09, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x52, 0x75, 0x6c, 0x65, 1239 | 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 1240 | 0x12, 0x10, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 1241 | 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 1242 | 0x22, 0x00, 0x12, 0x35, 0x0a, 0x0c, 0x52, 0x65, 0x73, 0x65, 0x74, 0x4d, 0x61, 0x74, 0x63, 0x68, 1243 | 0x65, 0x72, 0x12, 0x10, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 1244 | 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6e, 0x6c, 0x70, 0x2e, 0x54, 0x65, 0x78, 0x74, 0x52, 1245 | 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 1246 | 0x33, 1247 | } 1248 | 1249 | var ( 1250 | file_nlp_proto_rawDescOnce sync.Once 1251 | file_nlp_proto_rawDescData = file_nlp_proto_rawDesc 1252 | ) 1253 | 1254 | func file_nlp_proto_rawDescGZIP() []byte { 1255 | file_nlp_proto_rawDescOnce.Do(func() { 1256 | file_nlp_proto_rawDescData = protoimpl.X.CompressGZIP(file_nlp_proto_rawDescData) 1257 | }) 1258 | return file_nlp_proto_rawDescData 1259 | } 1260 | 1261 | var file_nlp_proto_msgTypes = make([]protoimpl.MessageInfo, 14) 1262 | var file_nlp_proto_goTypes = []interface{}{ 1263 | (*TextRequest)(nil), // 0: nlp.TextRequest 1264 | (*TextSimilarityRequest)(nil), // 1: nlp.TextSimilarityRequest 1265 | (*TextResponse)(nil), // 2: nlp.TextResponse 1266 | (*TextSimilarity)(nil), // 3: nlp.TextSimilarity 1267 | (*Doc)(nil), // 4: nlp.Doc 1268 | (*Ent)(nil), // 5: nlp.Ent 1269 | (*Sent)(nil), // 6: nlp.Sent 1270 | (*NounChunk)(nil), // 7: nlp.Noun_chunk 1271 | (*Token)(nil), // 8: nlp.Token 1272 | (*ParsedNLPRes)(nil), // 9: nlp.ParsedNLPRes 1273 | (*Pattern)(nil), // 10: nlp.Pattern 1274 | (*Rule)(nil), // 11: nlp.Rule 1275 | (*Match)(nil), // 12: nlp.Match 1276 | (*Matches)(nil), // 13: nlp.Matches 1277 | } 1278 | var file_nlp_proto_depIdxs = []int32{ 1279 | 4, // 0: nlp.ParsedNLPRes.doc:type_name -> nlp.Doc 1280 | 5, // 1: nlp.ParsedNLPRes.ents:type_name -> nlp.Ent 1281 | 6, // 2: nlp.ParsedNLPRes.sents:type_name -> nlp.Sent 1282 | 7, // 3: nlp.ParsedNLPRes.noun_chunks:type_name -> nlp.Noun_chunk 1283 | 8, // 4: nlp.ParsedNLPRes.tokens:type_name -> nlp.Token 1284 | 10, // 5: nlp.Rule.patterns:type_name -> nlp.Pattern 1285 | 12, // 6: nlp.Matches.matches:type_name -> nlp.Match 1286 | 0, // 7: nlp.Nlp.LoadModel:input_type -> nlp.TextRequest 1287 | 0, // 8: nlp.Nlp.NlpProcess:input_type -> nlp.TextRequest 1288 | 1, // 9: nlp.Nlp.DocSimilarity:input_type -> nlp.TextSimilarityRequest 1289 | 11, // 10: nlp.Nlp.AddRule:input_type -> nlp.Rule 1290 | 0, // 11: nlp.Nlp.RemoveRule:input_type -> nlp.TextRequest 1291 | 0, // 12: nlp.Nlp.GetRule:input_type -> nlp.TextRequest 1292 | 0, // 13: nlp.Nlp.GetMatches:input_type -> nlp.TextRequest 1293 | 0, // 14: nlp.Nlp.ResetMatcher:input_type -> nlp.TextRequest 1294 | 2, // 15: nlp.Nlp.LoadModel:output_type -> nlp.TextResponse 1295 | 9, // 16: nlp.Nlp.NlpProcess:output_type -> nlp.ParsedNLPRes 1296 | 3, // 17: nlp.Nlp.DocSimilarity:output_type -> nlp.TextSimilarity 1297 | 2, // 18: nlp.Nlp.AddRule:output_type -> nlp.TextResponse 1298 | 2, // 19: nlp.Nlp.RemoveRule:output_type -> nlp.TextResponse 1299 | 11, // 20: nlp.Nlp.GetRule:output_type -> nlp.Rule 1300 | 13, // 21: nlp.Nlp.GetMatches:output_type -> nlp.Matches 1301 | 2, // 22: nlp.Nlp.ResetMatcher:output_type -> nlp.TextResponse 1302 | 15, // [15:23] is the sub-list for method output_type 1303 | 7, // [7:15] is the sub-list for method input_type 1304 | 7, // [7:7] is the sub-list for extension type_name 1305 | 7, // [7:7] is the sub-list for extension extendee 1306 | 0, // [0:7] is the sub-list for field type_name 1307 | } 1308 | 1309 | func init() { file_nlp_proto_init() } 1310 | func file_nlp_proto_init() { 1311 | if File_nlp_proto != nil { 1312 | return 1313 | } 1314 | if !protoimpl.UnsafeEnabled { 1315 | file_nlp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 1316 | switch v := v.(*TextRequest); i { 1317 | case 0: 1318 | return &v.state 1319 | case 1: 1320 | return &v.sizeCache 1321 | case 2: 1322 | return &v.unknownFields 1323 | default: 1324 | return nil 1325 | } 1326 | } 1327 | file_nlp_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 1328 | switch v := v.(*TextSimilarityRequest); i { 1329 | case 0: 1330 | return &v.state 1331 | case 1: 1332 | return &v.sizeCache 1333 | case 2: 1334 | return &v.unknownFields 1335 | default: 1336 | return nil 1337 | } 1338 | } 1339 | file_nlp_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 1340 | switch v := v.(*TextResponse); i { 1341 | case 0: 1342 | return &v.state 1343 | case 1: 1344 | return &v.sizeCache 1345 | case 2: 1346 | return &v.unknownFields 1347 | default: 1348 | return nil 1349 | } 1350 | } 1351 | file_nlp_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 1352 | switch v := v.(*TextSimilarity); i { 1353 | case 0: 1354 | return &v.state 1355 | case 1: 1356 | return &v.sizeCache 1357 | case 2: 1358 | return &v.unknownFields 1359 | default: 1360 | return nil 1361 | } 1362 | } 1363 | file_nlp_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 1364 | switch v := v.(*Doc); i { 1365 | case 0: 1366 | return &v.state 1367 | case 1: 1368 | return &v.sizeCache 1369 | case 2: 1370 | return &v.unknownFields 1371 | default: 1372 | return nil 1373 | } 1374 | } 1375 | file_nlp_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { 1376 | switch v := v.(*Ent); i { 1377 | case 0: 1378 | return &v.state 1379 | case 1: 1380 | return &v.sizeCache 1381 | case 2: 1382 | return &v.unknownFields 1383 | default: 1384 | return nil 1385 | } 1386 | } 1387 | file_nlp_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { 1388 | switch v := v.(*Sent); i { 1389 | case 0: 1390 | return &v.state 1391 | case 1: 1392 | return &v.sizeCache 1393 | case 2: 1394 | return &v.unknownFields 1395 | default: 1396 | return nil 1397 | } 1398 | } 1399 | file_nlp_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { 1400 | switch v := v.(*NounChunk); i { 1401 | case 0: 1402 | return &v.state 1403 | case 1: 1404 | return &v.sizeCache 1405 | case 2: 1406 | return &v.unknownFields 1407 | default: 1408 | return nil 1409 | } 1410 | } 1411 | file_nlp_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { 1412 | switch v := v.(*Token); i { 1413 | case 0: 1414 | return &v.state 1415 | case 1: 1416 | return &v.sizeCache 1417 | case 2: 1418 | return &v.unknownFields 1419 | default: 1420 | return nil 1421 | } 1422 | } 1423 | file_nlp_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { 1424 | switch v := v.(*ParsedNLPRes); i { 1425 | case 0: 1426 | return &v.state 1427 | case 1: 1428 | return &v.sizeCache 1429 | case 2: 1430 | return &v.unknownFields 1431 | default: 1432 | return nil 1433 | } 1434 | } 1435 | file_nlp_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { 1436 | switch v := v.(*Pattern); i { 1437 | case 0: 1438 | return &v.state 1439 | case 1: 1440 | return &v.sizeCache 1441 | case 2: 1442 | return &v.unknownFields 1443 | default: 1444 | return nil 1445 | } 1446 | } 1447 | file_nlp_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { 1448 | switch v := v.(*Rule); i { 1449 | case 0: 1450 | return &v.state 1451 | case 1: 1452 | return &v.sizeCache 1453 | case 2: 1454 | return &v.unknownFields 1455 | default: 1456 | return nil 1457 | } 1458 | } 1459 | file_nlp_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { 1460 | switch v := v.(*Match); i { 1461 | case 0: 1462 | return &v.state 1463 | case 1: 1464 | return &v.sizeCache 1465 | case 2: 1466 | return &v.unknownFields 1467 | default: 1468 | return nil 1469 | } 1470 | } 1471 | file_nlp_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { 1472 | switch v := v.(*Matches); i { 1473 | case 0: 1474 | return &v.state 1475 | case 1: 1476 | return &v.sizeCache 1477 | case 2: 1478 | return &v.unknownFields 1479 | default: 1480 | return nil 1481 | } 1482 | } 1483 | } 1484 | type x struct{} 1485 | out := protoimpl.TypeBuilder{ 1486 | File: protoimpl.DescBuilder{ 1487 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 1488 | RawDescriptor: file_nlp_proto_rawDesc, 1489 | NumEnums: 0, 1490 | NumMessages: 14, 1491 | NumExtensions: 0, 1492 | NumServices: 1, 1493 | }, 1494 | GoTypes: file_nlp_proto_goTypes, 1495 | DependencyIndexes: file_nlp_proto_depIdxs, 1496 | MessageInfos: file_nlp_proto_msgTypes, 1497 | }.Build() 1498 | File_nlp_proto = out.File 1499 | file_nlp_proto_rawDesc = nil 1500 | file_nlp_proto_goTypes = nil 1501 | file_nlp_proto_depIdxs = nil 1502 | } 1503 | 1504 | // Reference imports to suppress errors if they are not otherwise used. 1505 | var _ context.Context 1506 | var _ grpc.ClientConnInterface 1507 | 1508 | // This is a compile-time assertion to ensure that this generated file 1509 | // is compatible with the grpc package it is being compiled against. 1510 | const _ = grpc.SupportPackageIsVersion6 1511 | 1512 | // NlpClient is the client API for Nlp service. 1513 | // 1514 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 1515 | type NlpClient interface { 1516 | LoadModel(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) 1517 | NlpProcess(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*ParsedNLPRes, error) 1518 | DocSimilarity(ctx context.Context, in *TextSimilarityRequest, opts ...grpc.CallOption) (*TextSimilarity, error) 1519 | AddRule(ctx context.Context, in *Rule, opts ...grpc.CallOption) (*TextResponse, error) 1520 | RemoveRule(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) 1521 | GetRule(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*Rule, error) 1522 | GetMatches(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*Matches, error) 1523 | ResetMatcher(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) 1524 | } 1525 | 1526 | type nlpClient struct { 1527 | cc grpc.ClientConnInterface 1528 | } 1529 | 1530 | func NewNlpClient(cc grpc.ClientConnInterface) NlpClient { 1531 | return &nlpClient{cc} 1532 | } 1533 | 1534 | func (c *nlpClient) LoadModel(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) { 1535 | out := new(TextResponse) 1536 | err := c.cc.Invoke(ctx, "/nlp.Nlp/LoadModel", in, out, opts...) 1537 | if err != nil { 1538 | return nil, err 1539 | } 1540 | return out, nil 1541 | } 1542 | 1543 | func (c *nlpClient) NlpProcess(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*ParsedNLPRes, error) { 1544 | out := new(ParsedNLPRes) 1545 | err := c.cc.Invoke(ctx, "/nlp.Nlp/NlpProcess", in, out, opts...) 1546 | if err != nil { 1547 | return nil, err 1548 | } 1549 | return out, nil 1550 | } 1551 | 1552 | func (c *nlpClient) DocSimilarity(ctx context.Context, in *TextSimilarityRequest, opts ...grpc.CallOption) (*TextSimilarity, error) { 1553 | out := new(TextSimilarity) 1554 | err := c.cc.Invoke(ctx, "/nlp.Nlp/DocSimilarity", in, out, opts...) 1555 | if err != nil { 1556 | return nil, err 1557 | } 1558 | return out, nil 1559 | } 1560 | 1561 | func (c *nlpClient) AddRule(ctx context.Context, in *Rule, opts ...grpc.CallOption) (*TextResponse, error) { 1562 | out := new(TextResponse) 1563 | err := c.cc.Invoke(ctx, "/nlp.Nlp/AddRule", in, out, opts...) 1564 | if err != nil { 1565 | return nil, err 1566 | } 1567 | return out, nil 1568 | } 1569 | 1570 | func (c *nlpClient) RemoveRule(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) { 1571 | out := new(TextResponse) 1572 | err := c.cc.Invoke(ctx, "/nlp.Nlp/RemoveRule", in, out, opts...) 1573 | if err != nil { 1574 | return nil, err 1575 | } 1576 | return out, nil 1577 | } 1578 | 1579 | func (c *nlpClient) GetRule(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*Rule, error) { 1580 | out := new(Rule) 1581 | err := c.cc.Invoke(ctx, "/nlp.Nlp/GetRule", in, out, opts...) 1582 | if err != nil { 1583 | return nil, err 1584 | } 1585 | return out, nil 1586 | } 1587 | 1588 | func (c *nlpClient) GetMatches(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*Matches, error) { 1589 | out := new(Matches) 1590 | err := c.cc.Invoke(ctx, "/nlp.Nlp/GetMatches", in, out, opts...) 1591 | if err != nil { 1592 | return nil, err 1593 | } 1594 | return out, nil 1595 | } 1596 | 1597 | func (c *nlpClient) ResetMatcher(ctx context.Context, in *TextRequest, opts ...grpc.CallOption) (*TextResponse, error) { 1598 | out := new(TextResponse) 1599 | err := c.cc.Invoke(ctx, "/nlp.Nlp/ResetMatcher", in, out, opts...) 1600 | if err != nil { 1601 | return nil, err 1602 | } 1603 | return out, nil 1604 | } 1605 | 1606 | // NlpServer is the server API for Nlp service. 1607 | type NlpServer interface { 1608 | LoadModel(context.Context, *TextRequest) (*TextResponse, error) 1609 | NlpProcess(context.Context, *TextRequest) (*ParsedNLPRes, error) 1610 | DocSimilarity(context.Context, *TextSimilarityRequest) (*TextSimilarity, error) 1611 | AddRule(context.Context, *Rule) (*TextResponse, error) 1612 | RemoveRule(context.Context, *TextRequest) (*TextResponse, error) 1613 | GetRule(context.Context, *TextRequest) (*Rule, error) 1614 | GetMatches(context.Context, *TextRequest) (*Matches, error) 1615 | ResetMatcher(context.Context, *TextRequest) (*TextResponse, error) 1616 | } 1617 | 1618 | // UnimplementedNlpServer can be embedded to have forward compatible implementations. 1619 | type UnimplementedNlpServer struct { 1620 | } 1621 | 1622 | func (*UnimplementedNlpServer) LoadModel(context.Context, *TextRequest) (*TextResponse, error) { 1623 | return nil, status.Errorf(codes.Unimplemented, "method LoadModel not implemented") 1624 | } 1625 | func (*UnimplementedNlpServer) NlpProcess(context.Context, *TextRequest) (*ParsedNLPRes, error) { 1626 | return nil, status.Errorf(codes.Unimplemented, "method NlpProcess not implemented") 1627 | } 1628 | func (*UnimplementedNlpServer) DocSimilarity(context.Context, *TextSimilarityRequest) (*TextSimilarity, error) { 1629 | return nil, status.Errorf(codes.Unimplemented, "method DocSimilarity not implemented") 1630 | } 1631 | func (*UnimplementedNlpServer) AddRule(context.Context, *Rule) (*TextResponse, error) { 1632 | return nil, status.Errorf(codes.Unimplemented, "method AddRule not implemented") 1633 | } 1634 | func (*UnimplementedNlpServer) RemoveRule(context.Context, *TextRequest) (*TextResponse, error) { 1635 | return nil, status.Errorf(codes.Unimplemented, "method RemoveRule not implemented") 1636 | } 1637 | func (*UnimplementedNlpServer) GetRule(context.Context, *TextRequest) (*Rule, error) { 1638 | return nil, status.Errorf(codes.Unimplemented, "method GetRule not implemented") 1639 | } 1640 | func (*UnimplementedNlpServer) GetMatches(context.Context, *TextRequest) (*Matches, error) { 1641 | return nil, status.Errorf(codes.Unimplemented, "method GetMatches not implemented") 1642 | } 1643 | func (*UnimplementedNlpServer) ResetMatcher(context.Context, *TextRequest) (*TextResponse, error) { 1644 | return nil, status.Errorf(codes.Unimplemented, "method ResetMatcher not implemented") 1645 | } 1646 | 1647 | func RegisterNlpServer(s *grpc.Server, srv NlpServer) { 1648 | s.RegisterService(&_Nlp_serviceDesc, srv) 1649 | } 1650 | 1651 | func _Nlp_LoadModel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1652 | in := new(TextRequest) 1653 | if err := dec(in); err != nil { 1654 | return nil, err 1655 | } 1656 | if interceptor == nil { 1657 | return srv.(NlpServer).LoadModel(ctx, in) 1658 | } 1659 | info := &grpc.UnaryServerInfo{ 1660 | Server: srv, 1661 | FullMethod: "/nlp.Nlp/LoadModel", 1662 | } 1663 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1664 | return srv.(NlpServer).LoadModel(ctx, req.(*TextRequest)) 1665 | } 1666 | return interceptor(ctx, in, info, handler) 1667 | } 1668 | 1669 | func _Nlp_NlpProcess_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1670 | in := new(TextRequest) 1671 | if err := dec(in); err != nil { 1672 | return nil, err 1673 | } 1674 | if interceptor == nil { 1675 | return srv.(NlpServer).NlpProcess(ctx, in) 1676 | } 1677 | info := &grpc.UnaryServerInfo{ 1678 | Server: srv, 1679 | FullMethod: "/nlp.Nlp/NlpProcess", 1680 | } 1681 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1682 | return srv.(NlpServer).NlpProcess(ctx, req.(*TextRequest)) 1683 | } 1684 | return interceptor(ctx, in, info, handler) 1685 | } 1686 | 1687 | func _Nlp_DocSimilarity_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1688 | in := new(TextSimilarityRequest) 1689 | if err := dec(in); err != nil { 1690 | return nil, err 1691 | } 1692 | if interceptor == nil { 1693 | return srv.(NlpServer).DocSimilarity(ctx, in) 1694 | } 1695 | info := &grpc.UnaryServerInfo{ 1696 | Server: srv, 1697 | FullMethod: "/nlp.Nlp/DocSimilarity", 1698 | } 1699 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1700 | return srv.(NlpServer).DocSimilarity(ctx, req.(*TextSimilarityRequest)) 1701 | } 1702 | return interceptor(ctx, in, info, handler) 1703 | } 1704 | 1705 | func _Nlp_AddRule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1706 | in := new(Rule) 1707 | if err := dec(in); err != nil { 1708 | return nil, err 1709 | } 1710 | if interceptor == nil { 1711 | return srv.(NlpServer).AddRule(ctx, in) 1712 | } 1713 | info := &grpc.UnaryServerInfo{ 1714 | Server: srv, 1715 | FullMethod: "/nlp.Nlp/AddRule", 1716 | } 1717 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1718 | return srv.(NlpServer).AddRule(ctx, req.(*Rule)) 1719 | } 1720 | return interceptor(ctx, in, info, handler) 1721 | } 1722 | 1723 | func _Nlp_RemoveRule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1724 | in := new(TextRequest) 1725 | if err := dec(in); err != nil { 1726 | return nil, err 1727 | } 1728 | if interceptor == nil { 1729 | return srv.(NlpServer).RemoveRule(ctx, in) 1730 | } 1731 | info := &grpc.UnaryServerInfo{ 1732 | Server: srv, 1733 | FullMethod: "/nlp.Nlp/RemoveRule", 1734 | } 1735 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1736 | return srv.(NlpServer).RemoveRule(ctx, req.(*TextRequest)) 1737 | } 1738 | return interceptor(ctx, in, info, handler) 1739 | } 1740 | 1741 | func _Nlp_GetRule_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1742 | in := new(TextRequest) 1743 | if err := dec(in); err != nil { 1744 | return nil, err 1745 | } 1746 | if interceptor == nil { 1747 | return srv.(NlpServer).GetRule(ctx, in) 1748 | } 1749 | info := &grpc.UnaryServerInfo{ 1750 | Server: srv, 1751 | FullMethod: "/nlp.Nlp/GetRule", 1752 | } 1753 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1754 | return srv.(NlpServer).GetRule(ctx, req.(*TextRequest)) 1755 | } 1756 | return interceptor(ctx, in, info, handler) 1757 | } 1758 | 1759 | func _Nlp_GetMatches_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1760 | in := new(TextRequest) 1761 | if err := dec(in); err != nil { 1762 | return nil, err 1763 | } 1764 | if interceptor == nil { 1765 | return srv.(NlpServer).GetMatches(ctx, in) 1766 | } 1767 | info := &grpc.UnaryServerInfo{ 1768 | Server: srv, 1769 | FullMethod: "/nlp.Nlp/GetMatches", 1770 | } 1771 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1772 | return srv.(NlpServer).GetMatches(ctx, req.(*TextRequest)) 1773 | } 1774 | return interceptor(ctx, in, info, handler) 1775 | } 1776 | 1777 | func _Nlp_ResetMatcher_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 1778 | in := new(TextRequest) 1779 | if err := dec(in); err != nil { 1780 | return nil, err 1781 | } 1782 | if interceptor == nil { 1783 | return srv.(NlpServer).ResetMatcher(ctx, in) 1784 | } 1785 | info := &grpc.UnaryServerInfo{ 1786 | Server: srv, 1787 | FullMethod: "/nlp.Nlp/ResetMatcher", 1788 | } 1789 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 1790 | return srv.(NlpServer).ResetMatcher(ctx, req.(*TextRequest)) 1791 | } 1792 | return interceptor(ctx, in, info, handler) 1793 | } 1794 | 1795 | var _Nlp_serviceDesc = grpc.ServiceDesc{ 1796 | ServiceName: "nlp.Nlp", 1797 | HandlerType: (*NlpServer)(nil), 1798 | Methods: []grpc.MethodDesc{ 1799 | { 1800 | MethodName: "LoadModel", 1801 | Handler: _Nlp_LoadModel_Handler, 1802 | }, 1803 | { 1804 | MethodName: "NlpProcess", 1805 | Handler: _Nlp_NlpProcess_Handler, 1806 | }, 1807 | { 1808 | MethodName: "DocSimilarity", 1809 | Handler: _Nlp_DocSimilarity_Handler, 1810 | }, 1811 | { 1812 | MethodName: "AddRule", 1813 | Handler: _Nlp_AddRule_Handler, 1814 | }, 1815 | { 1816 | MethodName: "RemoveRule", 1817 | Handler: _Nlp_RemoveRule_Handler, 1818 | }, 1819 | { 1820 | MethodName: "GetRule", 1821 | Handler: _Nlp_GetRule_Handler, 1822 | }, 1823 | { 1824 | MethodName: "GetMatches", 1825 | Handler: _Nlp_GetMatches_Handler, 1826 | }, 1827 | { 1828 | MethodName: "ResetMatcher", 1829 | Handler: _Nlp_ResetMatcher_Handler, 1830 | }, 1831 | }, 1832 | Streams: []grpc.StreamDesc{}, 1833 | Metadata: "nlp.proto", 1834 | } 1835 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/yash1994/spacy-go 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/golang/protobuf v1.4.1 7 | google.golang.org/grpc v1.30.0 8 | google.golang.org/protobuf v1.24.0 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 4 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 5 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 6 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 7 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 8 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 9 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 10 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 11 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 12 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 13 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 14 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 15 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 16 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 17 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 18 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 19 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 20 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 21 | github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= 22 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 23 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 24 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 25 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 26 | github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= 27 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 28 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 29 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 30 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 31 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 32 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 33 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 34 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 35 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 36 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 37 | golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= 38 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 39 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 40 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 41 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 42 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 43 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 44 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= 45 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 46 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 47 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 48 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 49 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 50 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 51 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 52 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 53 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 54 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 55 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 56 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 57 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= 58 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 59 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= 60 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 61 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 62 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 63 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 64 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 65 | google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= 66 | google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= 67 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 68 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 69 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 70 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 71 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 72 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 73 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 74 | google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= 75 | google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= 76 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 77 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 78 | -------------------------------------------------------------------------------- /protos/nlp.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package nlp; 4 | 5 | service Nlp { 6 | rpc LoadModel (TextRequest) returns (TextResponse) {} 7 | rpc NlpProcess (TextRequest) returns (ParsedNLPRes) {} 8 | rpc DocSimilarity (TextSimilarityRequest) returns (TextSimilarity) {} 9 | rpc AddRule (Rule) returns (TextResponse) {} 10 | rpc RemoveRule (TextRequest) returns (TextResponse) {} 11 | rpc GetRule (TextRequest) returns (Rule) {} 12 | rpc GetMatches (TextRequest) returns (Matches) {} 13 | rpc ResetMatcher (TextRequest) returns (TextResponse) {} 14 | } 15 | 16 | message TextRequest { 17 | string text = 1; 18 | } 19 | 20 | message TextSimilarityRequest { 21 | string texta = 1; 22 | string textb = 2; 23 | } 24 | 25 | message TextResponse { 26 | string message = 1; 27 | } 28 | 29 | message TextSimilarity { 30 | float similarity = 1; 31 | } 32 | 33 | message Doc { 34 | string text = 1; 35 | string text_with_ws = 2; 36 | bool is_tagged = 3; 37 | bool is_parsed = 4; 38 | bool is_nered = 5; 39 | bool is_sentenced = 6; 40 | } 41 | 42 | message Ent { 43 | int32 start = 1; 44 | int32 end = 2; 45 | string label = 3; 46 | } 47 | 48 | message Sent { 49 | int32 start = 1; 50 | int32 end = 2; 51 | } 52 | 53 | message Noun_chunk { 54 | int32 start = 1; 55 | int32 end = 2; 56 | } 57 | 58 | message Token { 59 | string text = 1; 60 | string text_with_ws = 2; 61 | string whitespace = 3; 62 | string ent_type = 5; 63 | string ent_iob = 6; 64 | string lemma = 7; 65 | string norm = 8; 66 | string lower = 9; 67 | string shape = 10; 68 | string prefix = 11; 69 | string suffix = 12; 70 | string pos = 13; 71 | string tag = 14; 72 | string dep = 15; 73 | bool is_alpha = 16; 74 | bool is_ascii = 17; 75 | bool is_digit = 18; 76 | bool is_lower = 19; 77 | bool is_upper = 20; 78 | bool is_title = 21; 79 | bool is_punct = 22; 80 | bool is_left_punct = 23; 81 | bool is_right_punct = 24; 82 | bool is_space = 25; 83 | bool is_bracket = 26; 84 | bool is_currency = 27; 85 | bool like_url = 28; 86 | bool like_num = 29; 87 | bool like_email = 30; 88 | bool is_oov = 31; 89 | bool is_stop = 32; 90 | bool is_sent_start = 33; 91 | int32 head = 34; 92 | } 93 | 94 | message ParsedNLPRes { 95 | string model = 1; 96 | Doc doc = 2; 97 | repeated Ent ents = 3; 98 | repeated Sent sents = 4; 99 | repeated Noun_chunk noun_chunks = 5; 100 | repeated Token tokens = 6; 101 | } 102 | 103 | message Pattern { 104 | string key = 1; 105 | string value = 2; 106 | } 107 | 108 | message Rule { 109 | string id = 1; 110 | repeated Pattern patterns = 2; 111 | } 112 | 113 | message Match { 114 | string id = 1; 115 | int32 start = 2; 116 | int32 end = 3; 117 | } 118 | 119 | message Matches { 120 | repeated Match matches = 1; 121 | } -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | protobuf 2 | grpcio==1.29.0 3 | grpcio-tools==1.29.0 4 | spacy>=2.1.0 5 | pytest-grpc -------------------------------------------------------------------------------- /spacygo.go: -------------------------------------------------------------------------------- 1 | package spacygo 2 | 3 | import ( 4 | "context" 5 | "log" 6 | "os" 7 | "path" 8 | "time" 9 | 10 | pb "github.com/yash1994/spacy-go/go-stubs" 11 | 12 | "google.golang.org/grpc" 13 | "google.golang.org/grpc/credentials" 14 | ) 15 | 16 | type pattern struct { 17 | key, value string 18 | } 19 | 20 | type rule struct { 21 | id string 22 | patterns []pattern 23 | } 24 | 25 | const ( 26 | serverAddr string = "localhost:50051" 27 | defaultModel string = "en_core_web_sm" 28 | ) 29 | 30 | var grpcConnection *grpc.ClientConn 31 | var grpcConnError error 32 | var grpcClient pb.NlpClient 33 | 34 | // Load : load language model 35 | func Load(modelName string) (r *pb.TextResponse, err error) { 36 | if modelName == "" { 37 | modelName = defaultModel 38 | } 39 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 40 | defer cancel() 41 | 42 | r, err = grpcClient.LoadModel(ctx, &pb.TextRequest{Text: modelName}) 43 | 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | return r, nil 49 | } 50 | 51 | // Nlp : annotate text 52 | func Nlp(text string) (r *pb.ParsedNLPRes, err error) { 53 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 54 | defer cancel() 55 | 56 | r, err = grpcClient.NlpProcess(ctx, &pb.TextRequest{Text: text}) 57 | 58 | if err != nil { 59 | return nil, err 60 | } 61 | return r, nil 62 | } 63 | 64 | // Similarity : compute vector similarity between two texts 65 | func Similarity(texta string, textb string) (r *pb.TextSimilarity, err error) { 66 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 67 | defer cancel() 68 | 69 | r, err = grpcClient.DocSimilarity(ctx, &pb.TextSimilarityRequest{Texta: texta, Textb: textb}) 70 | 71 | if err != nil { 72 | return nil, err 73 | } 74 | return r, nil 75 | } 76 | 77 | // PatternMatch : Match sequences of tokens, based on pattern rules 78 | func PatternMatch(matchrules []rule, text string) (r *pb.Matches, err error) { 79 | for _, mrule := range matchrules { 80 | 81 | var tempRuleArray []*pb.Pattern 82 | 83 | for _, pat := range mrule.patterns { 84 | patpb := &pb.Pattern{Key: pat.key, Value: pat.value} 85 | tempRuleArray = append(tempRuleArray, patpb) 86 | } 87 | rulepb := &pb.Rule{Id: mrule.id, Patterns: tempRuleArray} 88 | 89 | arctx, arcancle := context.WithTimeout(context.Background(), time.Second) 90 | defer arcancle() 91 | 92 | arresp, arerror := grpcClient.AddRule(arctx, rulepb) 93 | 94 | if arerror != nil { 95 | log.Printf("Add rule error: %v", arerror.Error()) 96 | } else { 97 | log.Printf("%v", arresp.GetMessage()) 98 | } 99 | 100 | } 101 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) 102 | defer cancel() 103 | 104 | r, err = grpcClient.GetMatches(ctx, &pb.TextRequest{Text: text}) 105 | 106 | rsctx, rscancel := context.WithTimeout(context.Background(), time.Second) 107 | 108 | resetresp, _ := grpcClient.ResetMatcher(rsctx, &pb.TextRequest{Text: ""}) 109 | defer rscancel() 110 | 111 | if resetresp != nil { 112 | log.Printf("%v", resetresp.GetMessage()) 113 | } 114 | 115 | if err != nil { 116 | return nil, err 117 | } 118 | 119 | return r, nil 120 | 121 | } 122 | 123 | func init() { 124 | 125 | // Set up a connection to the server. 126 | var tslFilePath string 127 | 128 | if _, oserr := os.Stat("server.crt"); oserr == nil { 129 | tslFilePath = "server.crt" 130 | } else { 131 | tslFilePath = path.Join(os.Getenv("GOPATH"), "src/github.com/yash1994/spacy-go/server.crt") 132 | } 133 | 134 | // SSL Credentials 135 | clientCert, err := credentials.NewClientTLSFromFile(tslFilePath, "") 136 | 137 | if err != nil { 138 | log.Fatalf("Could not create client SSL certificate: %v", err) 139 | } 140 | 141 | grpcConnection, grpcConnError = grpc.Dial(serverAddr, grpc.WithTransportCredentials(clientCert), grpc.WithBlock()) 142 | 143 | if grpcConnError != nil { 144 | log.Fatalf("Could not connect to server: %v", grpcConnError) 145 | } 146 | 147 | //defer grpcConnection.Close() 148 | 149 | grpcClient = pb.NewNlpClient(grpcConnection) 150 | 151 | } 152 | -------------------------------------------------------------------------------- /spacygo_test.go: -------------------------------------------------------------------------------- 1 | package spacygo 2 | 3 | import ( 4 | "math" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | func TestLoadModelError(t *testing.T) { 10 | var modelName string = "dummy_model_name" 11 | var errSubs string = "Can't find model 'dummy_model_name'" 12 | r, err := Load(modelName) 13 | 14 | if r == nil { 15 | if strings.Contains(err.Error(), errSubs) { 16 | t.Logf("passed testLoadModelError: %v", errSubs) 17 | } else { 18 | t.Errorf("failed testLoadModelError: %v", err.Error()) 19 | } 20 | } 21 | } 22 | 23 | func TestNlpProcessError(t *testing.T) { 24 | var text string = "This is error test." 25 | var errSubs string = "'NoneType' object is not callable" 26 | r, err := Nlp(text) 27 | 28 | if r == nil { 29 | if strings.Contains(err.Error(), errSubs) { 30 | t.Logf("passed testNlpProcessError: %v", errSubs) 31 | } else { 32 | t.Errorf("failed testNlpProcessError: %v", err.Error()) 33 | } 34 | } 35 | } 36 | 37 | func TestDocSimilarityError(t *testing.T) { 38 | var texta string = "I like apples" 39 | var textb string = "I like oranges" 40 | var errSubs string = "'NoneType' object is not callable" 41 | 42 | r, err := Similarity(texta, textb) 43 | 44 | if r == nil { 45 | if strings.Contains(err.Error(), errSubs) { 46 | t.Logf("passed testDocSimilarityError: %v", errSubs) 47 | } else { 48 | t.Errorf("failed testDocSimilarityError: %v", err.Error()) 49 | } 50 | } 51 | } 52 | 53 | func TestLoadModelDefault(t *testing.T) { 54 | var modelName string = "" 55 | r, err := Load(modelName) 56 | 57 | if r.GetMessage() == "Model loaded 'en_core_web_sm'" { 58 | t.Logf("passed testLoadModelDefault.load: %v == Model loaded 'en_core_web_sm'", r.GetMessage()) 59 | } else { 60 | t.Errorf("failed testLoadModelDefault.load: %v != Model loaded 'en_core_web_sm'", r.GetMessage()) 61 | } 62 | 63 | if err != nil { 64 | t.Errorf("failed testLoadModelDefault: %v", err.Error()) 65 | } 66 | 67 | } 68 | 69 | func TestLoadModel(t *testing.T) { 70 | var modelName string = "en_core_web_sm" 71 | r, err := Load(modelName) 72 | 73 | if r.GetMessage() == "Model loaded 'en_core_web_sm'" { 74 | t.Logf("passed testLoadModel.load: %v == Model loaded 'en_core_web_sm'", r.GetMessage()) 75 | } else { 76 | t.Errorf("failed testLoadModel.load: %v != Model loaded 'en_core_web_sm'", r.GetMessage()) 77 | } 78 | 79 | if err != nil { 80 | t.Errorf("failed testLoadModel: %v", err.Error()) 81 | } 82 | 83 | } 84 | 85 | func TestNlpProcessDoc(t *testing.T) { 86 | var text string = "Apple is looking at buying U.K. startup for $1 billion" 87 | r, err := Nlp(text) 88 | 89 | if r.GetDoc().GetText() == text { 90 | t.Logf("passed testNlpProcess.doc.text: %v == %v", r.GetDoc().GetText(), text) 91 | } else { 92 | t.Errorf("failed testNlpProcess.doc.text: %v != %v", r.GetDoc().GetText(), text) 93 | } 94 | 95 | if r.GetDoc().GetTextWithWs() == text { 96 | t.Logf("passed testNlpProcess.doc.text_with_ws: %v == %v", r.GetDoc().GetTextWithWs(), text) 97 | } else { 98 | t.Errorf("failed testNlpProcess.doc.text_with_ws: %v != %v", r.GetDoc().GetTextWithWs(), text) 99 | } 100 | 101 | if r.GetDoc().GetIsTagged() == true { 102 | t.Logf("passed testNlpProcess.doc.is_tagged: %v == %v", r.GetDoc().GetIsTagged(), true) 103 | } else { 104 | t.Errorf("failed testNlpProcess.doc.is_tagged: %v != %v", r.GetDoc().GetIsTagged(), false) 105 | } 106 | 107 | if r.GetDoc().GetIsParsed() == true { 108 | t.Logf("passed testNlpProcess.doc.is_parsed: %v == %v", r.GetDoc().GetIsParsed(), true) 109 | } else { 110 | t.Errorf("failed testNlpProcess.doc.is_parsed: %v != %v", r.GetDoc().GetIsParsed(), false) 111 | } 112 | 113 | if r.GetDoc().GetIsNered() == true { 114 | t.Logf("passed testNlpProcess.doc.is_nered: %v == %v", r.GetDoc().GetIsNered(), true) 115 | } else { 116 | t.Errorf("failed testNlpProcess.doc.is_nered: %v != %v", r.GetDoc().GetIsNered(), false) 117 | } 118 | 119 | if r.GetDoc().GetIsSentenced() == true { 120 | t.Logf("passed testNlpProcess.doc.is_sentenced: %v == %v", r.GetDoc().GetIsSentenced(), true) 121 | } else { 122 | t.Errorf("failed testNlpProcess.doc.is_sentenced: %v != %v", r.GetDoc().GetIsSentenced(), false) 123 | } 124 | 125 | if err != nil { 126 | t.Errorf("failed TestNlpProcessDoc: %v", err.Error()) 127 | } 128 | } 129 | 130 | func TestNlpProcessEnts(t *testing.T) { 131 | var text string = "Apple is looking at buying U.K. startup for $1 billion" 132 | r, err := Nlp(text) 133 | 134 | if r.GetEnts()[0].GetLabel() == "ORG" && r.GetEnts()[0].GetStart() == 0 && r.GetEnts()[0].GetEnd() == 1 { 135 | t.Logf("passed testNlpProcess.ents[0].label_: %v == %v", r.GetEnts()[0].GetLabel(), "ORG") 136 | t.Logf("passed testNlpProcess.ents[0].start: %v == %v", r.GetEnts()[0].GetStart(), 0) 137 | t.Logf("passed testNlpProcess.ents[0].end: %v == %v", r.GetEnts()[0].GetEnd(), 1) 138 | } else { 139 | t.Errorf("failed testNlpProcess.ents[0].label_: %v != %v", r.GetEnts()[0].GetLabel(), "ORG") 140 | t.Errorf("failed testNlpProcess.ents[0].start: %v != %v", r.GetEnts()[0].GetStart(), 0) 141 | t.Errorf("failed testNlpProcess.ents[0].end: %v != %v", r.GetEnts()[0].GetEnd(), 1) 142 | } 143 | 144 | if r.GetEnts()[1].GetLabel() == "GPE" && r.GetEnts()[1].GetStart() == 5 && r.GetEnts()[1].GetEnd() == 6 { 145 | t.Logf("passed testNlpProcess.ents[1].label_: %v == %v", r.GetEnts()[1].GetLabel(), "GPE") 146 | t.Logf("passed testNlpProcess.ents[1].start: %v == %v", r.GetEnts()[1].GetStart(), 5) 147 | t.Logf("passed testNlpProcess.ents[1].end: %v == %v", r.GetEnts()[1].GetEnd(), 6) 148 | } else { 149 | t.Errorf("failed testNlpProcess.ents[1].label_: %v != %v", r.GetEnts()[1].GetLabel(), "GPE") 150 | t.Errorf("failed testNlpProcess.ents[1].start: %v != %v", r.GetEnts()[1].GetStart(), 5) 151 | t.Errorf("failed testNlpProcess.ents[1].end: %v != %v", r.GetEnts()[1].GetEnd(), 6) 152 | } 153 | 154 | if err != nil { 155 | t.Errorf("failed TestNlpProcessEnts: %v", err.Error()) 156 | } 157 | } 158 | 159 | func TestNlpProcessSents(t *testing.T) { 160 | var text string = "Systems based on automatically learning the rules can be made more accurate simply by supplying more input data. However, systems based on handwritten rules can only be made more accurate by increasing the complexity of the rules, which is a much more difficult task." 161 | 162 | r, err := Nlp(text) 163 | 164 | if r.GetSents()[0].GetStart() == 0 && r.GetSents()[0].GetEnd() == 19 { 165 | t.Logf("passed testNlpProcess.sents[0].start: %v == %v", r.GetSents()[0].GetStart(), 0) 166 | t.Logf("passed testNlpProcess.sents[0].end: %v == %v", r.GetSents()[0].GetEnd(), 19) 167 | } else { 168 | t.Errorf("failed testNlpProcess.sents[0].start: %v != %v", r.GetSents()[0].GetStart(), 0) 169 | t.Errorf("failed testNlpProcess.sents[0].end: %v != %v", r.GetSents()[0].GetEnd(), 19) 170 | } 171 | 172 | if err != nil { 173 | t.Errorf("failed TestNlpProcessSents: %v", err.Error()) 174 | } 175 | } 176 | 177 | func TestNlpProcessNounChunks(t *testing.T) { 178 | var text string = "Systems based on automatically learning the rules can be made more accurate simply by supplying more input data." 179 | 180 | r, err := Nlp(text) 181 | 182 | if r.GetNounChunks()[0].GetStart() == 0 && r.GetNounChunks()[0].GetEnd() == 1 { 183 | t.Logf("passed testNlpProcess.noun_chunks[0].start: %v == %v", r.GetNounChunks()[0].GetStart(), 0) 184 | t.Logf("passed testNlpProcess.noun_chunks[0].end: %v == %v", r.GetNounChunks()[0].GetEnd(), 1) 185 | } else { 186 | t.Errorf("failed testNlpProcess.noun_chunks[0].start: %v != %v", r.GetNounChunks()[0].GetStart(), 0) 187 | t.Errorf("failed testNlpProcess.noun_chunks[0].end: %v != %v", r.GetNounChunks()[0].GetEnd(), 1) 188 | } 189 | 190 | if r.GetNounChunks()[2].GetStart() == 15 && r.GetNounChunks()[2].GetEnd() == 18 { 191 | t.Logf("passed testNlpProcess.noun_chunks[2].start: %v == %v", r.GetNounChunks()[2].GetStart(), 15) 192 | t.Logf("passed testNlpProcess.noun_chunks[2].end: %v == %v", r.GetNounChunks()[2].GetEnd(), 18) 193 | } else { 194 | t.Errorf("failed testNlpProcess.noun_chunks[2].start: %v != %v", r.GetNounChunks()[2].GetStart(), 15) 195 | t.Errorf("failed testNlpProcess.noun_chunks[2].end: %v != %v", r.GetNounChunks()[2].GetEnd(), 18) 196 | } 197 | 198 | if err != nil { 199 | t.Errorf("failed TestNlpProcessNounChunks: %v", err.Error()) 200 | } 201 | } 202 | 203 | func TestNlpProcessTokens(t *testing.T) { 204 | var text string = "Apple is looking at buying U.K. startup for $1 billion" 205 | r, err := Nlp(text) 206 | 207 | if r.GetTokens()[0].GetText() == "Apple" { 208 | t.Logf("passed testNlpProcess.tokens[0].text: %v == %v", r.GetTokens()[0].GetText(), "Apple") 209 | } else { 210 | t.Errorf("failed testNlpProcess.tokens[0].text: %v != %v", r.GetTokens()[0].GetText(), "Apple") 211 | } 212 | 213 | if r.GetTokens()[0].GetTextWithWs() == "Apple " { 214 | t.Logf("passed testNlpProcess.tokens[0].text_with_ws: %v == %v", r.GetTokens()[0].GetTextWithWs(), "Apple ") 215 | } else { 216 | t.Errorf("failed testNlpProcess.tokens[0].text_with_ws: %v != %v", r.GetTokens()[0].GetTextWithWs(), "Apple ") 217 | } 218 | 219 | if r.GetTokens()[1].GetWhitespace() == " " { 220 | t.Logf("passed testNlpProcess.tokens[1].whitespace_: %v == %v", r.GetTokens()[1].GetWhitespace(), " ") 221 | } else { 222 | t.Errorf("failed testNlpProcess.tokens[1].whitespace_: %v != %v", r.GetTokens()[1].GetWhitespace(), " ") 223 | } 224 | 225 | if r.GetTokens()[1].GetEntType() == "" { 226 | t.Logf("passed testNlpProcess.tokens[1].ent_type_: %v == %v", r.GetTokens()[1].GetEntType(), "") 227 | } else { 228 | t.Errorf("failed testNlpProcess.tokens[1].ent_type_: %v != %v", r.GetTokens()[1].GetEntType(), "") 229 | } 230 | 231 | if r.GetTokens()[2].GetEntIob() == "O" { 232 | t.Logf("passed testNlpProcess.tokens[2].ent_iob_: %v == %v", r.GetTokens()[2].GetEntIob(), "O") 233 | } else { 234 | t.Errorf("failed testNlpProcess.tokens[2].ent_iob_: %v != %v", r.GetTokens()[2].GetEntIob(), "O") 235 | } 236 | 237 | if r.GetTokens()[2].GetLemma() == "look" { 238 | t.Logf("passed testNlpProcess.tokens[2].lemma_: %v == %v", r.GetTokens()[2].GetLemma(), "look") 239 | } else { 240 | t.Errorf("failed testNlpProcess.tokens[2].lemma_: %v != %v", r.GetTokens()[2].GetLemma(), "look") 241 | } 242 | 243 | if r.GetTokens()[2].GetNorm() == "looking" { 244 | t.Logf("passed testNlpProcess.tokens[2].norm_: %v == %v", r.GetTokens()[2].GetNorm(), "looking") 245 | } else { 246 | t.Errorf("failed testNlpProcess.tokens[2].norm_: %v != %v", r.GetTokens()[2].GetNorm(), "looking") 247 | } 248 | 249 | if r.GetTokens()[3].GetLower() == "at" { 250 | t.Logf("passed testNlpProcess.tokens[3].lower_: %v == %v", r.GetTokens()[3].GetLower(), "at") 251 | } else { 252 | t.Errorf("failed testNlpProcess.tokens[3].lower_: %v != %v", r.GetTokens()[3].GetLower(), "at") 253 | } 254 | 255 | if r.GetTokens()[3].GetShape() == "xx" { 256 | t.Logf("passed testNlpProcess.tokens[3].shape_: %v == %v", r.GetTokens()[3].GetShape(), "xx") 257 | } else { 258 | t.Errorf("failed testNlpProcess.tokens[3].shape_: %v != %v", r.GetTokens()[3].GetShape(), "xx") 259 | } 260 | 261 | if r.GetTokens()[3].GetPrefix() == "a" { 262 | t.Logf("passed testNlpProcess.tokens[3].prefix_: %v == %v", r.GetTokens()[3].GetPrefix(), "a") 263 | } else { 264 | t.Errorf("failed testNlpProcess.tokens[3].prefix_: %v != %v", r.GetTokens()[3].GetPrefix(), "a") 265 | } 266 | 267 | if r.GetTokens()[3].GetSuffix() == "at" { 268 | t.Logf("passed testNlpProcess.tokens[3].suffix_: %v == %v", r.GetTokens()[3].GetSuffix(), "at") 269 | } else { 270 | t.Errorf("failed testNlpProcess.tokens[3].suffix_: %v != %v", r.GetTokens()[3].GetSuffix(), "at") 271 | } 272 | 273 | if r.GetTokens()[4].GetPos() == "VERB" { 274 | t.Logf("passed testNlpProcess.tokens[4].pos_: %v == %v", r.GetTokens()[4].GetPos(), "VERB") 275 | } else { 276 | t.Errorf("failed testNlpProcess.tokens[4].pos_: %v != %v", r.GetTokens()[4].GetPos(), "VERB") 277 | } 278 | 279 | if r.GetTokens()[4].GetTag() == "VBG" { 280 | t.Logf("passed testNlpProcess.tokens[4].tag_: %v == %v", r.GetTokens()[4].GetTag(), "VBG") 281 | } else { 282 | t.Errorf("failed testNlpProcess.tokens[4].tag_: %v != %v", r.GetTokens()[4].GetTag(), "VBG") 283 | } 284 | 285 | if r.GetTokens()[4].GetDep() == "pcomp" { 286 | t.Logf("passed testNlpProcess.tokens[4].dep_: %v == %v", r.GetTokens()[4].GetDep(), "pcomp") 287 | } else { 288 | t.Errorf("failed testNlpProcess.tokens[4].dep_: %v != %v", r.GetTokens()[4].GetDep(), "pcomp") 289 | } 290 | 291 | if r.GetTokens()[4].GetIsAlpha() == true { 292 | t.Logf("passed testNlpProcess.tokens[4].is_alpha: %v == %v", r.GetTokens()[4].GetIsAlpha(), true) 293 | } else { 294 | t.Errorf("failed testNlpProcess.tokens[4].is_alpha: %v != %v", r.GetTokens()[4].GetIsAlpha(), true) 295 | } 296 | 297 | if r.GetTokens()[4].GetIsAscii() == true { 298 | t.Logf("passed testNlpProcess.tokens[4].is_ascii: %v == %v", r.GetTokens()[4].GetIsAscii(), true) 299 | } else { 300 | t.Errorf("failed testNlpProcess.tokens[4].is_ascii: %v != %v", r.GetTokens()[4].GetIsAscii(), true) 301 | } 302 | 303 | if r.GetTokens()[5].GetIsDigit() == false { 304 | t.Logf("passed testNlpProcess.tokens[5].is_digit: %v == %v", r.GetTokens()[5].GetIsDigit(), false) 305 | } else { 306 | t.Errorf("failed testNlpProcess.tokens[5].is_digit: %v != %v", r.GetTokens()[5].GetIsDigit(), false) 307 | } 308 | 309 | if r.GetTokens()[5].GetIsLower() == false { 310 | t.Logf("passed testNlpProcess.tokens[5].is_lower: %v == %v", r.GetTokens()[5].GetIsLower(), false) 311 | } else { 312 | t.Errorf("failed testNlpProcess.tokens[5].is_lower: %v != %v", r.GetTokens()[5].GetIsLower(), false) 313 | } 314 | 315 | if r.GetTokens()[5].GetIsUpper() == true { 316 | t.Logf("passed testNlpProcess.tokens[5].is_upper: %v == %v", r.GetTokens()[5].GetIsUpper(), true) 317 | } else { 318 | t.Errorf("failed testNlpProcess.tokens[5].is_upper: %v != %v", r.GetTokens()[5].GetIsUpper(), true) 319 | } 320 | 321 | if r.GetTokens()[5].GetIsTitle() == true { 322 | t.Logf("passed testNlpProcess.tokens[5].is_title: %v == %v", r.GetTokens()[5].GetIsTitle(), true) 323 | } else { 324 | t.Errorf("failed testNlpProcess.tokens[5].is_title: %v != %v", r.GetTokens()[5].GetIsTitle(), true) 325 | } 326 | 327 | if r.GetTokens()[5].GetIsPunct() == false { 328 | t.Logf("passed testNlpProcess.tokens[5].is_punct: %v == %v", r.GetTokens()[5].GetIsPunct(), false) 329 | } else { 330 | t.Errorf("failed testNlpProcess.tokens[5].is_punct: %v != %v", r.GetTokens()[5].GetIsPunct(), false) 331 | } 332 | 333 | if r.GetTokens()[5].GetIsLeftPunct() == false { 334 | t.Logf("passed testNlpProcess.tokens[5].is_left_punct: %v == %v", r.GetTokens()[5].GetIsLeftPunct(), false) 335 | } else { 336 | t.Errorf("failed testNlpProcess.tokens[5].is_left_punct: %v != %v", r.GetTokens()[5].GetIsLeftPunct(), false) 337 | } 338 | 339 | if r.GetTokens()[6].GetIsRightPunct() == false { 340 | t.Logf("passed testNlpProcess.tokens[6].is_right_punct: %v == %v", r.GetTokens()[6].GetIsRightPunct(), false) 341 | } else { 342 | t.Errorf("failed testNlpProcess.tokens[6].is_right_punct: %v != %v", r.GetTokens()[6].GetIsRightPunct(), false) 343 | } 344 | 345 | if r.GetTokens()[6].GetIsSpace() == false { 346 | t.Logf("passed testNlpProcess.tokens[6].is_space: %v == %v", r.GetTokens()[6].GetIsSpace(), false) 347 | } else { 348 | t.Errorf("failed testNlpProcess.tokens[6].is_space: %v != %v", r.GetTokens()[6].GetIsSpace(), false) 349 | } 350 | 351 | if r.GetTokens()[6].GetIsBracket() == false { 352 | t.Logf("passed testNlpProcess.tokens[6].is_bracket: %v == %v", r.GetTokens()[6].GetIsBracket(), false) 353 | } else { 354 | t.Errorf("failed testNlpProcess.tokens[6].is_bracket: %v != %v", r.GetTokens()[6].GetIsBracket(), false) 355 | } 356 | 357 | if r.GetTokens()[6].GetIsCurrency() == false { 358 | t.Logf("passed testNlpProcess.tokens[6].is_currency: %v == %v", r.GetTokens()[6].GetIsCurrency(), false) 359 | } else { 360 | t.Errorf("failed testNlpProcess.tokens[6].is_currency: %v != %v", r.GetTokens()[6].GetIsCurrency(), false) 361 | } 362 | 363 | if r.GetTokens()[6].GetLikeUrl() == false { 364 | t.Logf("passed testNlpProcess.tokens[6].like_url: %v == %v", r.GetTokens()[6].GetLikeUrl(), false) 365 | } else { 366 | t.Errorf("failed testNlpProcess.tokens[6].like_url: %v != %v", r.GetTokens()[6].GetLikeUrl(), false) 367 | } 368 | 369 | if r.GetTokens()[6].GetLikeNum() == false { 370 | t.Logf("passed testNlpProcess.tokens[6].like_num: %v == %v", r.GetTokens()[6].GetLikeNum(), false) 371 | } else { 372 | t.Errorf("failed testNlpProcess.tokens[6].like_num: %v != %v", r.GetTokens()[6].GetLikeNum(), false) 373 | } 374 | 375 | if r.GetTokens()[6].GetLikeEmail() == false { 376 | t.Logf("passed testNlpProcess.tokens[6].like_email: %v == %v", r.GetTokens()[6].GetLikeEmail(), false) 377 | } else { 378 | t.Errorf("failed testNlpProcess.tokens[6].like_email: %v != %v", r.GetTokens()[6].GetLikeEmail(), false) 379 | } 380 | 381 | if r.GetTokens()[7].GetIsOov() == true { 382 | t.Logf("passed testNlpProcess.tokens[7].is_oov: %v == %v", r.GetTokens()[7].GetIsOov(), true) 383 | } else { 384 | t.Errorf("failed testNlpProcess.tokens[7].is_oov: %v != %v", r.GetTokens()[7].GetIsOov(), true) 385 | } 386 | 387 | if r.GetTokens()[7].GetIsStop() == true { 388 | t.Logf("passed testNlpProcess.tokens[7].is_stop: %v == %v", r.GetTokens()[7].GetIsStop(), true) 389 | } else { 390 | t.Errorf("failed testNlpProcess.tokens[7].is_stop: %v != %v", r.GetTokens()[7].GetIsStop(), true) 391 | } 392 | 393 | if r.GetTokens()[8].GetIsSentStart() == false { 394 | t.Logf("passed testNlpProcess.tokens[8].is_sent_start: %v == %v", r.GetTokens()[8].GetIsSentStart(), false) 395 | } else { 396 | t.Errorf("failed testNlpProcess.tokens[8].is_sent_start: %v != %v", r.GetTokens()[8].GetIsSentStart(), false) 397 | } 398 | 399 | if r.GetTokens()[8].GetHead() == 10 { 400 | t.Logf("passed testNlpProcess.tokens[8].head.i: %v == %v", r.GetTokens()[8].GetHead(), 10) 401 | } else { 402 | t.Errorf("failed testNlpProcess.tokens[8].head.i: %v != %v", r.GetTokens()[8].GetHead(), 10) 403 | } 404 | 405 | if err != nil { 406 | t.Errorf("failed TestNlpProcessTokens: %v", err.Error()) 407 | } 408 | } 409 | 410 | func TestDocSimilarity(t *testing.T) { 411 | var texta string = "I like apples" 412 | var textb string = "I like oranges" 413 | var actualSimi float64 = 0.837 414 | var tolerance float64 = 0.001 415 | r, err := Similarity(texta, textb) 416 | 417 | if math.Abs(float64(r.GetSimilarity())-actualSimi) < tolerance { 418 | t.Logf("passed TestDocSimilarity: %v ~= %v", r.GetSimilarity(), actualSimi) 419 | } else { 420 | t.Errorf("failed TestDocSimilarity: %v", r.GetSimilarity()) 421 | } 422 | 423 | if err != nil { 424 | t.Errorf("failed TestDocSimilarity: %v", err.Error()) 425 | } 426 | } 427 | 428 | func TestMatcher(t *testing.T) { 429 | var testRules []rule 430 | var testRule rule 431 | testRule.id = "HelloWorld" 432 | var testPattern1, testPattern2 pattern 433 | testPattern1.key = "LOWER" 434 | testPattern1.value = "hello" 435 | testPattern2.key = "LOWER" 436 | testPattern2.value = "world" 437 | 438 | testRule.patterns = append(testRule.patterns, testPattern1, testPattern2) 439 | testRules = append(testRules, testRule) 440 | 441 | r, err := PatternMatch(testRules, "HELLO WORLD on Google Maps.") 442 | 443 | if r.GetMatches()[0].GetStart() == 0 { 444 | t.Logf("passed patternMatch.matches[0].start: %v == %v", r.GetMatches()[0].GetStart(), 0) 445 | } else { 446 | t.Errorf("failed patternMatch.matches[0].start: %v != %v", r.GetMatches()[0].GetStart(), 0) 447 | } 448 | 449 | if r.GetMatches()[0].GetEnd() == 2 { 450 | t.Logf("passed patternMatch.matches[0].end: %v == %v", r.GetMatches()[0].GetEnd(), 2) 451 | } else { 452 | t.Errorf("failed patternMatch.matches[0].end: %v != %v", r.GetMatches()[0].GetEnd(), 2) 453 | } 454 | 455 | if err != nil { 456 | t.Errorf("failed TestMatcher: %v", err.Error()) 457 | } 458 | 459 | } 460 | 461 | func TestMatcherError(t *testing.T) { 462 | var testRules []rule 463 | var text string = "This is error test." 464 | var errSubs string = "'NoneType' object is not callable" 465 | r, err := PatternMatch(testRules, text) 466 | 467 | if r == nil { 468 | if strings.Contains(err.Error(), errSubs) { 469 | t.Logf("passed testMatcherError: %v", errSubs) 470 | } else { 471 | t.Errorf("failed testMatcherError: %v", err.Error()) 472 | } 473 | } 474 | } 475 | 476 | func TestMatcherEmptyRuleError(t *testing.T) { 477 | var testRules []rule 478 | var testRule1, testRule2 rule 479 | testRule1.id = "HelloWorld1" 480 | testRule2.id = "HelloWorld2" 481 | 482 | var testPattern1 pattern 483 | testPattern1.key = "LOWER" 484 | testPattern1.value = "hello" 485 | 486 | testRule1.patterns = append(testRule1.patterns, testPattern1) 487 | testRules = append(testRules, testRule1, testRule2) 488 | 489 | r, err := PatternMatch(testRules, "HELLO WORLD on Google Maps.") 490 | 491 | if r == nil { 492 | t.Errorf("failed testMatcherEmptyRuleError: %v", err.Error()) 493 | } else { 494 | t.Log("passed testMatcherEmptyRuleError") 495 | } 496 | 497 | } 498 | --------------------------------------------------------------------------------