Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
BigData/MPQALexicon.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 lines (25 sloc)
897 Bytes
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
from nltk.corpus import wordnet as wn | |
def load(strong_only=False): | |
filename = "subjclueslen1-HLTEMNLP05.tff" | |
f = open(filename) | |
lines = f.readlines() | |
f.close() | |
words = [] | |
labels = [] | |
for line in lines: | |
fields = line.split(" ") | |
fields = [field for field in fields if "=" in field] #ugh, two lines have a random extra char in them | |
d = dict([field.rstrip().split("=") for field in fields]) | |
(word, label, pos, type) = d["word1"], d["priorpolarity"], d["pos1"], d["type"] | |
if word not in words: | |
if is_adjective(word): | |
if not (strong_only and (type != "strongsubj")): | |
if label == "positive": | |
words.append(word) | |
labels.append(1) | |
elif label == "negative": | |
words.append(word) | |
labels.append(-1) | |
return (words, labels) | |
def is_adjective(word): | |
return (len(wn.synsets(word, wn.ADJ)) > 0) |