-
Notifications
You must be signed in to change notification settings - Fork 0
/
adj.py
119 lines (99 loc) · 2.09 KB
/
adj.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from nltk.tokenize import word_tokenize,sent_tokenize
from pattern.en import sentiment
from nltk.tag import pos_tag
from nltk.corpus import wordnet as wn
import json
import urllib.request as urllib2
import requests
from pattern.en import *
import string
# from nltk.corpus import words
adj_dic={}
file=open("quan.txt","r")
adj_dic["quan"]=file.read().split()
file=open("middle.txt","r")
adj_dic["middle"]=file.read().split()
file=open("obs.txt","r")
adj_dic["obs"]=file.read().split()
file=open("size.txt","r")
adj_dic["size"]=file.read().split()
file=open("shape.txt","r")
adj_dic["shape"]=file.read().split()
file=open("age.txt","r")
adj_dic["age"]=file.read().split()
file=open("color.txt","r")
adj_dic["color"]=file.read().split()
file=open("origin.txt","r")
adj_dic["origin"]=file.read().split()
file=open("mat.txt","r")
adj_dic["mat"]=file.read().split()
val={}
val["quan"]=0
val["middle"]=0.5
val["obs"]=1
val["size"]=2
val["age"]=3
val["shape"]=4
val["color"]=5
val["origin"]=6
val["mat"]=7
des={}
des[0]="quan"
des[0.5]="middle"
des[1]="obs"
des[2]="size"
des[3]="age"
des[4]="shape"
des[5]="color"
des[6]="origin"
des[7]="mat"
adject=[]
dic={}
for i,j in adj_dic.items():
adject=adject+[wb.lower() for wb in j]
for word in j:
dic[word.lower()]=val[i]
# print(adject)
# print(dic)
# print(dic["very"])
# words_dic=[i.lower() for i in words.words()]
sentences = sent_tokenize(input())
# print(sentences)
for sent in sentences:
# sent = sent.translate(str.maketrans('', '', string.punctuation))
# sent = sent.replace(",","")
words = tag(sent)
lS = len(words)
ans=[]
# print(words)
pr=[]
for i in range(lS):
(w,t)=words[i]
wt=w
w=w.lower()
if(w in adject):
pr.append((dic[w],wt))
else:
pr.sort()
if(len(pr)!=0):
for j in pr:
ans.append(j[1])
pr=[]
# ans=ans+pr
# else:
ans.append(wt)
pr.sort()
if(len(pr)!=0):
for j in pr:
ans.append(j[1])
pr=[]
ln=len(ans)
s=""
for i in range(ln):
if(i==ln-1 or ans[i+1]=="," or ans[i+1]=="." or ans[i+1]=="?" or ans[i+1]=="!"):
s+=ans[i]
else:
s+=ans[i]
s+=" "
print(s,end=" ")
print()