Exemplo n.º 1
0
    def get_observations(self, state):
        """
        Returns the possible observations that are expected to be perceived from the dialogue state

        :param state: the dialogue state from which to extract observations
        :return: the inferred observations
        """
        prediction_nodes = set()

        for node_id in state.get_chance_node_ids():
            if "^p" in node_id:
                prediction_nodes.add(node_id)

        # intermediary observations
        for node_id in prediction_nodes:
            if state.get_chance_node(node_id).has_descendant(prediction_nodes):
                prediction_nodes.remove(node_id)

        builder = MultivariateTableBuilder()

        if len(prediction_nodes) != 0:
            observations = state.query_prob(prediction_nodes)

            for a in observations.get_values():
                new_a = Assignment()
                for var in a.get_variables():
                    new_a.add_pair(var.replace("^p", ""), a.get_value(var))

                builder.add_row(new_a, observations.get_prob(a))

        return builder.build()
Exemplo n.º 2
0
 def test_template7(self):
     template1 = Template.create("here we have slot {A} and slot {B}")
     fillers = Assignment()
     fillers.add_pair("A", "apple")
     fillers.add_pair("B", "banana")
     assert template1.fill_slots(fillers) == "here we have slot apple and slot banana"
     fillers.remove_pair("B")
     assert Template.create(template1.fill_slots(fillers)).get_slots().pop() == "B"
Exemplo n.º 3
0
    def get_assignment(self):
        """
        Returns the effect as an assignment of values. The variable labels are ended
        by a prime character.

        :return: the assignment of new values to the variables
        """
        assignment = Assignment()
        for effect in self._sub_effects:
            if not effect._negated:
                assignment.add_pair(effect.get_variable() + "'",
                                    effect.get_value())
            else:
                assignment.add_pair(effect.get_variable() + "'",
                                    ValueFactory.none())
        return assignment
Exemplo n.º 4
0
    def modify_variable_id(self, old_id, new_id):
        """
        Modifies a variable label with a new one

        :param old_id: the old variable label
        :param new_id: the new label
        :return:
        """
        new_table = dict()
        for assignment in self._table.keys():
            new_assignment = Assignment()
            for variable in assignment.get_variables():
                new_variable = new_id if variable == old_id else variable
                new_assignment.add_pair(new_variable,
                                        assignment.get_value(variable))

            new_table[new_assignment] = self._table[assignment]

        self._table = new_table
Exemplo n.º 5
0
    def sample(self):
        """
        Returns a sample value for the node, according to the probability distribution
        currently defined.

        The method assumes that the node is conditionally independent of every other
        node. If it isn't, one should use the sample(condition) method instead.

        :return: the sample value
        """
        if isinstance(self._distrib, IndependentDistribution):
            return self._distrib.sample()

        input_sample = Assignment()
        for input_node in self._input_nodes.values():
            if isinstance(input_node, ChanceNode) or isinstance(
                    input_node, ActionNode):
                input_sample.add_pair(input_node.get_id(), input_node.sample())

        return self.sample(input_sample)
Exemplo n.º 6
0
 def add_user_input(self, input_speech):
     assignment = Assignment(self._settings.user_speech, input_speech)
     assignment.add_pair(self._settings.floor, 'user')
     return self.add_content(assignment)