当前位置: 首页>>代码示例>>Python>>正文


Python jsbeautifier.default_options方法代码示例

本文整理汇总了Python中jsbeautifier.default_options方法的典型用法代码示例。如果您正苦于以下问题:Python jsbeautifier.default_options方法的具体用法?Python jsbeautifier.default_options怎么用?Python jsbeautifier.default_options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsbeautifier的用法示例。


在下文中一共展示了jsbeautifier.default_options方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_answer_to_ccr_csqa

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def add_answer_to_ccr_csqa(ccr_path, dataset_path, output_path):
    with open(ccr_path, "r", encoding="utf8") as f:
        ccr = json.load(f)

    with open(dataset_path, "r", encoding="utf8") as f:
        for i, line in enumerate(f.readlines()):
            csqa_json = json.loads(line)
            for j, ans in enumerate(csqa_json["question"]["choices"]):
                ccr[i * 5 + j]["stem"] = csqa_json["question"]["stem"].lower()
                ccr[i * 5 + j]["answer"] = ans["text"].lower()

    with open(output_path, "w", encoding="utf8") as f:
        import jsbeautifier
        opts = jsbeautifier.default_options()
        opts.indent_size = 2
        f.write(jsbeautifier.beautify(json.dumps(ccr), opts)) 
开发者ID:INK-USC,项目名称:KagNet,代码行数:18,代码来源:add_answer_to_ccr.py

示例2: add_answer_to_ccr_swag

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def add_answer_to_ccr_swag(ccr_path, dataset_path, output_path):
    with open(ccr_path, "r", encoding="utf8") as f:
        ccr = json.load(f)

    with open(dataset_path, "r", encoding="utf8") as csvfile:
        reader = csv.reader(csvfile)
        next(reader)  # Skip first line (header).
        for i, row in tqdm(enumerate(reader)):
            stem = row[4] + " " + row[5]
            answers = row[7:11]

            for j, ans in enumerate(answers):
                ccr[i * 4 + j]["stem"] = stem.lower()
                ccr[i * 4 + j]["answer"] = ans.lower()

    with open(output_path, "w", encoding="utf8") as f:
        import jsbeautifier
        opts = jsbeautifier.default_options()
        opts.indent_size = 2
        f.write(jsbeautifier.beautify(json.dumps(ccr), opts))
        #json.dump(ccr, f)


# python add_answer_to_ccr.py --mode csqa --ccr_path csqa_new/train_rand_split.jsonl.statements.ccr --dataset_path csqa_new/train_rand_split.jsonl.statements --output_path csqa_new/train_rand_split.jsonl.statements.ccr.a 
开发者ID:INK-USC,项目名称:KagNet,代码行数:26,代码来源:add_answer_to_ccr.py

示例3: combine

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def combine():
    final_json = []
    PATH = sys.argv[2]
    for i in range(NUM_BATCHES):
        with open(PATH + ".%d.mcp"%i) as fp:
            tmp_list = json.load(fp)
        final_json += tmp_list
    import jsbeautifier
    opts = jsbeautifier.default_options()
    opts.indent_size = 2


    with open(PATH + ".mcp", 'w') as fp:
        fp.write(jsbeautifier.beautify(json.dumps(final_json), opts)) 
开发者ID:INK-USC,项目名称:KagNet,代码行数:16,代码来源:batched_grounding.py

示例4: setUpClass

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def setUpClass(cls):
        options = jsbeautifier.default_options()
        options.indent_size = 4
        options.indent_char = ' '
        options.preserve_newlines = True
        options.jslint_happy = False
        options.keep_array_indentation = False
        options.brace_style = 'collapse'
        options.indent_level = 0

        cls.options = options
        cls.wrapregex = re.compile('^(.+)$', re.MULTILINE) 
开发者ID:Masood-M,项目名称:yalih,代码行数:14,代码来源:testindentation.py

示例5: setUpClass

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def setUpClass(cls):
        options = jsbeautifier.default_options()
        options.indent_size = 4
        options.indent_char = ' '
        options.preserve_newlines = True
        options.jslint_happy = False
        options.keep_array_indentation = False
        options.brace_style = 'collapse'
        options.indent_level = 0
        options.break_chained_methods = False
        options.eol = '\n'


        cls.options = options
        cls.wrapregex = re.compile('^(.+)$', re.MULTILINE) 
开发者ID:mrknow,项目名称:filmkodi,代码行数:17,代码来源:testjsbeautifier.py

示例6: process

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def process(self, data):
        super(DeenPluginJsBeautifierFormatter, self).process(data)
        if not JSBEAUTIFIER:
            self.log.warning('jsbeautifier is not available')
            return
        opts = jsbeautifier.default_options()
        opts.unescape_strings = True
        try:
            data = jsbeautifier.beautify(data.decode(), opts).encode()
        except (UnicodeDecodeError, TypeError) as e:
            self.error = e
            self.log.error(self.error)
            self.log.debug(self.error, exc_info=True)
            return
        return data 
开发者ID:takeshixx,项目名称:deen,代码行数:17,代码来源:plugin_jsbeautifier.py

示例7: pretty_json_dumps

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def pretty_json_dumps(inputs):
    js_opts = jsbeautifier.default_options()
    js_opts.indent_size = 2

    inputs = remove_none(inputs)
    return jsbeautifier.beautify(json.dumps(inputs)) 
开发者ID:naver,项目名称:claf,代码行数:8,代码来源:utils.py

示例8: un_zip

# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import default_options [as 别名]
def un_zip(target_path):
    """
    解压缩目标压缩包
    实现新需求,解压缩后相应的js文件做代码格式化
    :return: 
    """

    logger.info("[Pre][Unzip] Upzip file {}...".format(target_path))

    if not os.path.isfile(target_path):
        logger.warn("[Pre][Unzip] Target file {} is't exist...pass".format(target_path))
        return False

    zip_file = zipfile.ZipFile(target_path)
    target_file_path = target_path + "_files/"

    if os.path.isdir(target_file_path):
        logger.debug("[Pre][Unzip] Target files {} is exist...continue".format(target_file_path))
        return target_file_path
    else:
        os.mkdir(target_file_path)

    for names in zip_file.namelist():
        zip_file.extract(names, target_file_path)

        # 对其中部分文件中为js的时候,将js代码格式化便于阅读
        if names.endswith(".js"):
            file_path = os.path.join(target_file_path, names)
            file = codecs.open(file_path, 'r+', encoding='utf-8', errors='ignore')
            file_content = file.read()
            file.close()

            new_file = codecs.open(file_path, 'w+', encoding='utf-8', errors='ignore')

            opts = jsbeautifier.default_options()
            opts.indent_size = 2

            new_file.write(jsbeautifier.beautify(file_content, opts))
            new_file.close()

    zip_file.close()

    return target_file_path 
开发者ID:LoRexxar,项目名称:Cobra-W,代码行数:45,代码来源:pretreatment.py


注:本文中的jsbeautifier.default_options方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。