Skip to content
This repository was archived by the owner on Dec 28, 2018. It is now read-only.

Commit ae16afb

Browse files
committed
Hash implementation!
1 parent 526d29d commit ae16afb

File tree

2 files changed

+6119
-0
lines changed

2 files changed

+6119
-0
lines changed

hash.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os,csv
2+
3+
def hashtag(words):
4+
feature =[]
5+
hashtags_part1 =0
6+
hashtags_part2=0
7+
hashtags_part3 =0
8+
for i in range(0,len(words)):
9+
if(words[i].startswith('#')):
10+
if(i< len(words)/3):
11+
hashtags_part1=hashtags_part1+1
12+
elif(i<( len(words)*2)/3):
13+
hashtags_part2=hashtags_part2+1
14+
else:
15+
hashtags_part3=hashtags_part3+1
16+
feature.append(hashtags_part1)
17+
feature.append(hashtags_part2)
18+
feature.append(hashtags_part3)
19+
return feature
20+
21+
22+
def writeFile(folder,csvfile):
23+
f5 = csv.writer(csvfile,delimiter=",")
24+
for f in sorted(os.listdir(folder)):
25+
inputFile = open(os.path.join(folder,f),"r")
26+
reader= list(csv.reader(inputFile))
27+
tweet = reader[1][2]
28+
f5.writerow(hashtag(tweet.split(" ")))
29+
inputFile.close()
30+
31+
32+
33+
34+
def main():
35+
pwd = os.getcwd()
36+
norm = pwd + "/normal_with_past"
37+
sarc = pwd + "/sarcastic_with_past"
38+
csvfile = open("hash5.csv","w")
39+
writeFile(norm,csvfile)
40+
writeFile(sarc,csvfile)
41+
csvfile.close()
42+
43+
44+
if __name__=="__main__":
45+
main()

0 commit comments

Comments
 (0)