コード例 #1
0
    def setUp(self):
        self.disc = Discrimination()
        self.verbalizer = Verbalizer()

        try:
            #ResourcePool().ontology_server.reset()

            ResourcePool().ontology_server.add([
                "raquel rdf:type Human", "Gamebox rdfs:subClassOf Box",
                "Gamebox rdfs:label \"game box\"",
                "BLUE_BOTTLE rdf:type Bottle", "BLUE_BOTTLE hasColor blue",
                "ORANGE_BOTTLE rdf:type Bottle",
                "ORANGE_BOTTLE hasColor orange",
                "ORANGE_BOTTLE isOn ACCESSKIT",
                "YELLOW_BOTTLE rdf:type Bottle",
                "YELLOW_BOTTLE hasColor yellow", 'ACCESSKIT rdf:type Gamebox',
                'ACCESSKIT hasColor white', 'ACCESSKIT hasSize big',
                'ACCESSKIT isOn table1', 'ORANGEBOX rdf:type Gamebox',
                'ORANGEBOX hasColor orange', 'ORANGEBOX hasSize big',
                'ORANGEBOX isOn ACCESSKIT', 'SPACENAVBOX rdf:type Gamebox',
                'SPACENAVBOX hasColor white', 'SPACENAVBOX hasSize big',
                'SPACENAVBOX isOn ACCESSKIT'
            ])

            ResourcePool().ontology_server.addForAgent(
                ResourcePool().get_model_mapping("raquel"),
                ["BLUE_BOTTLE isVisible true", "ORANGE_BOTTLE isVisible true"])

        except AttributeError:  #the ontology server is not started of doesn't know the method
            raise (DialogError("The ontology server is not started!"))
コード例 #2
0
    def noun_phrases_resolution(self, sentence, current_speaker, uie_object,
                                uie_object_with_more_info):

        logger.info(colored_print("-> Resolving noun phrases", 'green'))

        #Skipping processing of sentences that are neither questions nor statements nor imperatives
        if not sentence.data_type in [
                W_QUESTION, YES_NO_QUESTION, STATEMENT, IMPERATIVE
        ]:
            return sentence

        #Nominal group replacement possibly after uie_object and uie_object_with_more_info are sent from Dialog to resolve missing content
        if uie_object and uie_object_with_more_info:
            sentence = self._noun_phrases_replace_with_ui_exception(
                sentence, uie_object, uie_object_with_more_info)

            #No uie_objects needed after replacement
            uie_object = None
            uie_object_with_more_info = None

        #Record of current sentence
        self._current_sentence = sentence

        #NominalGroupStatementBuilder
        builder = NominalGroupStatementBuilder(None, current_speaker)

        #Discrimination
        discriminator = Discrimination()

        #sentence.sn nominal groups nouns phrase resolution
        if sentence.sn:
            sentence.sn = self._resolve_groups_nouns(sentence.sn,
                                                     current_speaker,
                                                     discriminator, builder)
            #sentence.sv nominal groups nouns phrase resolution
        if sentence.sv:
            sentence.sv = self.verbal_phrases_noun_resolution(
                sentence.sv, current_speaker, discriminator, builder)

        return sentence
