コード例 #1
0
ファイル: cuedda.py プロジェクト: AoJ/alex
    def parse(self):
        cuedDA = self.cuedDA

        numOfDAs = len(split_by_comma(cuedDA))
        if numOfDAs > 1:
            raise ValueError('Too many DAs in input text.')

        # get the dialogue act type
        i = cuedDA.index("(")
        dialogue_act_type = cuedDA[:i]

        slots = cuedDA[i:].lower()
        slots = slots.replace('(', '')
        slots = slots.replace(')', '')

        slts = []
        if slots == '':
            # no slots to process
            slots = []
        else:
            # split slots
            slots = split_by_comma(slots)
            for slt in slots:
                try:
                    s = CUEDSlot(slt)
                    s.parse()
                    slts.append(s)
                except ValueError:
                    # check for invalid slot items
                    pass

        self.dialogue_act_type = dialogue_act_type
        self.slots = slts

        return
コード例 #2
0
ファイル: cuedda.py プロジェクト: henrypig/alex-1
    def parse(self):
        cuedDA = self.cuedDA

        numOfDAs = len(split_by_comma(cuedDA))
        if numOfDAs > 1:
            raise ValueError('Too many DAs in input text.')

        # get the dialogue act type
        i = cuedDA.index("(")
        dialogue_act_type = cuedDA[:i]

        slots = cuedDA[i:].lower()
        slots = slots.replace('(', '')
        slots = slots.replace(')', '')

        slts = []
        if slots == '':
            # no slots to process
            slots = []
        else:
            # split slots
            slots = split_by_comma(slots)
            for slt in slots:
                try:
                    s = CUEDSlot(slt)
                    s.parse()
                    slts.append(s)
                except ValueError:
                    # check for invalid slot items
                    pass

        self.dialogue_act_type = dialogue_act_type
        self.slots = slts

        return
コード例 #3
0
ファイル: cued_da.py プロジェクト: henrypig/alex-1
    def parse(self, da_str):
        # Get the dialogue act type.
        first_par_idx = da_str.index("(")
        self.dat = da_str[:first_par_idx]

        if len(split_by_comma(da_str)) != 1:
            raise ValueError('Too many (or none -- too few) DAs in CUED DA '
                             'representation.')

        slots_str = da_str[first_par_idx:].lower()[1:-1]
        if not slots_str:
            # no slots to process
            self._dais = list()
        else:
            # split slots_str
            slotstr_list = split_by(slots_str, splitter=',', quotes='"')

            slots = list()
            for slot_str in slotstr_list:
                try:
                    slots.append(CUEDSlot(slot_str))
                except ValueError:
                    # Skip slots we cannot parse.
                    pass

            if self.dat == 'inform':
                for slot in slots:
                    if slot.negated:
                        self._dais.append(
                            DialogueActItem('deny', slot.name, slot.value))
                    else:
                        self._dais.append(
                            DialogueActItem('inform', slot.name, slot.value))

            elif self.dat == 'request':
                for slot in slots:
                    if slot.value:
                        if slot.negated:
                            self._dais.append(
                                DialogueActItem('deny', slot.name, slot.value))
                        else:
                            self._dais.append(
                                DialogueActItem('inform', slot.name,
                                                slot.value))
                    else:
                        self._dais.append(
                            DialogueActItem('request', slot.name, slot.value))

            elif self.dat == 'confirm':
                for slot in slots:
                    if slot.name == 'name':
                        self._dais.append(
                            DialogueActItem('inform', slot.name, slot.value))
                    else:
                        self._dais.append(
                            DialogueActItem('confirm', slot.name, slot.value))

            elif self.dat == 'select':
                # XXX We cannot represent DAIS with multiple slots as of now.
                # Therefore, the select DAT is split into two DAIs here.
                self._dais.append(
                    DialogueActItem('select', slots[0].name, slots[0].value))
                self._dais.append(
                    DialogueActItem('select', slots[1].name, slots[1].value))

            elif self.dat in ('silence', 'thankyou', 'ack', 'bye', 'hangup',
                              'repeat', 'help', 'restart', 'null'):
                self._dais.append(DialogueActItem(self.dat))

            elif self.dat in ('hello', 'affirm', 'negate', 'reqalts',
                              'reqmore'):
                self._dais.append(DialogueActItem(self.dat))
                for slot in self._dais:
                    if slot.negated:
                        self._dais.append(
                            DialogueActItem('deny', slot.name, slot.value))
                    else:
                        self._dais.append(
                            DialogueActItem('inform', slot.name, slot.value))

            elif self.dat == 'deny':
                self._dais.append(
                    DialogueActItem('deny', slots[0].name, slots[0].value))
                for slot in slots[1:]:
                    if slot.negated:
                        self._dais.append(
                            DialogueActItem('deny', slot.name, slot.value))
                    else:
                        self._dais.append(
                            DialogueActItem('inform', slot.name, slot.value))

            else:
                raise CuedDialogueActError(
                    'Unknown CUED DA type "{dat}" when parsing "{da_str}".'.
                    format(dat=self.dat, da_str=da_str))

        self._dais_sorted = False
