當前位置: 首頁>>代碼示例>>Python>>正文


Python ujson.load方法代碼示例

本文整理匯總了Python中ujson.load方法的典型用法代碼示例。如果您正苦於以下問題:Python ujson.load方法的具體用法?Python ujson.load怎麽用?Python ujson.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ujson的用法示例。


在下文中一共展示了ujson.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_dataset

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def load_dataset(path):
    """Load json file and store fields separately."""
    with open(path) as f:
        data = json.load(f)['data']
    output = {'qids': [], 'questions': [], 'answers': [],
              'contexts': [], 'qid2cid': []}
    for article in data:
        for paragraph in article['paragraphs']:
            output['contexts'].append(paragraph['context'])
            for qa in paragraph['qas']:
                output['qids'].append(qa['id'])
                output['questions'].append(qa['question'])
                output['qid2cid'].append(len(output['contexts']) - 1)
                if 'answers' in qa:
                    output['answers'].append(qa['answers'])
    return output 
開發者ID:HKUST-KnowComp,項目名稱:MnemonicReader,代碼行數:18,代碼來源:preprocess.py

示例2: load_answers

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def load_answers(filename):
    """Load the answers only of a SQuAD dataset. Store as qid -> [answers]."""
    # Load JSON file
    with open(filename) as f:
        examples = json.load(f)['data']

    ans = {}
    for article in examples:
        for paragraph in article['paragraphs']:
            for qa in paragraph['qas']:
                ans[qa['id']] = list(map(lambda x: x['text'], qa['answers']))
    return ans


# ------------------------------------------------------------------------------
# Dictionary building
# ------------------------------------------------------------------------------ 
開發者ID:HKUST-KnowComp,項目名稱:MnemonicReader,代碼行數:19,代碼來源:utils.py

示例3: configure

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def configure(ctx):
    """
    Configure the following application settings:

    (1) Default encoding to load files.
    (2) HTTP/HTTPS proxy server URI (for url sub-command).

    Configurations are written to '~/.sqlitebiter'.
    You can remove these settings by deleting '~/.sqlitebiter'.
    """

    initialize_logger("{:s} file".format(PROGRAM_NAME), ctx.obj[Context.LOG_LEVEL])

    logger.debug("{} configuration file existence: {}".format(PROGRAM_NAME, app_config_mgr.exists))

    sys.exit(app_config_mgr.configure()) 
開發者ID:thombashi,項目名稱:sqlitebiter,代碼行數:18,代碼來源:__main__.py

示例4: __init__

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def __init__(self, config=None):

		if isinstance(config, dict) or isinstance(config, OrderedDict):
			self.config = config
		elif isinstance(config, str):
			try:
				self.config = json.load(open(config, "r"))
			except:
				self.config = {}

		self.username = self.config.get("username", "data_security_es_45")
		self.password = self.config.get("password", "Nb6121ca7ffe3")
		es_url = self.config.get("es_url", ['http://zsearch.alipay.com:9999'])

		if isinstance(es_url, list):
			self.es_url = es_url
		else:
			self.es_url = [es_url]

		self.es = Elasticsearch(self.es_url, http_auth=(self.username, self.password)) 
開發者ID:yyht,項目名稱:BERT,代碼行數:22,代碼來源:es_indexing.py

示例5: populate_new_fields

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def populate_new_fields(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
    # Open the JSON file which contains the data to be used for migration.
    MIGRATION_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "management", "data")
    path_to_unified_reactions = os.path.join(MIGRATION_DATA_PATH, "unified_reactions.json")
    unified_reactions = ujson.load(open(path_to_unified_reactions))

    Reaction = apps.get_model('zerver', 'Reaction')
    for reaction in Reaction.objects.all():
        reaction.emoji_code = unified_reactions.get(reaction.emoji_name)
        if reaction.emoji_code is None:
            # If it's not present in the unified_reactions map, it's a realm emoji.
            reaction.emoji_code = reaction.emoji_name
            if reaction.emoji_name == 'zulip':
                # `:zulip:` emoji is a zulip special custom emoji.
                reaction.reaction_type = 'zulip_extra_emoji'
            else:
                reaction.reaction_type = 'realm_emoji'
        reaction.save() 
開發者ID:zulip,項目名稱:zulip,代碼行數:20,代碼來源:0097_reactions_emoji_code.py

示例6: team_view

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def team_view(request: HttpRequest) -> HttpResponse:
    if not settings.ZILENCER_ENABLED:
        return HttpResponseRedirect('https://zulip.com/team/', status=301)

    try:
        with open(settings.CONTRIBUTOR_DATA_FILE_PATH) as f:
            data = ujson.load(f)
    except FileNotFoundError:
        data = {'contrib': {}, 'date': "Never ran."}

    return TemplateResponse(
        request,
        'zerver/team.html',
        context={
            'page_params': {
                'contrib': data['contrib'],
            },
            'date': data['date'],
        },
    ) 
開發者ID:zulip,項目名稱:zulip,代碼行數:22,代碼來源:portico.py

示例7: create_language_name_map

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def create_language_name_map(self) -> None:
        join = os.path.join
        deploy_root = settings.DEPLOY_ROOT
        path = join(deploy_root, 'locale', 'language_options.json')
        output_path = join(deploy_root, 'locale', 'language_name_map.json')

        with open(path) as reader:
            languages = ujson.load(reader)
            lang_list = []
            for lang_info in languages['languages']:
                lang_info['name'] = lang_info['name_local']
                del lang_info['name_local']
                lang_list.append(lang_info)

            lang_list.sort(key=lambda lang: lang['name'])

        with open(output_path, 'w') as output_file:
            ujson.dump({'name_map': lang_list}, output_file, indent=4, sort_keys=True)
            output_file.write('\n') 
