当前位置: 首页>>代码示例>>Python>>正文


Python DialogueActConfusionNetwork.merge方法代码示例

本文整理汇总了Python中alex.components.slu.da.DialogueActConfusionNetwork.merge方法的典型用法代码示例。如果您正苦于以下问题:Python DialogueActConfusionNetwork.merge方法的具体用法?Python DialogueActConfusionNetwork.merge怎么用?Python DialogueActConfusionNetwork.merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alex.components.slu.da.DialogueActConfusionNetwork的用法示例。


在下文中一共展示了DialogueActConfusionNetwork.merge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_merge

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import merge [as 别名]
    def test_merge(self):
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))

        dacn.merge(dacn, combine='max')

        # Russian food should be pruned.
        dacn.sort().prune()
        self.assertTrue(not DialogueActItem(dai='inform(food=russian)') in dacn)
开发者ID:UFAL-DSG,项目名称:alex,代码行数:13,代码来源:test_da.py

示例2: parse_1_best

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import merge [as 别名]
    def parse_1_best(self, obs, verbose=False, *args, **kwargs):
        """Parse an utterance into a dialogue act.

        :rtype DialogueActConfusionNetwork
        """

        utterance = obs['utt']

        if isinstance(utterance, UtteranceHyp):
            # Parse just the utterance and ignore the confidence score.
            utterance = utterance.utterance

        if verbose:
            print 'Parsing utterance "{utt}".'.format(utt=utterance)

        res_cn = DialogueActConfusionNetwork()

        dict_da = self.utt2da.get(unicode(utterance), None)
        if dict_da:
            for dai in DialogueAct(dict_da):
                res_cn.add(1.0, dai)
            return res_cn

        utterance = self.preprocessing.normalise_utterance(utterance)
        abutterance, category_labels = self.abstract_utterance(utterance)

        if verbose:
            print 'After preprocessing: "{utt}".'.format(utt=abutterance)
            print category_labels

        self.parse_non_speech_events(utterance, res_cn)

        utterance = utterance.replace_all(['_noise_'], '').replace_all(['_laugh_'], '').replace_all(['_ehm_hmm_'], '').replace_all(['_inhale_'], '')
        abutterance = abutterance.replace_all(['_noise_'], '').replace_all(['_laugh_'], '').replace_all(['_ehm_hmm_'], '').replace_all(['_inhale_'], '')

        abutterance = self.handle_false_abstractions(abutterance)
        category_labels.add('CITY')
        category_labels.add('VEHICLE')
        category_labels.add('NUMBER')

        if len(res_cn) == 0:
            if 'STOP' in category_labels:
                self.parse_stop(abutterance, res_cn)
            if 'CITY' in category_labels:
                self.parse_city(abutterance, res_cn)
            if 'NUMBER' in category_labels:
                self.parse_number(abutterance)
                if any([word.startswith("TIME") for word in abutterance]):
                    category_labels.add('TIME')
            if 'TIME' in category_labels:
                self.parse_time(abutterance, res_cn)
            if 'DATE_REL' in category_labels:
                self.parse_date_rel(abutterance, res_cn)
            if 'AMPM' in category_labels:
                self.parse_ampm(abutterance, res_cn)
            if 'VEHICLE' in category_labels:
                self.parse_vehicle(abutterance, res_cn)
            if 'TASK' in category_labels:
                self.parse_task(abutterance, res_cn)

            self.parse_meta(utterance, res_cn)

        res_cn.merge()

        return res_cn
开发者ID:beka-evature,项目名称:alex,代码行数:67,代码来源:hdc_slu.py

