Skip to content

Commit

Permalink
Merge pull request #108 from ambivalentno/master
Browse files Browse the repository at this point in the history
Covered a case when all words have a zero score.
  • Loading branch information
aboSamoor committed Jul 24, 2017
2 parents ddb0f88 + fe9c37c commit 560f048
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions polyglot/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def polarity(self):
"""Return the polarity score as a float within the range [-1.0, 1.0]
"""
scores = [w.polarity for w in self.words if w.polarity != 0]
if not scores:
return 0.0
return sum(scores) / float(len(scores))

@cached_property
Expand Down

0 comments on commit 560f048

Please sign in to comment.