-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
64 lines (53 loc) · 1.1 KB
/
eval.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
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
import string
exclude = set(string.punctuation)
print exclude
exclude.union(set(['\t',' ','\n']))
import re
tweets = []
for j in xrange(4):
x1 = raw_input()
x1 = int(x1)
tweets1 = []
for i in xrange(x1):
y1 = raw_input()
y1 = ''.join(ch for ch in str(y1) if ch not in exclude)
y1 = re.sub(' +',' ',y1)
tweets1 += [str(y1)]
tweets += [ tweets1 ]
print tweets
score={}
score[0]=0
score[1]=0
score[2]=0
score[3]=0
for i in xrange(4):
st = [0,1,2,3]
st.remove(i)
for k in st:
for j in tweets[i]:
overall = 0.00
for l in tweets[k]:
occ = 0.0
for tw1 in j.split(' '):
cur = 0.0
for tw2 in l.split(' '):
cur += similar(tw1,tw2)
# cur /= len(l.split(' '))
occ += cur
occ = occ/(len(l.split(' ')*len(j.split(' '))))
if overall < occ:
overall = occ
score[i] += overall
total = 0
for i in score:
base = 0
for j in tweets[i]:
base += len(j.split(' '))
score[i] = score[i]/base
total += score[i]
for i in score:
score[i] /= total
print score