diff --git a/sample-functions/SentimentAnalysis/Dockerfile b/sample-functions/SentimentAnalysis/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d46f4d25473a5ebc3c2e58978065b98662215642 --- /dev/null +++ b/sample-functions/SentimentAnalysis/Dockerfile @@ -0,0 +1,17 @@ +FROM python:2.7-alpine +RUN pip install textblob +RUN python -m textblob.download_corpora + +ADD https://github.com/alexellis/faas/releases/download/0.5.1-alpha/fwatchdog /usr/bin +RUN chmod +x /usr/bin/fwatchdog + +WORKDIR /root/ + +COPY handler.py . + +ENV fprocess="python handler.py" + +HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] + diff --git a/sample-functions/SentimentAnalysis/build.sh b/sample-functions/SentimentAnalysis/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..c3d66b76f1f6ff6a5fed98c43541825672267091 --- /dev/null +++ b/sample-functions/SentimentAnalysis/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +echo "Building functions/sentimentanalysis" +docker build -t functions/sentimentanalysis . + + diff --git a/sample-functions/SentimentAnalysis/handler.py b/sample-functions/SentimentAnalysis/handler.py new file mode 100644 index 0000000000000000000000000000000000000000..707640e6b8ab2bb20cd1db1c8b2c90970169948c --- /dev/null +++ b/sample-functions/SentimentAnalysis/handler.py @@ -0,0 +1,17 @@ +import sys +from textblob import TextBlob + +def get_stdin(): + buf = "" + for line in sys.stdin: + buf = buf + line + return buf + +if(__name__ == "__main__"): + st = get_stdin() + blob = TextBlob(st) + out ="" + for sentence in blob.sentences: + out = out + "Polarity: " + str(sentence.sentiment.polarity) + " Subjectivity: " + str(sentence.sentiment.subjectivity) + "\n" + print(out) +