Esempio n. 1
0
	def __init__( self, nat_class_set, start, states, parameters,
			 precision=None, m=None, e=None ):
		'''See: param_wfsa.ParametrizedWFSA
		arcs: dict(start state -> dict(natural class -> 
				pair(destination state, parameter number) ) )
		nat_class_set: A NaturalClassSet, which contains all the natural classes
				in the language, plus the alphabet, plus information useful for
				determining machine complexity.
		'''
		self.nat_class_set = nat_class_set
		self.alphabet = nat_class_set.alphabet
		self.complexity = 0
		ParametrizedWFSA.__init__( self, self.alphabet, start, states, 
				parameters, 0, precision, m, e )
		self.complexity = self._complex()
Esempio n. 2
0
    def __init__(self, alphabet, start, stops, arcs, categories, parameters, precision=None, m=None, e=None):
        """arcs: a dictionary from states to dictionaries
				from letters or frozen sets of categories to 
				state, weight tuples. The categories on an arc 
				label are intersected to get the set of letters
				that may traverse that arc.
		   categories: a dictionary from categories to the set
				of phones belonging to that category.
		"""
        # self.categories[symbol] = set of phonemes
        self.categories = {}
        for cat, phones in categories.items():
            self.categories[cat] = set(phones)

        alphabet = set(alphabet)

        # convert CatWFSA into an ordinary ParametrizedWFSA
        self.cat_arcs = arcs
        new_arcs = {}
        for state, v in arcs.items():
            new_arcs[state] = {}
            for label, val in v.items():
                if isinstance(label, frozenset):
                    phones = alphabet
                    for cat in label:
                        phones = phones.intersection(self.categories[cat])
                    for phone in phones:
                        if phone in new_arcs[state].keys():
                            # do error checking
                            dest0, w0 = new_arcs[state][phone]
                            dest1, w1 = val
                            if dest0 != dest1 or w0 != w1:
                                raise ArcCategoryError(state, phone, dest0, dest1, w0, w1)
                        else:
                            new_arcs[state][phone] = val
                else:
                    if label in new_arcs[state].keys():
                        # do error checking
                        dest0, w0 = self.arcs[state][label]
                        dest1, w1 = val
                        if dest0 != dest1 or w0 != w1:
                            raise ArcCategoryError(state, label, dest0, dest1, w0, w1)
                    else:
                        new_arcs[state][label] = val
        self.complexity = 1
        ParametrizedWFSA.__init__(self, alphabet, start, stops, new_arcs, parameters)
        self.complexity = self._complex()