]> git.somenet.org - pub/jan/aic18.git/blob - service-analysis/README.md
small changes in readme
[pub/jan/aic18.git] / service-analysis / README.md
1 # Sentiment Service
2
3
4 ## API
5 Provides a REST-API to get the average sentiment of a given list of texts
6 The service uses the the sentiment analysis service indico.
7
8 `GET`: `/` Displays the expected input for a POST
9
10 `POST`: `/` Calculates the average sentiment for a given list of texts
11 - param: Term[] as Content-Tye: `application/json`
12 example body of request:
13 ```json
14 [
15         {
16                 'text': 'sample text 1',
17         },
18         {       
19                 'text': 'sample text 2',
20         },
21         {       
22                 'text': 'sample text 3',
23         }
24 ]
25 ```
26 JSON string may contain more value-key pairs than 'text', but 'text' is needed for the sentiment analysis. Everything else will be ignored.
27 For more examples see curl commands in local -> commands.
28
29 ## API errors
30 - `409`: input string does not meet specifications
31 - `503`: indico sentiment analysis not available
32
33 ## external services
34 This sentiment analysis service uses and relies on the online sentiment analysis indico ([https://www.indico.io]).
35 The api key can be set in the file indico_api_key.txt. The current key does work, however excessive use of this service will require you to provide your own key, since the amount of requests for this key is limited.
36
37 ## run with docker
38 - `docker build -t sentiment_analysis .`
39 - `docker container run -d -p YOUR_PORT:8081 sentiment_analysis`
40
41 ## run local
42 ### requirements
43 - python 3.7
44 pip:
45 - indicoio
46 - flask
47 - flask_restful
48 ### commands
49 - `python3.7 sentiment_analysis.py`
50 - positive sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"happy birthday, i love you"}]'`
51 - negative sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"i hate you, please die"}]'`
52   
53 ## health check
54 Under http://localhost:8081/health the service returns HTTP Status 200 if it is running OK.
55 ### commans
56 curl -v -X GET http://localhost:8081/health