StanfordNLP.parse()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 5
rs 9.4285
1
import json
2
#from jsonrpc import ServerProxy, JsonRpc20, TransportTcpIp
3
import requests
4
5
class StanfordNLP:
6
    def __init__(self, port_number=9000):
7
        self.server = "http://localhost:%d" % port_number
8
9
    def parse(self, text):
10
        r = requests.post(self.server, params={'properties' : '{"annotators": "tokenize,ssplit,pos,lemma,ner,parse", "outputFormat": "json", "parse.flags": " -makeCopulaHead"}'}, data=text.encode('utf8'))
11
        result = r.json()['sentences'][0]
12
        result['text'] = text
13
        return result
14
15
nlp = StanfordNLP()
16
17
if __name__ == "__main__":
18
    while(True):
19
        line=input("")
20
        result = nlp.parse(line)
21
        print(result)
22