mirror of
				https://github.com/gsi-upm/senpy
				synced 2025-11-04 01:08:16 +00:00 
			
		
		
		
	First version for PyPi
This commit is contained in:
		@@ -1,2 +1,3 @@
 | 
				
			|||||||
Flask==0.10.1
 | 
					Flask==0.10.1
 | 
				
			||||||
gunicorn==19.0.0
 | 
					gunicorn==19.0.0
 | 
				
			||||||
 | 
					requests==2.4.1
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@
 | 
				
			|||||||
#    See the License for the specific language governing permissions and
 | 
					#    See the License for the specific language governing permissions and
 | 
				
			||||||
#    limitations under the License.
 | 
					#    limitations under the License.
 | 
				
			||||||
'''
 | 
					'''
 | 
				
			||||||
Simple Sentiment Analysis server for EUROSENTIMENT
 | 
					Simple Sentiment Analysis server
 | 
				
			||||||
'''
 | 
					'''
 | 
				
			||||||
from flask import Blueprint, render_template, request, jsonify, current_app
 | 
					from flask import Blueprint, render_template, request, jsonify, current_app
 | 
				
			||||||
import config
 | 
					import config
 | 
				
			||||||
@@ -42,6 +42,9 @@ PARAMS = {"input": {"aliases": ["i", "input"],
 | 
				
			|||||||
                        "required": False,
 | 
					                        "required": False,
 | 
				
			||||||
                        "options": ["json-ld"],
 | 
					                        "options": ["json-ld"],
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
 | 
					          "algorithm": {"aliases": ["algorithm", "a"],
 | 
				
			||||||
 | 
					                        "required": False,
 | 
				
			||||||
 | 
					                        },
 | 
				
			||||||
          "language": {"aliases": ["language", "l"],
 | 
					          "language": {"aliases": ["language", "l"],
 | 
				
			||||||
                       "required": False,
 | 
					                       "required": False,
 | 
				
			||||||
                       "options": ["es", "en"],
 | 
					                       "options": ["es", "en"],
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										0
									
								
								senpy/plugins/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								senpy/plugins/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										41
									
								
								senpy/plugins/sentiment140.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								senpy/plugins/sentiment140.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					'''
 | 
				
			||||||
 | 
					SENTIMENT140
 | 
				
			||||||
 | 
					=============
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* http://www.sentiment140.com/api/bulkClassifyJson
 | 
				
			||||||
 | 
					* Method: POST
 | 
				
			||||||
 | 
					* Parameters: JSON Object (that is copied to the result)
 | 
				
			||||||
 | 
					    * text
 | 
				
			||||||
 | 
					    * query
 | 
				
			||||||
 | 
					    * language
 | 
				
			||||||
 | 
					    * topic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* Example response:
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{"data": [{"text": "I love Titanic.", "id":1234, "polarity": 4},
 | 
				
			||||||
 | 
					          {"text": "I hate Titanic.", "id":4567, "polarity": 0}]}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					'''
 | 
				
			||||||
 | 
					import requests
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENDPOINT_URI = "http://www.sentiment140.com/api/bulkClassifyJson"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def analyse(texts):
 | 
				
			||||||
 | 
					    parameters = {"data": []}
 | 
				
			||||||
 | 
					    if isinstance(texts, list):
 | 
				
			||||||
 | 
					        for text in texts:
 | 
				
			||||||
 | 
					            parameters["data"].append({"text": text})
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        parameters["data"].append({"text": texts})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    res = requests.post(ENDPOINT_URI, json.dumps(parameters))
 | 
				
			||||||
 | 
					    res.json()
 | 
				
			||||||
 | 
					    return res.json()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test():
 | 
				
			||||||
 | 
					    print analyse("I love Titanic")
 | 
				
			||||||
 | 
					    print analyse(["I love Titanic", "I hate Titanic"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    test()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user