Beispiel #1
0
    def __init__(self, speaker=None, demo=False):
        Thread.__init__(self)

        self.go_on = True
        self._logger = logging.getLogger('dialogs')

        self._demo_mode = demo

        if speaker:
            self._speaker = speaker
        else:
            self._speaker = SpeakerIdentifier().get_current_speaker_id()

        self._parser = Parser()
        self._resolver = Resolver()
        self._content_analyser = ContentAnalyser()
        self._verbalizer = Verbalizer()

        self._nl_input_queue = Queue()
        self._sentence_output_queue = Queue()

        #true when the Dialog module is within an interaction with a speaker
        self.in_interaction = False

        #the current set of sentences that dialog is dealing with
        self.sentences = deque()

        #the current sentence being worked on. Specifically, if active_sentence
        #is set, the parser will _complete_ this sentence instead of creating a
        #new one.
        self.active_sentence = None

        #true when, during an interaction, more infos is needed.
        self.waiting_for_more_info = False

        #contains the last result of a failed resolution (including the object
        #that could not be resolved. Cf doc of UnsufficientInputError for details.
        self._last_output = None

        #contains the last result of a failed resolution of an anaphoric words (it, one) (including the object
        #that could not be resolved. Cf doc of UnidentifiedAnaphoraError for details.
        self._anaphora_input = None

        #the ID of the speaker we are talking with. used to resolve references
        #like 'me', 'you', etc.
        self.current_speaker = None

        #the set of the statements generated by the analysis of the last sentence.
        # For testing purposes.
        self.last_stmts_set = []

        #last utterance outputed to user. This is a tuple containing both the
        # Sentence object and the verbalized version.
        self.last_sentence = (None, None)
    def setUp(self):
        ResourcePool().ontology_server.reset()

        ResourcePool().ontology_server.add(['SPEAKER rdf:type Human', 'SPEAKER rdfs:label "Patrick"',
                                            'blue_cube rdf:type Cube',
                                            'blue_cube hasColor blue',
                                            'blue_cube isOn table1',

                                            'another_cube rdf:type Cube',
                                            'another_cube isAt shelf1',
                                            'another_cube belongsTo SPEAKER',
                                            'another_cube hasSize small',

                                            'shelf1 rdf:type Shelf',
                                            'table1 rdf:type Table',

                                            'myself sees shelf1',

                                            'take_blue_cube performedBy myself',
                                            'take_blue_cube rdf:type Get',
                                            'take_blue_cube actsOnObject blue_cube',

                                            'take_my_cube canBePerformedBy SPEAKER',
                                            'take_my_cube involves another_cube',
                                            'take_my_cube rdf:type Take',

                                            'SPEAKER focusesOn another_cube',

                                            'id_danny rdfs:label "Danny"',

                                            'give_another_cube rdf:type Give',
                                            'give_another_cube performedBy id_danny',
                                            'give_another_cube receivedBy SPEAKER',
                                            'give_another_cube actsOnObject another_cube',

                                            'id_danny sees SPEAKER',
        ])
        ResourcePool().ontology_server.addForAgent(ResourcePool().get_model_mapping('SPEAKER'),
                                                   [   'SPEAKER rdf:type Human',
                                                       'SPEAKER rdfs:label "Patrick"',
                                                       'blue_cube rdf:type Cube',
                                                       'blue_cube hasColor blue',
                                                       'blue_cube isOn table1',

                                                       'another_cube rdf:type Cube',
                                                       'another_cube isAt shelf1',
                                                       'another_cube belongsTo SPEAKER',
                                                       'another_cube hasSize small',

                                                       'shelf1 rdf:type Shelf',
                                                       'table1 rdf:type Table',

                                                       'myself sees shelf1',

                                                       'take_blue_cube performedBy myself',
                                                       'take_blue_cube rdf:type Get',
                                                       'take_blue_cube actsOnObject blue_cube',

                                                       'take_my_cube canBePerformedBy SPEAKER',
                                                       'take_my_cube involves another_cube',
                                                       'take_my_cube rdf:type Take',

                                                       'SPEAKER focusesOn another_cube',

                                                       'id_danny rdfs:label "Danny"',

                                                       'give_another_cube rdf:type Give',
                                                       'give_another_cube performedBy id_danny',
                                                       'give_another_cube receivedBy SPEAKER',
                                                       'give_another_cube actsOnObject another_cube',

                                                       'id_danny sees SPEAKER',
                                                   ])

        self.qhandler = QuestionHandler("SPEAKER")
        self.resolver = Resolver()