開發者ID:zulip,項目名稱:zulip,代碼行數:21,代碼來源:compilemessages.py

示例8: export_usermessages_batch

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def export_usermessages_batch(input_path: Path, output_path: Path,
                              consent_message_id: Optional[int]=None) -> None:
    """As part of the system for doing parallel exports, this runs on one
    batch of Message objects and adds the corresponding UserMessage
    objects. (This is called by the export_usermessage_batch
    management command)."""
    with open(input_path) as input_file:
        output = ujson.load(input_file)
    message_ids = [item['id'] for item in output['zerver_message']]
    user_profile_ids = set(output['zerver_userprofile_ids'])
    del output['zerver_userprofile_ids']
    realm = Realm.objects.get(id=output['realm_id'])
    del output['realm_id']
    output['zerver_usermessage'] = fetch_usermessages(realm, set(message_ids), user_profile_ids,
                                                      output_path, consent_message_id)
    write_message_export(output_path, output)
    os.unlink(input_path) 
開發者ID:zulip,項目名稱:zulip,代碼行數:19,代碼來源:export.py

示例9: read_metric

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def read_metric(path: str) -> List[int]:
    """
    Read metric file in JSON or Rdump format.
    Return dimensions of entry "inv_metric".
    """
    if path.endswith('.json'):
        with open(path, 'r') as fd:
            metric_dict = json.load(fd)
        if 'inv_metric' in metric_dict:
            dims = np.asarray(metric_dict['inv_metric'])
            return list(dims.shape)
        else:
            raise ValueError(
                'metric file {}, bad or missing'
                ' entry "inv_metric"'.format(path)
            )
    else:
        dims = list(read_rdump_metric(path))
        if dims is None:
            raise ValueError(
                'metric file {}, bad or missing'
                ' entry "inv_metric"'.format(path)
            )
        return dims 
開發者ID:stan-dev,項目名稱:cmdstanpy,代碼行數:26,代碼來源:utils.py

示例10: Apps

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def Apps(self, data=None):
        self.destroy()
        self.create_window(show=False)
        self.btngroup = ButtonGroup(self.window, 40, 30, 240, 40, 10)
        self.widgets.append(self.btngroup)
        for app in uos.listdir('/apps'):
            try:
                with open('/apps/{}/app.json'.format(app)) as fp:
                    data = json.load(fp)
            except Exception as e:
                print(e)
                continue
            if 'name' in data:
                self.btngroup.add(data['name'], self.run_app, data=app)
        self.btngroup.end()
        self.window.show() 
開發者ID:IBM-Developer-Korea,項目名稱:developer-badge-2018-apps,代碼行數:18,代碼來源:launcher.py

示例11: process_file

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def process_file(filename, config, word_counter=None, char_counter=None):
    data = json.load(open(filename, 'r'))

    examples = []
    eval_examples = {}

    outputs = Parallel(n_jobs=12, verbose=10)(delayed(_process_article)(article, config) for article in data)
    # outputs = [_process_article(article, config) for article in data]
    examples = [e[0] for e in outputs]
    for _, e in outputs:
        if e is not None:
            eval_examples[e['id']] = e

    # only count during training
    if word_counter is not None and char_counter is not None:
        for example in examples:
            for token in example['ques_tokens'] + example['context_tokens']:
                word_counter[token] += 1
                for char in token:
                    char_counter[char] += 1

    random.shuffle(examples)
    print("{} questions in total".format(len(examples)))

    return examples, eval_examples 
開發者ID:hotpotqa,項目名稱:hotpot,代碼行數:27,代碼來源:prepro.py

示例12: setUpClass

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def setUpClass(self):
        t0 = time.time()

        # Test data comes from NED
        with open(os.path.join(test_dir, 'ned_output.json'), 'r') as f:
            self._test_data = json.load(f)

        # Set up SFD query object
        self._sfd = sfd.SFDQuery()

        t1 = time.time()
        print('Loaded SFD test data in {:.5f} s.'.format(t1-t0)) 
開發者ID:gregreen,項目名稱:dustmaps,代碼行數:14,代碼來源:test_sfd.py

示例13: read_as_pickle

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def read_as_pickle(data_path, **kwargs):
    '''Submethod to read data as pickle'''
    with open(data_path, 'rb') as f:
        data = pickle.load(f)
    return data 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:7,代碼來源:util.py

示例14: read_as_plain

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def read_as_plain(data_path, **kwargs):
    '''Submethod to read data as plain type'''
    open_file = open(data_path, 'r')
    ext = get_file_ext(data_path)
    if ext == '.json':
        data = ujson.load(open_file, **kwargs)
    elif ext == '.yml':
        data = yaml.load(open_file, **kwargs)
    else:
        data = open_file.read()
    open_file.close()
    return data 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:14,代碼來源:util.py

示例15: load_text

# 需要導入模塊: import ujson [as 別名]
# 或者: from ujson import load [as 別名]
def load_text(filename):
    """Load the paragraphs only of a SQuAD dataset. Store as qid -> text."""
    # Load JSON file
    with open(filename) as f:
        examples = json.load(f)['data']

    texts = {}
    for article in examples:
        for paragraph in article['paragraphs']:
            for qa in paragraph['qas']:
                texts[qa['id']] = paragraph['context']
    return texts 
開發者ID:HKUST-KnowComp,項目名稱:MnemonicReader,代碼行數:14,代碼來源:utils.py


注:本文中的ujson.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。