forked from MontrealCorpusTools/SPADE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.py
More file actions
26 lines (19 loc) · 955 Bytes
/
Copy pathimport.py
File metadata and controls
26 lines (19 loc) · 955 Bytes
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
from polyglotdb import CorpusContext
import polyglotdb.io as pgio
from polyglotdb.query.base.func import Count, Average
corpus_root = '/home/mlipari/spade-SOTC/audio_and_transcripts'
corpus_name = 'spade-SOTC'
# Import
parser = pgio.inspect_labbcat(corpus_root)
parser.call_back = print
with CorpusContext(corpus_name) as c:
c.reset()
print('IMPORT...')
c.load(parser, corpus_root)
print('Speakers:', c.speakers)
print('Discourses:', c.discourses)
# Optional: Use order_by to enforce ordering on the output for easier comparison with the sample output.
q = c.query_graph(c.phone).order_by(c.phone.label).group_by(c.phone.label.column_name('phone'))
results = q.aggregate(Count().column_name('count'), Average(c.phone.duration).column_name('average_duration'))
for r in results:
print('The phone {} had {} occurrences and an average duration of {}.'.format(r['phone'], r['count'], r['average_duration']))