-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml_to_larctag.py
28 lines (24 loc) · 1.02 KB
/
xml_to_larctag.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
import glob
import sys
from os.path import basename
from dump_speaker_data import rewriter
from util.talkbank_parser import MorParser
def xml_to_tagfile(filename):
parser = MorParser("{http://www.talkbank.org/ns/talkbank}")
corpus = parser.parse(filename)
for speaker, tokens in corpus:
yield speaker, [rewriter(t) for t in tokens]
if __name__ == "__main__":
files = sorted(glob.glob("/home/paul/corpora/Brown/Eve/*.xml"))
for xmlfile in files:
sys.stderr.write(xmlfile + "\n")
outf = ('data/MOT-%s' % basename(xmlfile)).rstrip('.xml') + '.txt'
print outf
with open(outf, 'w') as fh:
for speaker, words in xml_to_tagfile(xmlfile):
if speaker != "MOT":
continue
# with open('larc-tagged-output-mother.txt', 'w') as fh:
fh.write(" ".join(["{0}/{1}".format(
pair[0] if pair[0] else 'XXX', pair[1].upper() if pair[1] else 'YYY')
for pair in words]) + "\n")