forked from sudhof/politeness
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
executable file
·76 lines (64 loc) · 2.36 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import argparse
def _train(args):
classifier = Classifier()
classifier.train(args.documents, args.ntesting)
def _predict(args):
classifier = Classifier(verbose=True)
classifier.predict(args.documents)
def _download(args):
from politeness.data.download import download
download()
def _set_corenlp_url(args):
from politeness import helpers
if args.list:
print(helpers.get_corenlp_url())
else:
helpers.set_corenlp_url(args.url)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Command line access to the Stanford Politeness API. '
)
subparsers = parser.add_subparsers(title='Commands', dest='command')
subparsers.required = True
parser_train = subparsers.add_parser(
'train', help='Train politeness classifier.'
)
parser_train.add_argument(
'-d', '--documents', choices=['all', 'wikipedia', 'stackexchange'],
default='all',
help='Specify whether to train the classifier on the wikipedia '
'documents, the stack-exchange documents, or all documents. '
'Default is all.'
)
parser_train.add_argument(
'-n', '--ntesting', default=500,
help='The number of documents to withhold for testing.'
)
parser_train.set_defaults(handler=_train)
parser_predict = subparsers.add_parser(
'predict', help='Predict politeness of a sentence.'
)
parser_predict.add_argument(
'-f', '--documents',
help='The filepath containing the documents to be classified.'
)
parser_predict.set_defaults(handler=_predict)
parser_download = subparsers.add_parser(
'download', help='Download training data.'
)
parser_download.set_defaults(handler=_download)
parser_url = subparsers.add_parser(
'url', help='Set the URL for the Stanford CoreNLP Server.'
)
parser_url.add_argument(
'-u', '--url', help='The URL for a CoreNLP Server.'
)
parser_url.add_argument(
'-l', '--list', action='store_true',
help='Show the currently saved URL.'
)
parser_url.set_defaults(handler=_set_corenlp_url)
args = parser.parse_args()
from politeness.classifier import Classifier
args.handler(args)