Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #9 (negate_sequence bug) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions info.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def negate_sequence(text):
pprev = prev
prev = negated

if any(neg in word for neg in ["not", "n't", "no"]):
if stripped in ["not", "cannot", "no"] or stripped.endswith("n't"):
negation = not negation

if any(c in word for c in delims):
Expand All @@ -59,7 +59,7 @@ def negate_sequence(text):
def train():
global pos, neg, totals
retrain = False

# Load counts if they already exist.
if not retrain and os.path.isfile(CDATA_FILE):
pos, neg, totals = cPickle.load(open(CDATA_FILE))
Expand All @@ -74,12 +74,12 @@ def train():
for word in set(negate_sequence(open("./aclImdb/train/neg/" + file).read())):
neg[word] += 1
pos['not_' + word] += 1

prune_features()

totals[0] = sum(pos.values())
totals[1] = sum(neg.values())

countdata = (pos, neg, totals)
cPickle.dump(countdata, open(CDATA_FILE, 'w'))

Expand All @@ -104,7 +104,7 @@ def classify2(text):

def classify_demo(text):
words = set(word for word in negate_sequence(text) if word in pos or word in neg)
if (len(words) == 0):
if (len(words) == 0):
print "No features to compare on"
return True

Expand Down