StanfordNLP   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 9
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 2 1
A parse() 0 5 1
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