def multiple_unconditional(self, args): """ simple_unconditional, but for phoneme lists. Works exactly the same way, but the domain and codomain are zipped together to create one change per phoneme pair. :param list args: Two phoneme lists. :returns: A Change object. """ domain, codomain = args[0], args[1] ch = ChangeGroup([ change_functions.replace_phonemes(d, c) for d, c in zip(domain, codomain) ]) return ch
def replace_by_feature_conditional(self, args): """ Same as simple_conditional, but for feature expression to phoneme changes. :param list children: The list of change parameters. :returns: A ChangeGroup object. """ changes = [] domain = args[0] default = args[-1] for (codomain, condition) in zip(*[args[1:-1][i::2] for i in range(2)]): base_ch = self.replace_by_feature([domain, codomain]) cond_ch = self.basic_conditional([base_ch, condition]) changes.append(cond_ch) changes.append(self.replace_by_feature([domain, default])) return ChangeGroup(changes)
def multiple_conditional(self, children): """ Same as simple_conditional, but for phoneme list to phoneme list changes. :param list children: The list of change parameters. :returns: A ChangeGroup object. """ changes = [] domain = children[0] default = children[-1] for (codomain, condition) in zip(*[children[1:-1][i::2] for i in range(2)]): ch = self.multiple_unconditional([domain, codomain]) ch = ch.when(condition) changes.append(ch) default_ch = self.multiple_unconditional([domain, default]) changes.append(default_ch) return ChangeGroup(changes)
def simple_conditional(self, children): """ Translates phoneme-to-phoneme alternative-default changes. The way the arguments are passed is inconvenient since Python will not allow arbitrary list unpacking, thus the convoluted zip expression. The way this works is just by creating a conditional change for each alternative plus an unconditional one for the default, and returning them all as a ChangeGroup object. :param list children: The list of change parameters. :returns: A ChangeGroup object. """ changes = [] domain = children[0] default = children[-1] # the arguments are passed as: # [domain, codom, cond, codom, cond, ... , default] # the zip expression below essentially splits the list of codomains # and conditions into two list and then zips them into pairs. # # Example: # >>> args = [1, 2, 3, 4, 5, 6] # >>> args[1:-1] # [2, 3, 4, 5] # >>> args[1:-1][1::2] # [2, 4] # >>> [args[1:-1][i::2] for i in range(2)] # [[2, 4], [3, 5]] # >>> list(zip(*[args[1:-1][i::2] for i in range(2)])) # [(2, 3), (4, 5)] for (codomain, condition) in zip(*[children[1:-1][i::2] for i in range(2)]): ch = self.simple_unconditional([domain, codomain]) ch = ch.when(condition) changes.append(ch) default_ch = self.simple_unconditional([domain, default]) changes.append(default_ch) return ChangeGroup(changes)