]> git.somenet.org - pub/jan/aic18.git/blob - service-analysis/README.md
issue #49 for service analysis: indico api key is now in a .env file. readmes, docker...
[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 `GET`: `/health` Returns HTTP Status 200 if service is running
11
12 `POST`: `/` Calculates the average sentiment for a given list of texts using the online sentiment analysis tool indico (https://www.indico.io).
13 - param: Term[ ] as Content-Tye: `application/json`
14 example body of request:
15 ```json
16 [
17         {
18                 'text': 'sample text 1',
19         },
20         {       
21                 'text': 'sample text 2',
22         },
23         {       
24                 'text': 'sample text 3',
25         }
26 ]
27 ```
28 `POST`: `/offline_analysis` Calculates the average sentiment for a given list of texts using TextBlob (https://textblob.readthedocs.io)
29 - param:  Term[ ] as Content-Tye: `application/json`
30 example body of request:
31 ```json
32 [
33         {
34                 'text': 'sample text 1',
35         },
36         {       
37                 'text': 'sample text 2',
38         },
39         {       
40                 'text': 'sample text 3',
41         }
42 ]
43 ```
44 JSON string may contain more value-key pairs than 'text', but 'text' is needed for the sentiment analysis. Everything else will be ignored.
45 For more examples see curl commands in local -> commands.
46
47 ## API errors
48 - `409`: input string does not meet specifications
49 - `503`: indico sentiment analysis not available
50
51 ## external services
52 This sentiment analysis service uses the online sentiment analysis indico (https://www.indico.io).
53 The indico api key can be set in the file `analysis.env`. 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.
54 In case of an 503 error, you can use the `/offline_analysis`.
55
56 ## run with docker
57 - `docker build -t sentiment_analysis .`
58 - `docker container run --env-file=analysis.env -d -p YOUR_PORT:8081 sentiment_analysis`
59
60 ## run local
61 ### requirements
62 - python 3.7
63 - pip: indicoio
64 - pip: flask
65 - pip: flask_restful
66 - pip: textblob
67 ### commands
68 - `python3.7 sentiment_analysis.py` to start the service
69 - positive online sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"happy birthday, i love you"}]'`
70 - negative online sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081 -d '[{"text":"i hate you, please die"}]'`
71 - positive offline sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081/offline_analysis -d '[{"text":"happy birthday, i love you"}]'`
72 - negative offline sentiment test example: `curl -v -H 'content-type: application/json' -X POST http://localhost:8081/offline_analysis -d '[{"text":"i hate you, please die"}]'`
73 - health check test example: `curl -v -X GET http://localhost:8081/health`