Ejemplo n.º 1
0
def slu_factory(cfg, slu_type=None):
    """
    Creates an SLU parser.

    :param cfg:
    :param slu_type:
    :param require_model:
    :param training:
    :param verbose:

    """

    #This new and simple factory code.
    if slu_type is None:
        slu_type = get_slu_type(cfg)

    if inspect.isclass(slu_type) and issubclass(slu_type, DAILogRegClassifier):
        cldb = CategoryLabelDatabase(cfg['SLU'][slu_type]['cldb_fname'])
        preprocessing = cfg['SLU'][slu_type]['preprocessing_cls'](cldb)
        slu = slu_type(cldb, preprocessing)
        slu.load_model(cfg['SLU'][slu_type]['model_fname'])
        return slu
    elif inspect.isclass(slu_type) and issubclass(slu_type, SLUInterface):
        cldb = CategoryLabelDatabase(cfg['SLU'][slu_type]['cldb_fname'])
        preprocessing = cfg['SLU'][slu_type]['preprocessing_cls'](cldb)
        slu = slu_type(preprocessing)
        return slu

    raise SLUException('Unsupported SLU parser: %s' % slu_type)
Ejemplo n.º 2
0
Archivo: base.py Proyecto: tkraut/alex
 def normalise(self, utt_hyp):
     if isinstance(utt_hyp, Utterance):
         return self.normalise_utterance(utt_hyp)
     elif isinstance(utt_hyp, UtteranceNBList):
         return self.normalise_nblist(utt_hyp)
     elif isinstance(utt_hyp, UtteranceConfusionNetwork):
         return self.normalise_confnet(utt_hyp)
     else:
         raise SLUException("Unsupported observations.")
Ejemplo n.º 3
0
Archivo: base.py Proyecto: tkraut/alex
    def load(self, file_name):
        db_mod = load_as_module(file_name, force=True)
        if not hasattr(db_mod, 'database'):
            raise SLUException(
                "The category label database does not define the `database' object!"
            )
        self.database = db_mod.database

        self.normalise_database()
        # Update derived data structures.
        self.gen_synonym_value_category()
        self.gen_form_value_cl_list()
        self.gen_mapping_form2value2cl()

        self._form_val_upname = None
        self._form_upnames_vals = None
Ejemplo n.º 4
0
Archivo: da.py Proyecto: tkraut/alex
def merge_slu_nblists(multiple_nblists):
    """Merge multiple dialogue act N-best lists."""

    merged_nblists = DialogueActNBList()

    for prob_nblist, nblist in multiple_nblists:
        if not isinstance(nblist, DialogueActNBList):
            raise SLUException("Cannot merge something that is not DialogueActNBList.")
        nblist.merge()
        nblist.add_other()

        for prob, da in nblist:
            merged_nblists.add(prob_nblist * prob, da)

    merged_nblists.merge()
    merged_nblists.add_other()

    return merged_nblists
Ejemplo n.º 5
0
Archivo: da.py Proyecto: tkraut/alex
def merge_slu_confnets(confnet_hyps):
    """Merge multiple dialogue act confusion networks."""

    merged = DialogueActConfusionNetwork()

    for prob_confnet, confnet in confnet_hyps:
        if not isinstance(confnet, DialogueActConfusionNetwork):
            raise SLUException("Cannot merge something that is not a DialogueActConfusionNetwork.")

        for prob, dai in confnet.cn:
            # it is not clear why I wanted to remove all other() dialogue acts
            # if dai.dat == "other":
            #     continue

            merged.add_merge(prob_confnet * prob, dai, combine='add')

    merged.sort()

    return merged
Ejemplo n.º 6
0
    def read_asr_hypotheses_write_slu_hypotheses(self):
        if self.asr_hypotheses_in.poll():
            data_asr = self.asr_hypotheses_in.recv()

            if isinstance(data_asr, ASRHyp):
                slu_hyp = self.slu.parse(data_asr.hyp)
                fname = data_asr.fname

                confnet = None
                nblist = None

                if isinstance(slu_hyp, DialogueActConfusionNetwork):
                    confnet = slu_hyp
                    nblist = slu_hyp.get_da_nblist()
                elif isinstance(slu_hyp, DialogueActNBList):
                    confnet = None
                    nblist = slu_hyp


                if self.cfg['SLU']['debug']:
                    s = []
                    s.append("SLU Hypothesis")
                    s.append("-" * 60)
                    s.append("Confnet:")
                    s.append(unicode(confnet))
                    s.append("Nblist:")
                    s.append(unicode(nblist))
                    s.append("")
                    s = '\n'.join(s)
                    self.cfg['Logging']['system_logger'].debug(s)

                self.cfg['Logging']['session_logger'].slu("user", fname, nblist, confnet=confnet)

                self.commands.send(Command('slu_parsed(fname="%s")' % fname, 'SLU', 'HUB'))
                self.slu_hypotheses_out.send(SLUHyp(slu_hyp, asr_hyp=data_asr.hyp))

            elif isinstance(data_asr, Command):
                self.cfg['Logging']['system_logger'].info(data_asr)
            else:
                raise SLUException('Unsupported input.')
Ejemplo n.º 7
0
Archivo: base.py Proyecto: tkraut/alex
 def parse_1_best(self, obs, *args, **kwargs):
     # TODO Document.
     raise SLUException("Not implemented")