~dricottone/afinn-demo

866aea929caa0cb9910f6d5e8e1365e7ebc54d78 — Dominic Ricottone 1 year, 3 days ago
Initial commit
3 files changed, 36 insertions(+), 0 deletions(-)

A .gitignore
A python/Makefile
A python/main.py
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()