A => .gitignore +5 -0
@@ 1,5 @@
+.venv
+__pycache__
+
+knapsack_example.geojson
+
A => python/Makefile +12 -0
@@ 1,12 @@
+clean:
+ rm -rf .venv
+ rm -rf **/__pycache__ **/*.pyc
+
+.venv:
+ python -m venv .venv
+ (. .venv/bin/activate; pip install --upgrade pip)
+ (. .venv/bin/activate; pip install afinn)
+
+run:
+ (. .venv/bin/activate; python -m main)
+
A => python/main.py +19 -0
@@ 1,19 @@
+#!/usr/bin/env python
+
+import afinn
+
+def score_many(it):
+ model = afinn.Afinn()
+ yield from ((elem, model.score(elem), ) for elem in it)
+
+def main():
+ sentences = [
+ 'This is utterly excellent!',
+ 'How dare you',
+ ]
+ for sentence, score in score_many(sentences):
+ print(f'"{sentence}" -> {score}')
+
+if __name__ == '__main__':
+ main()
+