コード例 #4
0
ファイル: cued_da.py プロジェクト: AoJ/alex
    def parse(self, da_str):
        # Get the dialogue act type.
        first_par_idx = da_str.index("(")
        self.dat = da_str[:first_par_idx]

        if len(split_by_comma(da_str)) != 1:
            raise ValueError('Too many (or none -- too few) DAs in CUED DA '
                             'representation.')

        slots_str = da_str[first_par_idx:].lower()[1:-1]
        if not slots_str:
            # no slots to process
            self._dais = list()
        else:
            # split slots_str
            slotstr_list = split_by(slots_str, splitter=',', quotes='"')

            slots = list()
            for slot_str in slotstr_list:
                try:
                    slots.append(CUEDSlot(slot_str))
                except ValueError:
                    # Skip slots we cannot parse.
                    pass

            if self.dat == 'inform':
                for slot in slots:
                    if slot.negated:
                        self._dais.append(DialogueActItem(
                            'deny', slot.name, slot.value))
                    else:
                        self._dais.append(DialogueActItem(
                            'inform', slot.name, slot.value))

            elif self.dat == 'request':
                for slot in slots:
                    if slot.value:
                        if slot.negated:
                            self._dais.append(DialogueActItem(
                                'deny', slot.name, slot.value))
                        else:
                            self._dais.append(DialogueActItem(
                                'inform', slot.name, slot.value))
                    else:
                        self._dais.append(DialogueActItem(
                            'request', slot.name, slot.value))

            elif self.dat == 'confirm':
                for slot in slots:
                    if slot.name == 'name':
                        self._dais.append(DialogueActItem(
                            'inform', slot.name, slot.value))
                    else:
                        self._dais.append(DialogueActItem(
                            'confirm', slot.name, slot.value))

            elif self.dat == 'select':
                # XXX We cannot represent DAIS with multiple slots as of now.
                # Therefore, the select DAT is split into two DAIs here.
                self._dais.append(DialogueActItem(
                    'select', slots[0].name, slots[0].value))
                self._dais.append(DialogueActItem(
                    'select', slots[1].name, slots[1].value))

            elif self.dat in ('silence', 'thankyou', 'ack', 'bye', 'hangup',
                              'repeat', 'help', 'restart', 'null'):
                self._dais.append(DialogueActItem(self.dat))

            elif self.dat in ('hello', 'affirm', 'negate', 'reqalts',
                              'reqmore'):
                self._dais.append(DialogueActItem(self.dat))
                for slot in self._dais:
                    if slot.negated:
                        self._dais.append(DialogueActItem(
                            'deny', slot.name, slot.value))
                    else:
                        self._dais.append(DialogueActItem(
                            'inform', slot.name, slot.value))

            elif self.dat == 'deny':
                self._dais.append(DialogueActItem(
                    'deny', slots[0].name, slots[0].value))
                for slot in slots[1:]:
                    if slot.negated:
                        self._dais.append(DialogueActItem(
                            'deny', slot.name, slot.value))
                    else:
                        self._dais.append(DialogueActItem(
                            'inform', slot.name, slot.value))

            else:
                raise CuedDialogueActError(
                    'Unknown CUED DA type "{dat}" when parsing "{da_str}".'
                    .format(dat=self.dat, da_str=da_str))

        self._dais_sorted = False