-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
44 lines (35 loc) · 1.1 KB
/
test.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
from sys import argv
import re
from nltk.stem.porter import *
from nltk.corpus import wordnet as wn
"""
script, option, file_name, search_word = argv
def findword(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
if option == "-f":
file_content = open(file_name, 'r').read()
file_sentence = file_content.split(".")
for sentence in file_sentence:
if findword(search_word)(sentence) != None:
print sentence
script, option, file_name = argv
stemmer = PorterStemmer()
if option == "-f":
file_content = open(file_name, 'r').read()
file_sentence = file_content.split(".")
for sentence in file_sentence:
sentence = sentence.split(" ")
single_sentence = [stemmer.stem(sentenc) for sentenc in sentence]
print single_sentence
for i,j in enumerate(wn.synsets('custom')):
print "Synonyms:", ", ".join(j.lemma_names())
t = []
for i,j in enumerate(wn.synsets('custom')):
name = j.lemma_names()
for each_name in name:
if each_name not in t:
t.append(each_name)
print t
"""
for i,j in enumerate(wn.synsets('life')):
print "Synonyms:", i ,", ".join(j.lemma_names())