def export_data(self):
        weights = [[], []]
        for neuron in self.neuron_layers[0]:
            weights[0].extend(neuron.weights)
        for neuron in self.neuron_layers[1]:
            weights[1].extend(neuron.weights)

        weights_path = pathlib.Path('weights.json')
        weights_path.write_text(
            json_file.list_to_json(weights, json_file.data_to_json), 'utf-8')

        network_info = pathlib.Path('network_info.json')
        network_info.write_text(json_file.list_to_json(
            [self.input_size, self.hidden_size, self.genre_num],
            json_file.data_to_json),
                                encoding='utf-8')

        wordtoindex_dic_path = pathlib.Path('wordtoindex.json')
        wordtoindex_dic_path.write_text(json_file.dict_to_json(
            self.wordtoindex_dic, json_file.data_to_json),
                                        encoding='utf-8')

        genretoindex_dic_path = pathlib.Path('genretoindex.json')
        genretoindex_dic_path.write_text(json_file.dict_to_json(
            self.genretoindex_dic, json_file.data_to_json),
                                         encoding='utf-8')
 def export_data(self):
     coordpath = pathlib.Path('coordinates.json')
     coordpath.write_text(json_file.list_to_json(self.coords,
                                                 json_file.data_to_json),
                          encoding='utf-8')
     distpath = pathlib.Path('dist.json')
     distpath.write_text(json_file.list_to_json(self.real_dist,
                                                json_file.data_to_json),
                         encoding='utf-8')
Beispiel #3
0
    def export_data(self):
        book_p = pathlib.Path('book_data.json')
        book_p.write_text(json_file.list_to_json(self.book_list,
                                                 json_file.data_to_json),
                          encoding='utf-16')

        dic_p = pathlib.Path('date_to_book.json')
        dic_p.write_text(json_file.dict_to_json(self.date_to_book,
                                                json_file.data_to_json),
                         encoding='utf-16')
    def export_data(self):
        coordpath = pathlib.Path('coordinates.json')
        coord_json = json.dumps(
            json_file.list_to_json(self.coords, json_file.data_to_json))
        if coordpath.exists():
            file_data = coordpath.read_text(encoding='utf-8')
            if file_data != coord_json:
                coordpath.write_text(coord_json, encoding='utf-8')
        else:
            coordpath.write_text(coord_json, encoding='utf-8')

        distpath = pathlib.Path('dist.json')
        dist_json = json.dumps(
            json_file.list_to_json(self.real_dist, json_file.data_to_json))
        if distpath.exists():
            file_data = distpath.read_text(encoding='utf-8')
            if file_data != dist_json:
                distpath.write_text(dist_json, encoding='utf-8')
        else:
            distpath.write_text(dist_json, encoding='utf-8')
    def export_data(self):
        dic_p = pathlib.Path('word_prob.json')
        dic_p.write_text(json_file.list_to_json([[x, y]
                                                 for x, y in self.word_probs],
                                                json_file.data_to_json),
                         encoding='utf-16')

        dic_p = pathlib.Path('genre_num.json')
        dic_p.write_text(json_file.dict_to_json(self.genre_list,
                                                json_file.data_to_json),
                         encoding='utf-16')
    def make_training_set(self, num) :
        ordinary_set = self.get_ordinary_books()
        if num < len(ordinary_set):
            self.training_set = random.sample(ordinary_set, num)

        self.training_set = [{"book":b, "genre":[]} for b in self.training_set]

        tra_p = pathlib.Path('training_set.json')
        tra_json = json.dumps(json_file.list_to_json(self.training_set, json_file.data_to_json))
        if tra_p.exists():
            file_data = tra_p.read_text(encoding='utf-16')
            if file_data != tra_json:
                tra_p.write_text(tra_json, encoding='utf-16')
        else:
            tra_p.write_text(tra_json, encoding='utf-16')
    def export_data(self) :
        book_p = pathlib.Path('book_data.json')
        book_json = json.dumps(json_file.list_to_json(self.book_list, json_file.data_to_json))
        try:
            if book_p.exists() :
                file_data = book_p.read_text(encoding='utf-16')
                if file_data != book_json :
                    book_p.write_text(book_json, encoding='utf-16')
            else :
                book_p.write_text(book_json, encoding='utf-16')
        except:
            print("exception occured")

        dic_p = pathlib.Path('date_to_book.json')
        dic_json = json.dumps(json_file.dict_to_json(self.date_to_book, json_file.data_to_json))
        if dic_p.exists():
            file_data = dic_p.read_text(encoding='utf-16')
            if file_data != dic_json:
                dic_p.write_text(dic_json, encoding='utf-16')
        else:
            dic_p.write_text(dic_json, encoding='utf-16')
Beispiel #8
0
    tra_path = pathlib.Path("../training_set.json")
    if tra_path.exists():
        temp = tra_path.read_text(encoding='utf-16')
        book_dict = json.loads(temp, strict=False)

        for dic in book_dict:
            new_book = book_data.BookData()
            new_book.from_json_dict(dic["book"])
            dic["book"] = new_book

        training_set = book_dict

    t_json = []
    for t in training_set:
        data = t["book"].title
        pos = json_file.list_to_json([{
            "segment": n,
            "tag": t
        } for n, t in nlp_module.pos_Twitter(data)], json_file.data_to_json)
        t_json.append({"string": data, "pos": pos})

        data = t["book"].description
        pos = json_file.list_to_json([{
            "segment": n,
            "tag": t
        } for n, t in nlp_module.pos_Twitter(data)], json_file.data_to_json)
        t_json.append({"string": data, "pos": pos})

    tra_path = pathlib.Path("nlp_training_set.json")
    tra_path.write_text(json_file.list_to_json(t_json, json_file.data_to_json),
                        encoding='utf-8')
    def export_as_text(self) :
        txt_p = pathlib.Path('book_data.txt')
        book_list = json_file.list_to_json(self.book_list, json_file.data_to_json)

        txt_p.write_text(str(book_list), encoding='utf-8')