Esempio n. 1
0
def noun_subjectivity(noun):
    import src.im2text.data as data
    subjclues = data.subjectivity_clues()
    entry = subjclues.get((lemmatize(noun, wn.NOUN), 'noun'), None)
    if entry:
        return 'strong' if entry.type.startswith('strong') else 'weak'
    else:
        return None
Esempio n. 2
0
def verb_subjectivity(verb, synonym_threshold=3):
    import src.im2text.data as data
    subjclues = data.subjectivity_clues()
    entry = subjclues.get((lemmatize(verb, wn.VERB), 'verb'), None)
    if entry is not None:
        return 'strong' if entry['type'].startswith('strong') else 'weak'
    entries = [subjclues.get((synonym, 'verb'), None) 
               for synonym in synonyms(verb)]
    subjs = [None if not entry else entry['type'] for entry in entries]
    # at least 2 synonyms are in subj lexicon, then we consider the word as subjective
    if len(filter(lambda e: e is not None, subjs)) >= synonym_threshold:
        if any(itertools.imap(lambda s: s and s.startswith('strong'), subjs)):
            return 'strong'
        elif any(itertools.imap(lambda s: s and s.startswith('weak'), subjs)):
            return 'weak'
    return None
Esempio n. 3
0
def get_subjclue(word, pos):
    def word_type(pos):
        if pos.startswith('VB'):
            return 'verb'
        elif pos.startswith('NN'):
            return 'noun'
        elif pos.startswith('JJ'):
            return 'adj'
        elif pos.startswith('RB'):
            return 'adverb'
        else:
            return 'other'
    
    import src.im2text.data as data
    subjclues = data.subjectivity_clues()
    lemma = lemmatize(word, pos)
    entry = subjclues.get((lemma, word_type(pos)), None)
    if entry:
        return entry
    else:
        entry = subjclues.get((lemma, 'anypos'), None)
        return entry