예제 #1
0
 def test_append(self):
     dictionary = {"a": ["one"]}
     append_to_list_in_dict(dictionary, "b", 1)
     assert "b" in dictionary
     assert len(dictionary["b"]) == 1
     append_to_list_in_dict(dictionary, "a", 1)
     assert "a" in dictionary
     assert len(dictionary["a"]) == 2
예제 #2
0
 def get_synonyms_dict(self):
     if self._synonyms is None:
         self._synonyms = dict()
         for rule in self._all_rules:
             texts = [ex.text for ex in rule.generate_all()]
             if rule.slot_value is None:
                 for text in texts:
                     append_to_list_in_dict(self._synonyms, text, text)
             else:
                 extend_list_in_dict(self._synonyms, rule.slot_value, texts)
     return self._synonyms
예제 #3
0
파일: rasa_md.py 프로젝트: volerog/Chatette
    def _write_batch(self, output_file_handle, batch):
        prepared_examples = dict()
        for example in batch.examples:
            append_to_list_in_dict(prepared_examples, example.intent_name,
                                   self.prepare_example(example))

        for intent_name in prepared_examples:
            output_file_handle.write("## intent:" +
                                     cast_to_unicode(intent_name) + '\n')
            for text in prepared_examples[intent_name]:
                output_file_handle.write(cast_to_unicode("- " + text + '\n'))
            output_file_handle.write(cast_to_unicode('\n'))

        output_file_handle.write(
            cast_to_unicode(self.__format_synonyms(batch.synonyms)))

        remainder = self._get_base_to_extend()
        if remainder is not None:
            output_file_handle.write(cast_to_unicode(remainder) + '\n')