-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature5.py
82 lines (67 loc) · 1.39 KB
/
feature5.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
import nltk
#from feature1 import *
def structuralVariations(words , affectdict , sentidict):
feature = []
tags = nltk.pos_tag(words)
#print tags
try:
feature.append( tags[0][1] )
except:
feature.append('')
try:
feature.append( tags[1][1] )
except:
feature.append('')
try:
feature.append( tags[2][1] )
except:
feature.append('')
try:
feature.append( tags[len(words)-3][1] )
except:
feature.append('')
try:
feature.append( tags[len(words)-2][1] )
except:
feature.append('')
try:
feature.append( tags[len(words)-1][1] )
except:
feature.append('')
flag=0
for i in range (0,len(words)):
if( words[i] in affectdict):
feature.append(i+1)
flag=1
break
if(flag==0):
feature.append(0)
flag=0
for i in range (0,len(words)):
if( words[i] in sentidict):
feature.append(i+1)
flag=1
break
if(flag==0):
feature.append(0)
hashtags_part1 =0
hashtags_part2=0
hashtags_part3 =0
for i in range(0,len(words)):
#print words[i]
if(words[i][0]=='#'):
if(i< len(words)/3):
hashtags_part1=hashtags_part1+1
elif(i<( len(words)*2)/3):
hashtags_part2=hashtags_part2+1
else:
hashtags_part3=hashtags_part3+1
#trisecting the number of hashtags
feature.append(hashtags_part1)
feature.append(hashtags_part1)
feature.append(hashtags_part1)
#print feature
return feature
#a = []
#b = []
#structuralVariations(["hello" , "bye" ],a,b)