示例3: test_session_logger

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import merge [as 别名]
    def test_session_logger(self):
        cfg = Config.load_configs(config=CONFIG_DICT, use_default=False)

        sl = SessionLogger()

        # test 3 calls at once
        for i in range(3):
            sess_dir = "./%d" % i
            if not os.path.isdir(sess_dir):
                os.mkdir(sess_dir)
            sl.session_start(sess_dir)
            sl.config('config = ' + unicode(cfg))
            sl.header(cfg['Logging']["system_name"], cfg['Logging']["version"])
            sl.input_source("voip")

            sl.dialogue_rec_start(None, "both_complete_dialogue.wav")
            sl.dialogue_rec_start("system", "system_complete_dialogue.wav")
            sl.dialogue_rec_start("user", "user_complete_dialogue.wav")
            sl.dialogue_rec_end("both_complete_dialogue.wav")
            sl.dialogue_rec_end("system_complete_dialogue.wav")
            sl.dialogue_rec_end("user_complete_dialogue.wav")

            sl.turn("system")
            sl.dialogue_act("system", "hello()")
            sl.text("system", "Hello.")
            sl.rec_start("system", "system1.wav")
            sl.rec_end("system1.wav")

            sl.turn("user")
            sl.rec_start("user", "user1.wav")
            sl.rec_end("user1.wav")

            A1, A2, A3 = 0.90, 0.05, 0.05
            B1, B2, B3 = 0.70, 0.20, 0.10
            C1, C2, C3 = 0.80, 0.10, 0.10

            asr_confnet = UtteranceConfusionNetwork()
            asr_confnet.add([[A1, "want"], [A2, "has"], [A3, 'ehm']])
            asr_confnet.add([[B1, "Chinese"],  [B2, "English"], [B3, 'cheap']])
            asr_confnet.add([[C1, "restaurant"],  [C2, "pub"],   [C3, 'hotel']])
            asr_confnet.merge()
            asr_confnet.normalise()
            asr_confnet.sort()

            asr_nblist = asr_confnet.get_utterance_nblist()

            sl.asr("user", "user1.wav", asr_nblist, asr_confnet)

            slu_confnet = DialogueActConfusionNetwork()
            slu_confnet.add(0.7, DialogueActItem('hello'))
            slu_confnet.add(0.6, DialogueActItem('thankyou'))
            slu_confnet.add(0.4, DialogueActItem('restart'))
            slu_confnet.add(0.1, DialogueActItem('bye'))
            slu_confnet.merge()
            slu_confnet.normalise()
            slu_confnet.sort()

            slu_nblist = slu_confnet.get_da_nblist()

            sl.slu("user", "user1.wav", slu_nblist, slu_confnet)

            sl.turn("system")
            sl.dialogue_act("system", "thankyou()")
            sl.text("system", "Thank you.", cost = 1.0)
            sl.rec_start("system", "system2.wav")
            sl.rec_end("system2.wav")
            sl.barge_in("system", tts_time = True)

            sl.turn("user")
            sl.rec_start("user", "user2.wav")
            sl.rec_end("user2.wav")
            sl.hangup("user")
开发者ID:AoJ,项目名称:alex,代码行数:74,代码来源:test_sessionlogger.py

