示例#1
0
 def __init__(
     self,
     values: Dict[TemplateSlot, Collection["Template"]] = None,
     replacements: Dict[TemplateSlot, TemplateSlot] = None,
 ):
     if values is None:
         values = dict()
     self._replacements = (hashabledict(replacements)
                           if replacements is not None else hashabledict())
     super(SlotValues, self).__init__(values)
示例#2
0
    def test_merge_small_overlap(self):
        slot_values = SlotValues({self.a: self.e12, self.b: self.e23})

        merged = slot_values.merge_slots(relative_similarity_threshold=0.3)

        self.assertEqual(hashabledict({self.b: self.a}),
                         merged.get_replacements())
        self.assertEqual(
            SlotValues({
                self.a: self.e123,
                self.b: {Template([self.a])}
            }),
            merged,
        )
示例#3
0
    def test_merge_containing_slot(self):
        slot_values = SlotValues({
            self.a: {Template([self.b]), self.e1, self.e2, self.e3},
            self.b: self.e123,
            self.c: self.e456,
        })

        merged = slot_values.merge_slots()

        self.assertEqual(hashabledict({self.a: self.b}),
                         merged.get_replacements())
        self.assertEqual(
            SlotValues({
                self.a: {Template([self.b])},
                self.b: self.e123,
                self.c: self.e456
            }),
            merged,
        )
示例#4
0
    def test_merge_basic(self):
        slot_values = SlotValues({
            self.a: self.e123,
            self.b: self.e123,
            self.c: self.e456
        })

        merged = slot_values.merge_slots()

        self.assertEqual(hashabledict({self.b: self.a}),
                         merged.get_replacements())
        self.assertEqual(
            SlotValues({
                self.a: self.e123,
                self.b: {Template([self.a])},
                self.c: self.e456
            }),
            merged,
        )
示例#5
0
    def test_merge_containing_multiple_slots_complely(self):
        slot_values = SlotValues({
            self.a: {Template([self.b]),
                     Template([self.c]), self.e1, self.e2},
            self.b: self.e123,
            self.c: self.e123,
        })

        merged = slot_values.merge_slots()

        self.assertEqual(hashabledict({
            self.a: self.b,
            self.c: self.b
        }), merged.get_replacements())
        self.assertEqual(
            SlotValues({
                self.a: {Template([self.b])},
                self.b: self.e123,
                self.c: {Template([self.b])},
            }),
            merged,
        )