當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。