-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentiment-analyzer.py
40 lines (30 loc) · 1018 Bytes
/
sentiment-analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# Author: Alexandre Tea <alexandre.qtea@gmail.com>
# File: /Users/alexandretea/Work/sentiment-analysis/sentiment-analyzer.py
# Purpose: TODO (a one-line explanation)
# Created: 2016-09-11 18:07:59
# Modified: 2016-09-12 21:11:58
import sys
import argparse
import nltk
import nlp.sentiment as sentiment
__doc__ = """
This script can be used to classify a sentence as positive or negative.
It has to be trained with datasets from file with the following format:
0|1 sentence newline
Example:
1 I love Python
0 Gary is my enemy
"""
def run(args):
analyzer = sentiment.Analyzer(args.training_datasets)
analyzer.run_cli()
def main():
nltk.download("punkt")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("training_datasets", type=str, nargs="+",
help="path to training data sets")
args = parser.parse_args(sys.argv[1:])
run(args)
if __name__ == "__main__":
main()