コード例 #3
0
ファイル: discrimination_test.py プロジェクト: Kuew/dialogs
    def setUp(self):
        self.disc = Discrimination()
        self.verbalizer = Verbalizer()

        try:
            # ResourcePool().ontology_server.reset()

            ResourcePool().ontology_server.add(
                [
                    "raquel rdf:type Human",
                    "Gamebox rdfs:subClassOf Box",
                    'Gamebox rdfs:label "game box"',
                    "BLUE_BOTTLE rdf:type Bottle",
                    "BLUE_BOTTLE hasColor blue",
                    "ORANGE_BOTTLE rdf:type Bottle",
                    "ORANGE_BOTTLE hasColor orange",
                    "ORANGE_BOTTLE isOn ACCESSKIT",
                    "YELLOW_BOTTLE rdf:type Bottle",
                    "YELLOW_BOTTLE hasColor yellow",
                    "ACCESSKIT rdf:type Gamebox",
                    "ACCESSKIT hasColor white",
                    "ACCESSKIT hasSize big",
                    "ACCESSKIT isOn table1",
                    "ORANGEBOX rdf:type Gamebox",
                    "ORANGEBOX hasColor orange",
                    "ORANGEBOX hasSize big",
                    "ORANGEBOX isOn ACCESSKIT",
                    "SPACENAVBOX rdf:type Gamebox",
                    "SPACENAVBOX hasColor white",
                    "SPACENAVBOX hasSize big",
                    "SPACENAVBOX isOn ACCESSKIT",
                ]
            )

            ResourcePool().ontology_server.addForAgent(
                "raquel", ["BLUE_BOTTLE isVisible true", "ORANGE_BOTTLE isVisible true"]
            )

        except AttributeError:  # the ontology server is not started of doesn't know the method
            raise (DialogError("The ontology server is not started!"))
