You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/12/08 12:12:26 UTC

[kibble-scanners] branch master updated (387628a -> 047075c)

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git.


    from 387628a  bump the limit from 1 email to 100 per scan at max
     new 0d3300b  add support for picoAPI sentiment analysis
     new 047075c  weave picoAPI into pm-tone

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/plugins/scanners/ponymail-tone.py |  6 ++--
 src/plugins/utils/tone.py             | 63 +++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@kibble.apache.org" <co...@kibble.apache.org>'].

[kibble-scanners] 01/02: add support for picoAPI sentiment analysis

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git

commit 0d3300b0eeba4e89a001d6aa01b1ed73e409c02a
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Dec 8 13:11:05 2017 +0100

    add support for picoAPI sentiment analysis
    
    The more the merrier
---
 src/plugins/utils/tone.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/plugins/utils/tone.py b/src/plugins/utils/tone.py
index 9c26809..631bbb9 100644
--- a/src/plugins/utils/tone.py
+++ b/src/plugins/utils/tone.py
@@ -133,4 +133,67 @@ def azureTone(KibbleBit, bodies):
                 KibbleBit.pprint("Possible rate limiting in place, stopping for now.")
                 return False
         return moods
+    
+def picoTone(KibbleBit, bodies):
+    """ Sentiment analysis using picoAPI Text Analysis """
+    if 'picoapi' in KibbleBit.config:
+        headers = {
+            'Content-Type': 'application/json',
+            'PicoAPI-Key': KibbleBit.config['picoapi']['key']
+        }
+        
+        
+        js = {
+            "texts": []
+          }
+        
+        # For each body...
+        a = 0
+        moods = []
+        for body in bodies:
+            # Crop out quotes
+            lines = body.split("\n")
+            body = "\n".join([x for x in lines if not x.startswith(">")])
+            doc = {
+                "id": str(a),
+                "body": body
+              }
+            js['texts'].append(doc)
+            moods.append({}) # placeholder for each doc, to be replaced
+            a += 1
+        try:
+            rv = requests.post(
+                "https://v1.picoapi.com/api/text/sentiment",
+                headers = headers,
+                data = json.dumps(js)
+            )
+            jsout = rv.json()
+        except:
+            jsout = {} # borked sentiment analysis?
+        
+        if 'results' in jsout and len(jsout['results']) > 0:
+            for doc in jsout['results']:
+                mood = {}
+                # This is more parred than Watson, so we'll split it into three groups: positive, neutral and negative.
+                # Divide into four segments, 0->40%, 25->75% and 60->100%.
+                # 0-40 promotes negative, 60-100 promotes positive, and 25-75% promotes neutral.
+                # As we don't want to over-represent negative/positive where the results are
+                # muddy, the neutral zone is larger than the positive/negative zones by 10%.
+                val = (1 + doc['sentiment']) / 2 # This ranges from -1 to +1, so we'll just harmonize that to 0->1 and use the azure calcs
+                
+                mood['negative'] = max(0, ((0.4 - val) * 2.5)) # For 40% and below, use 2½ distance
+                mood['positive'] = max(0, ((val-0.6) * 2.5)) # For 60% and above, use 2½ distance
+                mood['neutral'] = max(0, 1 - (abs(val - 0.5) * 2)) # Between 25% and 75% use double the distance to middle.
+                moods[int(doc['id'])] = mood # Replace moods[X] with the actual mood
+                
+        else:
+            KibbleBit.pprint("Failed to analyze email body.")
+            print(jsout)
+            # 403 returned on invalid key, 429 on rate exceeded.
+            # If we see a code return, let's just stop for now.
+            # Later scans can pick up the slack.
+            if 'code' in jsout:
+                KibbleBit.pprint("Possible rate limiting in place, stopping for now.")
+                return False
+        return moods
     
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.

[kibble-scanners] 02/02: weave picoAPI into pm-tone

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git

commit 047075c36a092bd8363a0486bb4b6927ad4825b9
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Dec 8 13:12:02 2017 +0100

    weave picoAPI into pm-tone
---
 src/plugins/scanners/ponymail-tone.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/plugins/scanners/ponymail-tone.py b/src/plugins/scanners/ponymail-tone.py
index 5d62920..98b3124 100644
--- a/src/plugins/scanners/ponymail-tone.py
+++ b/src/plugins/scanners/ponymail-tone.py
@@ -62,8 +62,8 @@ def scan(KibbleBit, source):
         KibbleBit.updateSource(source)
         return
     
-    if not 'watson' in KibbleBit.config and not 'azure' in KibbleBit.config:
-        KibbleBit.pprint("No Watson/Azure creds configured, skipping tone analyzer")
+    if not 'watson' in KibbleBit.config and not 'azure' in KibbleBit.config and not 'picoapi' in KibbleBit.config:
+        KibbleBit.pprint("No Watson/Azure/picoAPI creds configured, skipping tone analyzer")
         return
     
     cookie = None
@@ -122,6 +122,8 @@ def scan(KibbleBit, source):
             moods = plugins.utils.tone.watsonTone(KibbleBit, bodies)
         elif 'azure' in KibbleBit.config:
             moods = plugins.utils.tone.azureTone(KibbleBit, bodies)
+        elif 'picoapi' in KibbleBit.config:
+            moods = plugins.utils.tone.picoTone(KibbleBit, bodies)
         if moods == False:
             KibbleBit.pprint("Hit rate limit, not trying further emails for now.")
             

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.