Esempio n. 1
0
    def test_nb(self):
        """Tests that the cast doesn't do anything for numeric types."""
        res_int = cast_to_unicode(5)
        assert res_int == 5

        res_float = cast_to_unicode(3.14159265)
        assert res_float == 3.14159265

        res_complex = cast_to_unicode(complex(1,2))
        assert res_complex == complex(1,2)
Esempio n. 2
0
    def test_dict(self):
        dicts = [{"a": "b"}, {}, {"c": 0, 1: "d"}, {"e": {"f": "g", 0: ["h", 3]}}]

        for d in dicts:
            res_dict = cast_to_unicode(d)
            if sys.version_info[0] == 3:
                assert res_dict == d
            else:
                self.check_is_unicode(res_dict)
Esempio n. 3
0
    def write(self, output_directory, examples, synonyms):
        super(JsonListAdapter, self).write(output_directory, examples, synonyms)

        processed_synonyms = self.__synonym_format(synonyms)
        if processed_synonyms is not None:
            synonyms_file_path = os.path.join(output_directory, "synonyms.json")
            with io.open(synonyms_file_path, 'w') as output_file:
                output_file.write(json.dumps(cast_to_unicode(processed_synonyms),
                                             ensure_ascii=False,
                                             sort_keys=True, indent=2))
Esempio n. 4
0
    def _write_batch(self, output_file_handle, batch):
        rasa_entities = [self.prepare_example(ex) for ex in batch.examples]

        json_data = {
            "rasa_nlu_data": {
                "common_examples": rasa_entities,
                "regex_features": [],
                "entity_synonyms": self.__synonym_format(batch.synonyms),
            }
        }

        json_data = cast_to_unicode(json_data)
        output_file_handle.write(
            json.dumps(json_data, ensure_ascii=False, indent=2,
                       sort_keys=True))
Esempio n. 5
0
 def prepare_example(self, example):
     example.text = example.text.replace(ENTITY_MARKER, "")
     return json.dumps(cast_to_unicode(example.__dict__), ensure_ascii=False, sort_keys=True)