示例4: parse_1_best

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import merge [as 别名]
    def parse_1_best(self, obs, verbose=False):
        """Parse an utterance into a dialogue act."""
        utterance = obs['utt']

        if isinstance(utterance, UtteranceHyp):
            # Parse just the utterance and ignore the confidence score.
            utterance = utterance.utterance

        # print 'Parsing utterance "{utt}".'.format(utt=utterance)
        if verbose:
            print 'Parsing utterance "{utt}".'.format(utt=utterance)

        if self.preprocessing:
            # the text normalisation
            utterance = self.preprocessing.normalise_utterance(utterance)

            abutterance, category_labels = self.abstract_utterance(utterance)

            if verbose:
                print 'After preprocessing: "{utt}".'.format(utt=abutterance)
                print category_labels
        else:
            category_labels = dict()

        # handle false positive alarms of abstraction
        abutterance = abutterance.replace(('STOP=Metra',), ('metra',))
        abutterance = abutterance.replace(('STOP=Nádraží',), ('nádraží',))
        abutterance = abutterance.replace(('STOP=SME',), ('sme',))
        abutterance = abutterance.replace(('STOP=Bílá Hora', 'STOP=Železniční stanice',), ('STOP=Bílá Hora', 'železniční stanice',))

        abutterance = abutterance.replace(('TIME=now','bych', 'chtěl'), ('teď', 'bych', 'chtěl'))
        abutterance = abutterance.replace(('STOP=Čím','se'), ('čím', 'se',))
        abutterance = abutterance.replace(('STOP=Lužin','STOP=Na Chmelnici',), ('STOP=Lužin','na','STOP=Chmelnici',))
        abutterance = abutterance.replace(('STOP=Konečná','zastávka'), ('konečná', 'zastávka',))
        abutterance = abutterance.replace(('STOP=Konečná','STOP=Anděl'), ('konečná', 'STOP=Anděl',))
        abutterance = abutterance.replace(('STOP=Konečná stanice','STOP=Ládví'), ('konečná', 'stanice', 'STOP=Ládví',))
        abutterance = abutterance.replace(('STOP=Výstupní', 'stanice', 'je'), ('výstupní', 'stanice', 'je'))
        abutterance = abutterance.replace(('STOP=Nová','jiné'), ('nové', 'jiné',))
        abutterance = abutterance.replace(('STOP=Nová','spojení'), ('nové', 'spojení',))
        abutterance = abutterance.replace(('STOP=Nová','zadání'), ('nové', 'zadání',))
        abutterance = abutterance.replace(('STOP=Nová','TASK=find_connection'), ('nový', 'TASK=find_connection',))
        abutterance = abutterance.replace(('z','CITY=Liberk',), ('z', 'CITY=Liberec',))
        abutterance = abutterance.replace(('do','CITY=Liberk',), ('do', 'CITY=Liberec',))
        abutterance = abutterance.replace(('pauza','hrozně','STOP=Dlouhá',), ('pauza','hrozně','dlouhá',))
        abutterance = abutterance.replace(('v','STOP=Praga',), ('v', 'CITY=Praha',))
        abutterance = abutterance.replace(('na','STOP=Praga',), ('na', 'CITY=Praha',))
        abutterance = abutterance.replace(('po','STOP=Praga', 'ale'), ('po', 'CITY=Praha',))
        abutterance = abutterance.replace(('jsem','v','STOP=Metra',), ('jsem', 'v', 'VEHICLE=metro',))
        category_labels.add('CITY')
        category_labels.add('VEHICLE')

        # print 'After preprocessing: "{utt}".'.format(utt=abutterance)
        # print category_labels

        res_cn = DialogueActConfusionNetwork()

        self.parse_non_speech_events(utterance, res_cn)

        if len(res_cn) == 0:
            # remove non speech events, they are not relevant for SLU
            abutterance = abutterance.replace_all('_noise_', '').replace_all('_laugh_', '').replace_all('_ehm_hmm_', '').replace_all('_inhale_', '')

            if 'STOP' in category_labels:
                self.parse_stop(abutterance, res_cn)
            if 'CITY' in category_labels:
                self.parse_city(abutterance, res_cn)
            if 'TIME' in category_labels:
                self.parse_time(abutterance, res_cn)
            if 'DATE_REL' in category_labels:
                self.parse_date_rel(abutterance, res_cn)
            if 'AMPM' in category_labels:
                self.parse_ampm(abutterance, res_cn)
            if 'VEHICLE' in category_labels:
                self.parse_vehicle(abutterance, res_cn)
            if 'TASK' in category_labels:
                self.parse_task(abutterance, res_cn)

            self.parse_meta(utterance, res_cn)

        res_cn.merge()

        return res_cn
开发者ID:elnaaz,项目名称:alex,代码行数:84,代码来源:hdc_slu.py


注:本文中的alex.components.slu.da.DialogueActConfusionNetwork.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。