コード例 #1
0
    def test_slot_copy_copies_value_type_and_attributes(self):
        slot = Slot(self.to_value, self.attributes, self.fact)
        copy = slot.copy()

        self.assertEqual(slot.value, copy.value)
        self.assertEqual(slot.slot_type, copy.slot_type)
        self.assertEqual(slot.attributes, copy.attributes)
コード例 #2
0
    def test_slot_copy_changes_to_copy_do_not_reflect_to_original(self):
        slot = Slot(self.to_value, self.attributes, self.fact)
        copy = slot.copy()
        copy.attributes["new_key"] = "new_val"
        copy.value = LiteralSource("new literal")

        self.assertNotEqual(slot.value, copy.value)
        self.assertNotEqual(slot.attributes, copy.attributes)
コード例 #3
0
    def test_template_move_slot_backwards(self):
        new_slot = Slot(FactFieldSource("parameters"))
        self.template.add_slot(2, new_slot)

        self.template.move_slot(2, 1)
        self.assertListEqual(self.template.components,
                             [self.slot, new_slot, self.literal])
コード例 #4
0
    def setUp(self):
        self.fact1 = Fact(
            "action",
            "action1",
            "parameters",
            "id",
        )
        self.fact2 = Fact(
            "action",
            "action2",
            "parameters",
            "id",
        )

        self.message1 = Message(self.fact1)
        self.message2 = Message(self.fact2)

        self.expr = FactField("name")
        self.matcher = Matcher(self.expr, "=", "action1")
        self.rules = [([self.matcher], [0])]

        self.slot = Slot(FactFieldSource("name"))
        self.literal = LiteralSlot("literal")
        self.components = [self.slot, self.literal]

        self.template = Template(self.components, self.rules)
コード例 #5
0
    def test_template_move_slot_forwards(self):
        # TODO: This fails, when it shouldn't
        new_slot = Slot(FactFieldSource("parameters"))
        self.template.add_slot(2, new_slot)

        self.template.move_slot(0, 1)
        self.assertListEqual(self.template.components,
                             [self.literal, self.slot, new_slot])
コード例 #6
0
    def test_slot_creation_with_default_values(self):
        slot = Slot(self.to_value)

        self.assertEqual(slot.value, "some literal")
        self.assertEqual(slot.slot_type, "literal")
        self.assertIsInstance(slot.attributes, dict)
        self.assertEqual(len(slot.attributes), 0)
        self.assertIsNone(slot.fact)
コード例 #7
0
 def resolve_surface_form(self, registry: Registry, random: Generator,
                          language: str, slot: Slot, entity: str,
                          entity_type: str) -> None:
     if entity_type in ["NEWSPAPER_NAME", "NEWSPAPER"]:
         value = entity.replace("_", " ").capitalize()
     elif entity_type == "LANGUAGE":
         value = LANGUAGES.get(language, {}).get(entity)
     elif entity_type == "DATE":
         value = entity[:10]
     else:
         return
     # Was one of the matching things
     slot.value = lambda f: value
    def setUp(self):
        self.fact = Fact(
            "1",
            "kissa",
            "params",
            "id",
        )
        self.message = Message(self.fact)

        self.expr = FactField("type")
        self.matcher = Matcher(self.expr, "=", "1")
        self.rules = [([self.matcher], [0])]

        self.slot = Slot(FactFieldSource("name"))
        self.literal = LiteralSlot("sana")
        self.components = [self.slot, self.literal]

        self.template = Template(self.components, self.rules)
        self.template.fill(self.message, [self.message])

        self.realizer = FinnishUralicNLPMorphologicalRealizer()
コード例 #9
0
 def test_template_added_slot_is_last_component(self):
     new_slot = Slot(FactFieldSource("parameters"))
     self.template.add_slot(2, new_slot)
     self.assertListEqual(self.template.components,
                          [self.slot, self.literal, new_slot])
コード例 #10
0
 def test_template_add_slot(self):
     new_slot = Slot(FactFieldSource("parameters"))
     self.template.add_slot(2, new_slot)
     self.assertIn(new_slot, self.template.components)
     self.assertEqual(self.template.get_slot("parameters"), new_slot)
コード例 #11
0
    def test_slot_copy_does_not_copy_fact(self):
        slot = Slot(self.to_value, self.attributes, self.fact)
        copy = slot.copy()

        self.assertIsNone(copy.fact)
コード例 #12
0
    def test_slot_value_setter_updates_slot_type(self):
        slot = Slot(self.to_value)
        slot.value = FactFieldSource("a fake type")

        self.assertEqual(slot.slot_type, "a fake type")
コード例 #13
0
    def test_slot_value_setter(self):
        slot = Slot(self.to_value)
        slot.value = LiteralSource("another literal")

        self.assertEqual(slot.value, "another literal")
コード例 #14
0
    def test_slot_creation_without_defaults(self):
        slot = Slot(self.to_value, self.attributes, self.fact)

        self.assertEqual(slot.attributes, self.attributes)
        self.assertEqual(slot.fact, self.fact)