Fix get next utterance (by score).
Switch to argparse in annotation_stats.py
This commit is contained in:
parent
6a3819eb0a
commit
626307f135
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import argparse
|
||||||
import redis
|
import redis
|
||||||
from extractor.find_hours import color_hour
|
from extractor.find_hours import color_hour
|
||||||
import pickle
|
import pickle
|
||||||
@ -77,18 +78,42 @@ def print_stats():
|
|||||||
print('Annotated utterances: {}'.format(len(annotated)))
|
print('Annotated utterances: {}'.format(len(annotated)))
|
||||||
|
|
||||||
|
|
||||||
|
def get_args():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
subparser = parser.add_subparsers(dest='cmd')
|
||||||
|
parser_stats = subparser.add_parser('stats', help='Show annotation stats.')
|
||||||
|
parser_investigate = subparser.add_parser(
|
||||||
|
'investigate', help='investigate cookie.')
|
||||||
|
parser_investigate.add_argument('cookie', help='User cookie string')
|
||||||
|
parser_index = subparser.add_parser('index', help='Print utterance.')
|
||||||
|
parser_index.add_argument('index', type=int, help='Utterance index')
|
||||||
|
subparser.add_parser('ipdb', help='Get into ipdb.')
|
||||||
|
parser_exec = subparser.add_parser('exec', help='Execute redis command.')
|
||||||
|
parser_exec.add_argument(
|
||||||
|
'redis_command',
|
||||||
|
help=
|
||||||
|
'Redis command (lowercased). e.g. to get r.zrangebyscore("key", "-inf", "inf", start=0, num=1) pass \'zrangebyscore("key", "-inf", "inf", start=0, num=1)\''
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if sys.argv[1] == 'stats':
|
args = get_args()
|
||||||
|
if args.cmd == 'stats':
|
||||||
print_stats()
|
print_stats()
|
||||||
elif sys.argv[1] == 'investigate':
|
elif args.cmd == 'investigate':
|
||||||
investigate_by_cookie(sys.argv[2])
|
investigate_by_cookie(args.cookie)
|
||||||
elif sys.argv[1] == 'index':
|
elif args.cmd == 'index':
|
||||||
pprint_utterance(int(sys.argv[2]))
|
pprint_utterance(args.index)
|
||||||
elif sys.argv[1] == 'console':
|
elif args.cmd == 'ipdb':
|
||||||
import ipdb
|
import ipdb
|
||||||
ipdb.set_trace()
|
ipdb.set_trace()
|
||||||
elif sys.argv[1] == 'exec':
|
elif args.cmd == 'exec':
|
||||||
exec('print(r.{})'.format(sys.argv[2]), {'print': print, 'r': r})
|
exec('print(r.{})'.format(args.redis_command), {
|
||||||
|
'print': print,
|
||||||
|
'r': r
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -65,13 +65,13 @@ def get_next(cookie_hash):
|
|||||||
"""returns utterance with minmum annotations if that utterance
|
"""returns utterance with minmum annotations if that utterance
|
||||||
wasn't annotated by cookie_hash user
|
wasn't annotated by cookie_hash user
|
||||||
or not yet annotated utterance by cookie_hash user"""
|
or not yet annotated utterance by cookie_hash user"""
|
||||||
index = int(r.zrangebyscore(UTT_SCORES, '-inf', 'inf')[1])
|
index = int(r.zrangebyscore(UTT_SCORES, '-inf', 'inf', start=0, num=1)[0])
|
||||||
if r.exists(f'{cookie_hash}:{index}'):
|
if r.exists(f'{cookie_hash}:{index}'):
|
||||||
index = find_not_annotated(cookie_hash)
|
index = find_not_annotated(cookie_hash)
|
||||||
log('found unannotated index: {}'.format(index))
|
log('found unannotated index: {}'.format(index))
|
||||||
left_context, hour, right_context = get_utterance_for_web(index)
|
left_context, hour, right_context = get_utterance_for_web(index)
|
||||||
# log('get_next index: {}, score: {}'.format(index,
|
log('get_next index: {}, score: {}'.format(index,
|
||||||
# r.zscore(UTT_SCORES, index)))
|
r.zscore(UTT_SCORES, index)))
|
||||||
return index, left_context, hour, right_context
|
return index, left_context, hour, right_context
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user