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)
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)
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])
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)
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])
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)
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()
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])
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)
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)
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")
def test_slot_value_setter(self): slot = Slot(self.to_value) slot.value = LiteralSource("another literal") self.assertEqual(slot.value, "another literal")
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)