Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Twitter corpus; random changes from last week
- Loading branch information
Showing
9 changed files
with
300 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import nltk | ||
import string | ||
import random | ||
|
||
def load(sample=True): | ||
CONJUNCTIONS = ["and", "but", "or"] | ||
|
||
f = open("Sentiment Analysis Dataset.csv") | ||
lines = f.readlines() | ||
#lines = lines[:1000] | ||
f.close() | ||
if sample: | ||
lines = random.sample(lines, 10000) | ||
ids = [] | ||
tweets = [] | ||
labels = [] | ||
for line in lines[1:]: | ||
line = line.replace("\"", "").strip() | ||
line2 = "" | ||
for c in line: | ||
if ord(c) < 128: line2 += c | ||
terms = line2.split(",") | ||
id = terms[0] | ||
label = int(terms[1]) | ||
if label == 0: label = -1 | ||
tweet = terms[3] | ||
ids.append(id) | ||
tweets.append(nltk.word_tokenize(tweet)) | ||
labels.append(label) | ||
return (ids, tweets, labels) |
Oops, something went wrong.