-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
65 lines (55 loc) · 1.86 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import cherrypy
from nltk.corpus import wordnet as wn
import nltk
#nltk.download() #MAKE SURE THIS COMMAND RUN FOR ONE TIME
from nltk.stem.wordnet import WordNetLemmatizer
import spacy
import inflect
class HelloJson(object):
@cherrypy.expose
def similarity(self, word1, word2):
try:
# https://stackoverflow.com/questions/45310409/using-a-word2vec-model-pre-trained-on-wikipedia
#modelPath = "./200/model.txt"
# word_vectors = gensim.models.KeyedVectors.load_word2vec_format(modelPath, binary=True)
#w1 = word_vectors['develop_VERB']
#w2 = word_vectors['create_VERB']
#w1 = word_vectors[word1]
#w2 = word_vectors[word2]
#sim = dot(w1, w2) / (norm(w1) * norm(w2))
#print('sim=', sim)
#return str(sim)
return '0'
except:
return '0'
@cherrypy.expose
def type(self, word):
nltk.download('wordnet')
pos = wn.synsets(word)
posString = ''
for p in pos:
posString += p.name().split(".")[1]
return "".join(set(posString))
@cherrypy.expose
def base(self, word):
nltk.download('wordnet')
return WordNetLemmatizer().lemmatize(word,'v')
@cherrypy.expose
def phraseSimilarity(self, phrase1, phrase2):
try:
nlp = spacy.load("en_core_web_lg")
except:
spacy.cli.download("en_core_web_lg")
nlp = spacy.load("en_core_web_lg")
doc1 = nlp(u''+phrase1)
doc2 = nlp(u''+phrase2)
sim = doc1.similarity(doc2)
print(sim)
return str(sim)
@cherrypy.expose
def plural(self, word):
p = inflect.engine()
return p.plural(word)
if __name__ == '__main__':
cherrypy.config.update({'server.socket_port':12311})
cherrypy.quickstart(HelloJson())