-
Notifications
You must be signed in to change notification settings - Fork 86
/
apply_review.py
executable file
·123 lines (90 loc) · 3.12 KB
/
apply_review.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2016, 2017, 2018 Guenter Bartsch
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# apply review-result.csv file to transcripts
#
import os
import sys
import logging
import readline
import atexit
import traceback
from time import time
from optparse import OptionParser
from StringIO import StringIO
from nltools import misc
from nltools.phonetics import ipa2xsampa
from nltools.tokenizer import tokenize
from speech_lexicon import Lexicon
from speech_transcripts import Transcripts
#
# init
#
misc.init_app ('apply_reviews')
config = misc.load_config ('.speechrc')
#
# command line
#
parser = OptionParser("usage: %prog corpus foo.csv [bar.csv ...])")
parser.add_option ("-l", "--lang", dest="lang", type = "str", default='de',
help="language (default: de)")
parser.add_option ("-f", "--force", action="store_true", dest="force",
help="force: apply quality rating also on already reviewed entries")
parser.add_option ("-v", "--verbose", action="store_true", dest="verbose",
help="enable debug output")
(options, args) = parser.parse_args()
if len(args)<2:
parser.print_help()
sys.exit(1)
if options.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
corpus = args[0]
#
# load lexicon, transcripts
#
logging.info("loading transcripts...")
transcripts = Transcripts(corpus_name=corpus)
logging.info("loading transcripts...done.")
#
# main
#
cnt = 0
for csvfn in args[1:]:
logging.info ("applying results from %s ..." % csvfn)
with open(csvfn, 'r') as csvf:
for line in csvf:
parts = line.strip().split(';')
if len(parts) != 2:
logging.error ('failed to parse line:' % line)
sys.exit(1)
utt_id = parts[0]
quality = int(parts[1])
if transcripts[utt_id]['quality'] != 0:
if not options.force:
logging.warn ('skipping %s because it is already rated.' % utt_id)
continue
transcripts[utt_id]['quality'] = quality
transcripts[utt_id]['ts'] = u' '.join(tokenize(transcripts[utt_id]['prompt'], lang=options.lang, keep_punctuation=True))
cnt += 1
logging.info ('results applied to %d transcripts.' % cnt)
logging.info("saving transcripts...")
transcripts.save()
logging.info("saving transcripts...done.")