Skip to content

Commit

Permalink
Escape discourse and speaker names for getting acoustics
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcauliffe committed Jul 25, 2019
1 parent f93181a commit 6c6a715
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions polyglotdb/corpus/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def generate_filter_string(discourse, begin, end, channel, num_points, kwargs):
end += time_step / 2
time_step *= 1000
filter_string += '\ngroup by time({}ms) fill(null)'.format(int(time_step))
discourse = discourse.replace("'", r"\'")
filter_string = filter_string.format(discourse, s_to_nano(begin), s_to_nano(end), channel)
return filter_string

Expand Down Expand Up @@ -708,6 +709,8 @@ def get_utterance_acoustics(self, acoustic_name, utterance_id, discourse, speake
properties = [x[0] for x in self.hierarchy.acoustic_properties[acoustic_name]]
property_names = ["{}".format(x) for x in properties]
columns = '"time", {}'.format(', '.join(property_names))
speaker = speaker.replace("'", r"\'") # Escape apostrophes
discourse = discourse.replace("'", r"\'") # Escape apostrophes
query = '''select {} from "{}"
WHERE "utterance_id" = '{}'
AND "discourse" = '{}'
Expand Down Expand Up @@ -949,6 +952,7 @@ def discourse_has_acoustics(self, acoustic_name, discourse):
"""
if acoustic_name not in self.hierarchy.acoustics:
return False
discourse = discourse.replace("'", r"\'")
query = '''select * from "{}" WHERE "discourse" = '{}' LIMIT 1;'''.format(acoustic_name, discourse)
result = self.execute_influxdb(query)
if len(result) == 0:
Expand Down Expand Up @@ -1216,6 +1220,7 @@ def relativize_acoustic_measure(self, acoustic_name, by_speaker=True, by_phone=F
for measure, (mean_name, sd_name) in aliases.items():
summary_data[(k[1]['speaker'], measure)] = v[0][mean_name], v[0][sd_name]
for s in self.speakers:
s = s.replace("'", r"\'")
all_query = '''select * from "{acoustic_type}"
where "phone" != '' and "speaker" = '{speaker}';'''.format(acoustic_type=acoustic_name, speaker=s)
all_results = client.query(all_query)
Expand Down Expand Up @@ -1284,6 +1289,8 @@ def reassess_utterances(self, acoustic_name):
self.utterance.begin.column_name('begin'),
self.utterance.end.column_name('end'))
utterances = q.all()
s = s.replace("'", r"\'")
discourse_name = discourse_name.replace("'", r"\'")
all_query = '''select * from "{}"
where "phone" != '' and
"discourse" = '{}' and
Expand Down

0 comments on commit 6c6a715

Please sign in to comment.