예제 #1
0
def pattern_assessor(x, *args):
    from pattern.web import plaintext
    from pattern.en import polarity, subjectivity
    key = args[0]
    pt = plaintext(x)
    sss = {}
    sss.update({'polarity': polarity(pt), 'subjectivity': subjectivity(pt)})
    #return sss[key]
    return sss
예제 #2
0
 def test_subjectivity(self):
     # Assert that en.subjectivity() yields en.sentiment()[1].
     s = "A great day!"
     self.assertTrue(en.subjectivity(s) == en.sentiment(s)[1])
     print("pattern.en.subjectivity()")
예제 #3
0
 def test_subjectivity(self):
     # Assert that en.subjectivity() yields en.sentiment()[1].
     s = "A great day!"
     self.assertTrue(en.subjectivity(s) == en.sentiment(s)[1])
     print "pattern.en.subjectivity()"
print conjugate('purred', '3sg')
print PAST in tenses('purred') # 'p' in tenses() also works.
print (PAST, 1, PL) in tenses('purred') 

print 'Quantification'

print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken'])
print quantify('carrot', amount=90)
print quantify({'carrot': 100, 'parrot': 20})

print 'ngrams'
print ngrams("I am eating a pizza.", n=2)


#parse
s = parse('I eat pizza with a fork.')
pprint(s)

#tag
for word, t in tag('The cat felt happy.'):
    print word +' is ' +t     
    
s = "The movie attempts to be surreal by incorporating various time paradoxes, but it's presented in such a ridiculous way it's seriously boring."    
print sentiment(s)     
print polarity(s)
print subjectivity(s)

#The modality() function returns a value between -1.0 and +1.0, expressing the degree of certainty
s2 = "Some amino acids tend to be acidic while others may be basic." # weaseling
se = Sentence(parse(s, chunks=False, lemmata=True))
print modality(se)
ACCESS_TOKEN_KEY = '----'
ACCESS_TOKEN_SECRET = '---'

api = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN_KEY,
                 ACCESS_TOKEN_SECRET)
r = api.request('statuses/filter', {
    'track': TRACK_TERM,
    'locations': TRACK_LOC
})

### MongoDB Calling
client = MongoClient("mongodb://127.0.0.1:3001/meteor")
db = client['meteor']

for item in r.get_iterator():
    if 'text' in item:
        a = item['text']
        p = polarity(a)
        s = subjectivity(a)
        if (p != 0.0):
            post = {
                "track": "newyork",
                "tweet": a,
                "tweetdate": datetime.datetime.utcnow(),
                "polarity": p,
                "subjectivity": s
            }
            db.tweets_newyork.insert_one(post).inserted_id
            print("NewYork")
            #print(a)
예제 #6
0
# It contains adjectives that occur frequently in customer reviews,
# hand-tagged with values for polarity and subjectivity.

# The polarity() function measures positive vs. negative, as a number between -1.0 and +1.0.
# The subjectivity() function measures objective vs. subjective, as a number between 0.0 and 1.0.
# The sentiment() function returns an averaged (polarity, subjectivity)-tuple for a given string.
for word in ("amazing", "horrible", "public"):
    print word, sentiment(word)

text = "The movie attempts to be surreal by incorporating time travel and various time paradoxes, but it's presented in such a ridiculous way it's seriously boring."
print
print sentiment(text) 
print 
print polarity(text)
print 
print subjectivity(text)

# The input string can be:
# - a string, 
# - a Synset (see pattern.en.wordnet), 
# - a parsed Sentence, Text, Chunk or Word (see pattern.en),
# - a Document (see pattern.vector).

# The positive() function returns True if the string's polarity >= threshold.
# The threshold can be lowered or raised, 
# but overall for strings with multiple words +0.1 yields the best results.
print
print "good:", positive("good", threshold=0.1)
print " bad:", positive("bad")
print
예제 #7
0
print lemma('running')
print conjugate('purred', '3sg')
print PAST in tenses('purred')  # 'p' in tenses() also works.
print(PAST, 1, PL) in tenses('purred')

print 'Quantification'

print quantify(['goose', 'goose', 'duck', 'chicken', 'chicken', 'chicken'])
print quantify('carrot', amount=90)
print quantify({'carrot': 100, 'parrot': 20})

print 'ngrams'
print ngrams("I am eating a pizza.", n=2)

#parse
s = parse('I eat pizza with a fork.')
pprint(s)

#tag
for word, t in tag('The cat felt happy.'):
    print word + ' is ' + t

s = "The movie attempts to be surreal by incorporating various time paradoxes, but it's presented in such a ridiculous way it's seriously boring."
print sentiment(s)
print polarity(s)
print subjectivity(s)

#The modality() function returns a value between -1.0 and +1.0, expressing the degree of certainty
s2 = "Some amino acids tend to be acidic while others may be basic."  # weaseling
se = Sentence(parse(s, chunks=False, lemmata=True))
print modality(se)
예제 #8
0
# It contains adjectives that occur frequently in customer reviews,
# hand-tagged with values for polarity and subjectivity.

# The polarity() function measures positive vs. negative, as a number between -1.0 and +1.0.
# The subjectivity() function measures objective vs. subjective, as a number between 0.0 and 1.0.
# The sentiment() function returns an averaged (polarity, subjectivity)-tuple for a given string.
for word in ("amazing", "horrible", "public"):
    print word, sentiment(word)

text = "The movie attempts to be surreal by incorporating time travel and various time paradoxes, but it's presented in such a ridiculous way it's seriously boring."
print
print sentiment(text)
print
print polarity(text)
print
print subjectivity(text)

# The input string can be:
# - a string,
# - a Synset (see pattern.en.wordnet),
# - a parsed Sentence, Text, Chunk or Word (see pattern.en),
# - a Document (see pattern.vector).

# The positive() function returns True if the string's polarity >= threshold.
# The threshold can be lowered or raised,
# but overall for strings with multiple words +0.1 yields the best results.
print
print "good:", positive("good", threshold=0.1)
print " bad:", positive("bad")
print