How to use ujson - 10 common examples

To help you get started, we’ve selected a few ujson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HKUST-KnowComp / R-Net / main.py View on Github external
sess.run(tf.assign(model.is_train, tf.constant(False, dtype=tf.bool)))
        losses = []
        answer_dict = {}
        remapped_dict = {}
        for step in tqdm(range(total // config.batch_size + 1)):
            qa_id, loss, yp1, yp2 = sess.run(
                [model.qa_id, model.loss, model.yp1, model.yp2])
            answer_dict_, remapped_dict_ = convert_tokens(
                eval_file, qa_id.tolist(), yp1.tolist(), yp2.tolist())
            answer_dict.update(answer_dict_)
            remapped_dict.update(remapped_dict_)
            losses.append(loss)
        loss = np.mean(losses)
        metrics = evaluate(eval_file, answer_dict)
        with open(config.answer_file, "w") as fh:
            json.dump(remapped_dict, fh)
        print("Exact Match: {}, F1: {}".format(
            metrics['exact_match'], metrics['f1']))
github burglarhobbit / machine-reading-comprehension / S-NET / 4_snet_without_pr_para_strip / main.py View on Github external
remapped_dict = {}
		for step in tqdm(range(total // config.batch_size + 1)):
			qa_id, loss, yp1, yp2 = sess.run(
				[model.qa_id, model.loss, model.yp1, model.yp2])
			answer_dict_, remapped_dict_, outlier = convert_tokens(
				eval_file, qa_id.tolist(), yp1.tolist(), yp2.tolist())
			answer_dict.update(answer_dict_)
			remapped_dict.update(remapped_dict_)
			losses.append(loss)
		loss = np.mean(losses)

		# evaluate with answer_dict, but in evaluate-v1.1.py, evaluate with remapped_dict
		# since only that is saved. Both dict are a little bit different, check evaluate-v1.1.py
		metrics = evaluate(eval_file, answer_dict)
		with open(config.answer_file, "w") as fh:
			json.dump(remapped_dict, fh)
		print("Exact Match: {}, F1: {} Rouge-L-F1: {} Rouge-L-p: {} Rouge-l-r: {}".format(\
			metrics['exact_match'], metrics['f1'], metrics['rouge-l-f'], metrics['rouge-l-p'],\
			metrics['rouge-l-r']))
github Gingernaut / microAuth / tests / test_admin.py View on Github external
def get_five_acccount_ids(self, test_server):
        accounts = []
        for i in range(1, 6):
            payload = {"emailAddress": f"test{i}@example.com", "password": "1234567"}
            res = test_server.post("/signup", data=ujson.dumps(payload))
            resData = res.json()
            accounts.append(resData["id"])
        return accounts
github FORTH-ICS-INSPIRE / artemis / testing / rpki / tester.py View on Github external
def get_hash(obj):
        return hashlib.shake_128(json.dumps(obj).encode("utf-8")).hexdigest(16)
github holmes-app / holmes-api / tests / unit / test_event_bus.py View on Github external
def test_on_message_when_type_message(self):
        redis, app, bus = self.get_bus()
        handler_mock = Mock()

        bus.throttling = {}

        bus.handlers['events']['uuid'] = handler_mock

        value = dumps({'type': 'test'})

        bus.on_message(('message', 'events', value))

        expect(handler_mock.called).to_be_true()
github unt-libraries / catalog-api / django / sierra / utils / test_helpers / solr_factories.py View on Github external
def fetch_schema(conn):
        """
        Fetch the Solr schema in JSON format via the provided pysolr
        connection object (`conn`).
        """
        jsn = conn._send_request('get', 'schema/fields?wt=json')
        return ujson.loads(jsn)
github esnme / ultrajson / python / tests.py View on Github external
def test_encodeTrueConversion(self):
		input = True
		output = ujson.encode(input)
		self.assertEquals(input, json.loads(output))
		self.assertEquals(output, json.dumps(input))
		self.assertEquals(input, ujson.decode(output))
		pass
github esnme / ultrajson / python / tests.py View on Github external
def test_decodeDictWithNoKey(self):
		input = "{{{{31337}}}}"
		try:
			ujson.decode(input)
			assert False, "Expected exception!"
		except(ValueError):
			return

		assert False, "Wrong exception"
github esnme / ultrajson / python / tests.py View on Github external
def test_encodeDoubleNegConversion(self):
		input = -math.pi
		output = ujson.encode(input)
		self.assertEquals(round(input, 5), round(json.loads(output), 5))
		self.assertEquals(round(input, 5), round(ujson.decode(output), 5))
		pass
github esnme / ultrajson / python / tests.py View on Github external
def test_decodeBrokenObjectStart(self):
		input = "{"
		try:
			ujson.decode(input)
			assert False, "Expected exception!"
		except(ValueError):
			return
		assert False, "Wrong exception"