コード例 #4
0
class TestDiscrimination(unittest.TestCase):
    """This function tests the main features of the class Discrimination"""

    def setUp(self):
        self.disc = Discrimination()
        self.verbalizer = Verbalizer()

        try:
            #ResourcePool().ontology_server.reset()

            ResourcePool().ontology_server.add(["raquel rdf:type Human",
                                                "Gamebox rdfs:subClassOf Box",
                                                "Gamebox rdfs:label \"game box\"",
                                                "BLUE_BOTTLE rdf:type Bottle",
                                                "BLUE_BOTTLE hasColor blue",
                                                "ORANGE_BOTTLE rdf:type Bottle",
                                                "ORANGE_BOTTLE hasColor orange",
                                                "ORANGE_BOTTLE isOn ACCESSKIT",
                                                "YELLOW_BOTTLE rdf:type Bottle",
                                                "YELLOW_BOTTLE hasColor yellow",
                                                'ACCESSKIT rdf:type Gamebox',
                                                'ACCESSKIT hasColor white',
                                                'ACCESSKIT hasSize big',
                                                'ACCESSKIT isOn table1',
                                                'ORANGEBOX rdf:type Gamebox',
                                                'ORANGEBOX hasColor orange',
                                                'ORANGEBOX hasSize big',
                                                'ORANGEBOX isOn ACCESSKIT',
                                                'SPACENAVBOX rdf:type Gamebox',
                                                'SPACENAVBOX hasColor white',
                                                'SPACENAVBOX hasSize big',
                                                'SPACENAVBOX isOn ACCESSKIT'
            ])

            ResourcePool().ontology_server.addForAgent(ResourcePool().get_model_mapping("raquel"),
                                                       ["BLUE_BOTTLE isVisible true",
                                                        "ORANGE_BOTTLE isVisible true"
                                                       ])

        except AttributeError: #the ontology server is not started of doesn't know the method
            raise (DialogError("The ontology server is not started!"))

    def test_01(self):
        logger.info("Test1: No ambiguity.")
        description = [['myself', '?obj', ['?obj rdf:type Bottle', '?obj hasColor blue']]]
        expected_result = "BLUE_BOTTLE"

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError:
            self.fail("Should need any more info")

        self.assertEquals(expected_result, res)

    def test_02(self):
        logger.info("\nTest2: Complete self.discriminant in robot model found.")
        description = [['myself', '?obj', ['?obj rdf:type Bottle']]]
        expected_result = "Which color is the bottle? Blue or orange or yellow."

        try:
            self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']), expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_03(self):
        logger.info("\nTest3: No complete self.discriminant in robot model found.")
        description = [['myself', '?obj', ['?obj rdf:type Box']]]
        expected_result = ["Which color is the box? Orange or white.",
                           "Where is the Box? On the ACCESSKIT or on the table1?"]

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertIn(self.verbalizer.verbalize(use.value['question']), expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_04(self):
        logger.info("\nTest4: Including visibility constraints")
        description = [['myself', '?obj', ['?obj rdf:type Bottle']], ['raquel', '?obj', ['?obj isVisible true']]]
        expected_result = "Which color is the bottle? Blue or orange."

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']), expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_05(self):
        logger.info("\nTest5: Testing location")
        description = [['myself', '?obj', ['?obj rdf:type Artifact', '?obj hasColor orange']]]
        expected_result = "Which type is the object? Game box or bottle."

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']), expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")
コード例 #5
0
class TestDiscrimination(unittest.TestCase):
    """This function tests the main features of the class Discrimination"""
    def setUp(self):
        self.disc = Discrimination()
        self.verbalizer = Verbalizer()

        try:
            #ResourcePool().ontology_server.reset()

            ResourcePool().ontology_server.add([
                "raquel rdf:type Human", "Gamebox rdfs:subClassOf Box",
                "Gamebox rdfs:label \"game box\"",
                "BLUE_BOTTLE rdf:type Bottle", "BLUE_BOTTLE hasColor blue",
                "ORANGE_BOTTLE rdf:type Bottle",
                "ORANGE_BOTTLE hasColor orange",
                "ORANGE_BOTTLE isOn ACCESSKIT",
                "YELLOW_BOTTLE rdf:type Bottle",
                "YELLOW_BOTTLE hasColor yellow", 'ACCESSKIT rdf:type Gamebox',
                'ACCESSKIT hasColor white', 'ACCESSKIT hasSize big',
                'ACCESSKIT isOn table1', 'ORANGEBOX rdf:type Gamebox',
                'ORANGEBOX hasColor orange', 'ORANGEBOX hasSize big',
                'ORANGEBOX isOn ACCESSKIT', 'SPACENAVBOX rdf:type Gamebox',
                'SPACENAVBOX hasColor white', 'SPACENAVBOX hasSize big',
                'SPACENAVBOX isOn ACCESSKIT'
            ])

            ResourcePool().ontology_server.addForAgent(
                ResourcePool().get_model_mapping("raquel"),
                ["BLUE_BOTTLE isVisible true", "ORANGE_BOTTLE isVisible true"])

        except AttributeError:  #the ontology server is not started of doesn't know the method
            raise (DialogError("The ontology server is not started!"))

    def test_01(self):
        logger.info("Test1: No ambiguity.")
        description = [[
            'myself', '?obj', ['?obj rdf:type Bottle', '?obj hasColor blue']
        ]]
        expected_result = "BLUE_BOTTLE"

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError:
            self.fail("Should need any more info")

        self.assertEquals(expected_result, res)

    def test_02(self):
        logger.info(
            "\nTest2: Complete self.discriminant in robot model found.")
        description = [['myself', '?obj', ['?obj rdf:type Bottle']]]
        expected_result = "Which color is the bottle? Blue or orange or yellow."

        try:
            self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']),
                              expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_03(self):
        logger.info(
            "\nTest3: No complete self.discriminant in robot model found.")
        description = [['myself', '?obj', ['?obj rdf:type Box']]]
        expected_result = [
            "Which color is the box? Orange or white.",
            "Where is the Box? On the ACCESSKIT or on the table1?"
        ]

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertIn(self.verbalizer.verbalize(use.value['question']),
                          expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_04(self):
        logger.info("\nTest4: Including visibility constraints")
        description = [['myself', '?obj', ['?obj rdf:type Bottle']],
                       ['raquel', '?obj', ['?obj isVisible true']]]
        expected_result = "Which color is the bottle? Blue or orange."

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']),
                              expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")

    def test_05(self):
        logger.info("\nTest5: Testing location")
        description = [[
            'myself', '?obj',
            ['?obj rdf:type Artifact', '?obj hasColor orange']
        ]]
        expected_result = "Which type is the object? Game box or bottle."

        try:
            res = self.disc.clarify(description)
        except UnsufficientInputError as use:
            self.assertEquals(use.value['status'], 'SUCCESS')
            self.assertEquals(self.verbalizer.verbalize(use.value['question']),
                              expected_result)
            return

        self.fail("Should trigger an unsufficient input exception!")