NLTK sentiment vader: ordering results
<p>I've just run the Vader sentiment analysis on my dataset: </p>

<pre><code>from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk import tokenize
sid = SentimentIntensityAnalyzer()
for sentence in filtered_lines2:
    print(sentence)
    ss = sid.polarity_scores(sentence)
    for k in sorted(ss):
        print('{0}: {1}, '.format(k, ss[k]), )
        print()
</code></pre>

<p>Here a sample of my results:</p>

<pre><code>Are these guests on Samsung and Google event mostly Chinese Wow Theyre
boring 

Google Samsung 

('compound: 0.3612, ',)

()

('neg: 0.12, ',)

()


('neu: 0.681, ',)


()


('pos: 0.199, ',)


()

 Adobe lose 135bn to piracy Report 


('compound: -0.4019, ',)


()


('neg: 0.31, ',)


()


('neu: 0.69, ',)


()


('pos: 0.0, ',)


()

Samsung Galaxy Nexus announced

('compound: 0.0, ',)

()

('neg: 0.0, ',)

()

('neu: 1.0, ',)

()

('pos: 0.0, ',)

()
</code></pre>

<p>I want to know how many times "compound" is equal, greater or less than zero.</p>

<p>I know that probably it is very easy but I'm really new to Python and coding in general.
I've tried in a lot of different ways to create what I need but I can't find any solution. </p>

<p>(please edit my question if the "sample of results" is incorrect, because i don't know the right way to write it)</p>

<p>I might define a function that returns the type of inequality that's being represented by a document:</p>

<pre><code>def inequality_type(val):
  if val == 0.0: 
      return "equal"
  elif val &gt; 0.0: 
      return "greater"
  return "less"
</code></pre>

<p>Then use this on the compound scores of all the sentences to increment the count of the corresponding inequality type.</p>

<pre><code>from collections import defaultdict

def count_sentiments(sentences):
    # Create a dictionary with values defaulted to 0
    counts = defaultdict(int)

    # Create a polarity score for each sentence
    for score in map(sid.polarity_scores, sentences):
        # Increment the dictionary entry for that inequality type
        counts[inequality_type(score["compound"])] += 1

    return counts
</code></pre>

<p>You could then call it on your filtered lines.</p>

<p>However, this can be obviated by just using <code>collections.Counter</code>:</p>

<pre><code>from collections import Counter

def count_sentiments(sentences):
    # Count the inequality type for each score in the sentences' polarity scores
    return Counter((inequality_type(score["compound"]) for score in map(sid.polarity_scores, sentences)))
</code></pre>

python python-3.x nltk