Beispiel #1
0
    def update_setting(self) -> None:
        """
        Get setting value from line edits and update global setting file.
        """
        settings = {}
        for field_name, tp in self.widgets.items():
            widget, field_type = tp
            value_text = widget.text()

            if field_type == bool:
                if value_text == "True":
                    field_value = True
                else:
                    field_value = False
            else:
                field_value = field_type(value_text)

            settings[field_name] = field_value

        QtWidgets.QMessageBox.information(self, "注意",
                                          "全局配置的修改需要重启VN Trader后才会生效!",
                                          QtWidgets.QMessageBox.Ok)

        save_json(SETTING_FILENAME, settings)
        self.accept()
    def save_model(self):
        path = self.saver.save(self.sess, self.path)
        try:
            with open(self.log_dir + "simple_log.json", "r") as f:
                d = json.load(f)
        except:
            d = dict()

        d["current_i"] = self.current_i

        utility.save_json(d, self.log_dir + "simple_log.json")

        print("model saved in path ", path)
        return
Beispiel #3
0
    def connect(self) -> None:
        """
        Get setting value from line edits and connect the gateway.
        """
        setting = {}
        for field_name, tp in self.widgets.items():
            widget, field_type = tp
            if field_type == list:
                field_value = str(widget.currentText())
            else:
                field_value = field_type(widget.text())
            setting[field_name] = field_value

        save_json(self.filename, setting)

        self.main_engine.connect(setting, self.gateway_name)

        self.accept()
    def test(self):
        # Test trained model
        print("now start evaluating the trained model")
        acc = self.sess.run(self.accuracy,
                            feed_dict={
                                self.x: self.data_set.test.images,
                                self.y_: self.data_set.test.labels
                            })
        print("accuracy is ", acc)
        try:
            self.simple_log = utility.load_json(self.log_dir +
                                                "simple_log.json")
        except:
            print("simple log does not exist, create a new one")
            self.simple_log = dict()

        self.simple_log["current_i"] = self.current_i
        self.simple_log["acc at " + str(self.current_i)] = float(acc)
        utility.save_json(self.simple_log, self.log_dir + "simple_log.json")
Beispiel #5
0
if __name__ == '__main__':
    # cmd line colours
    RESET = '\033[0;0m'
    RED = '\033[0;31m'
    GREEN = '\033[0;32m'

    # TODO add path_out
    ap = argparse.ArgumentParser()

    # positional arguments
    ap.add_argument('input', help='mal ANIME url')

    args = vars(ap.parse_args())

    # input validation
    if utility.get_mal_type(args['input']) is not 'anime':
        print('{}ERROR: given url ({}) is not a valid mal anime url'.format(
            RED, args['input']))
        sys.stdout.write(RESET)
        sys.exit()
    try:
        data = get_anime_info(args['input'], full=False)

        output_filename = 'output_{}.json'.format(re.sub(r'\W', '', timestamp))
        utility.save_json(data, output_filename)
        print('{}information saved to file: {}'.format(GREEN, output_filename))
    except Exception as e:
        print('{}ERROR: {}'.format(RED, str(e)))

    sys.stdout.write(RESET)
Beispiel #6
0
 def save_data(self):
     save_json(self.data_dic, '../data/ssu_notice.json')
     print('수집 결과를 저장합니다.')
     return
from utility import load_json, save_json

# 1. Strip empty lines
CUR_PATH = os.path.abspath('.')
if os.path.exists(config.PATH_STRIP):
    raw_wiki_lines = load_json(config.PATH_STRIP)
else:
    print("Load raw files:")
    raw_wiki_lines = []
    with open('computed/wiki.txt', 'r') as fin:
        for line in fin:
            line = line.strip()
            if len(line) > 0:
                raw_wiki_lines.append(line)
    try:
        save_json(raw_wiki_lines, config.PATH_STRIP)
    except:
        os.remove(config.PATH_STRIP)
        exit(1)

# 2. Segment lines
if os.path.exists(config.PATH_NEWLINE):
    new_lines = load_json(config.PATH_NEWLINE)
else:
    new_lines = []
    for line in tqdm(raw_wiki_lines, desc="Sentence segmentation", unit="Lns"):
        new_lines.extend(sent_tokenize(line))
    try:
        save_json(new_lines, config.PATH_NEWLINE)
    except:
        os.remove(config.PATH_NEWLINE)