



import argparse
import json
from typing import List

from ltp import LTP

from transformers import BertTokenizer

def        a						(      _UpperCAmelCase							:					Any						):







		'''simple docstring'''





		if (
		    (cp >= 0x4E00 and cp <= 0x9FFF)
		    or (cp >= 0x3400 and cp <= 0x4DBF)  #
		    or (cp >= 0x2_0000 and cp <= 0x2_A6DF)  #
		    or (cp >= 0x2_A700 and cp <= 0x2_B73F)  #
		    or (cp >= 0x2_B740 and cp <= 0x2_B81F)  #
		    or (cp >= 0x2_B820 and cp <= 0x2_CEAF)  #
		    or (cp >= 0xF900 and cp <= 0xFAFF)
		    or (cp >= 0x2_F800 and cp <= 0x2_FA1F)  #
		):  #
				return True

		return False

def        a						(      _UpperCAmelCase							:					str						):







		'''simple docstring'''





		for char in word:
				__UpperCAmelCase    :     Optional[Any]													=	ord(_UpperCAmelCase						)
				if not _is_chinese_char(_UpperCAmelCase						):
						return 0
		return 1

def        a						(      _UpperCAmelCase							:					List[str]						):







		'''simple docstring'''





		__UpperCAmelCase    :     Any													=	set()

		for token in tokens:
				__UpperCAmelCase    :     Dict													=	len(_UpperCAmelCase						) > 1 and is_chinese(_UpperCAmelCase						)
				if chinese_word:
						word_set.add(_UpperCAmelCase						)
		__UpperCAmelCase    :     List[str]													=	list(_UpperCAmelCase						)
		return word_list

def        a						(      _UpperCAmelCase							:					List[str] ,   _UpperCAmelCase							:					set()						):







		'''simple docstring'''





		if not chinese_word_set:
				return bert_tokens
		__UpperCAmelCase    :     int													=	max([len(_UpperCAmelCase						) for w in chinese_word_set]						)

		__UpperCAmelCase    :     str													=	bert_tokens
		__UpperCAmelCase							,					__UpperCAmelCase    :     Optional[Any]													=	0, len(_UpperCAmelCase						)
		while start < end:
				__UpperCAmelCase    :     Dict													=	True
				if is_chinese(bert_word[start]						):
						__UpperCAmelCase    :     Tuple													=	min(end - start ,   _UpperCAmelCase						)
						for i in range(_UpperCAmelCase ,   1 ,   -1						):
								__UpperCAmelCase    :     Union[str, Any]													=	''''''.join(bert_word[start : start + i]						)
								if whole_word in chinese_word_set:
										for j in range(start + 1 ,   start + i						):
												__UpperCAmelCase    :     Union[str, Any]													=	'''##''' + bert_word[j]
										__UpperCAmelCase    :     int													=	start + i
										__UpperCAmelCase    :     Tuple													=	False
										break
				if single_word:
						start += 1
		return bert_word

def        a						(      _UpperCAmelCase							:					List[str] ,   _UpperCAmelCase							:					LTP ,   _UpperCAmelCase							:					BertTokenizer						):







		'''simple docstring'''





		__UpperCAmelCase    :     str													=	[]

		for i in range(0 ,   len(_UpperCAmelCase						) ,   1_00						):
				__UpperCAmelCase    :     Dict													=	ltp_tokenizer.seg(lines[i : i + 1_00]						)[0]
				__UpperCAmelCase    :     Union[str, Any]													=	[get_chinese_word(_UpperCAmelCase						) for r in res]
				ltp_res.extend(_UpperCAmelCase						)
		assert len(_UpperCAmelCase						) == len(_UpperCAmelCase						)

		__UpperCAmelCase    :     Optional[Any]													=	[]
		for i in range(0 ,   len(_UpperCAmelCase						) ,   1_00						):
				__UpperCAmelCase    :     int													=	bert_tokenizer(lines[i : i + 1_00] ,   add_special_tokens=_UpperCAmelCase ,   truncation=_UpperCAmelCase ,   max_length=5_12						)
				bert_res.extend(res['''input_ids''']						)
		assert len(_UpperCAmelCase						) == len(_UpperCAmelCase						)

		__UpperCAmelCase    :     List[str]													=	[]
		for input_ids, chinese_word in zip(_UpperCAmelCase ,   _UpperCAmelCase						):
				__UpperCAmelCase    :     List[str]													=	[]
				for id in input_ids:
						__UpperCAmelCase    :     str													=	bert_tokenizer._convert_id_to_token(_UpperCAmelCase						)
						input_tokens.append(_UpperCAmelCase						)
				__UpperCAmelCase    :     Any													=	add_sub_symbol(_UpperCAmelCase ,   _UpperCAmelCase						)
				__UpperCAmelCase    :     Tuple													=	[]
				# We only save pos of chinese subwords start with ##, which mean is part of a whole word.
				for i, token in enumerate(_UpperCAmelCase						):
						if token[:2] == "##":
								__UpperCAmelCase    :     Any													=	token[2:]
								# save chinese tokens' pos
								if len(_UpperCAmelCase						) == 1 and _is_chinese_char(ord(_UpperCAmelCase						)						):
										ref_id.append(_UpperCAmelCase						)
				ref_ids.append(_UpperCAmelCase						)

		assert len(_UpperCAmelCase						) == len(_UpperCAmelCase						)

		return ref_ids

def        a						(      _UpperCAmelCase							:					List[Any]						):







		'''simple docstring'''





		with open(args.file_name ,   '''r''' ,   encoding='''utf-8'''						) as f:
				__UpperCAmelCase    :     Union[str, Any]													=	f.readlines()
		__UpperCAmelCase    :     str													=	[line.strip() for line in data if len(_UpperCAmelCase						) > 0 and not line.isspace()]  # avoid delimiter like '\u2029'
		__UpperCAmelCase    :     Any													=	LTP(args.ltp						)  # faster in GPU device
		__UpperCAmelCase    :     str													=	BertTokenizer.from_pretrained(args.bert						)

		__UpperCAmelCase    :     Any													=	prepare_ref(_UpperCAmelCase ,   _UpperCAmelCase ,   _UpperCAmelCase						)

		with open(args.save_path ,   '''w''' ,   encoding='''utf-8'''						) as f:
				__UpperCAmelCase    :     Optional[int]													=	[json.dumps(_UpperCAmelCase						) + '''\n''' for ref in ref_ids]
				f.writelines(_UpperCAmelCase						)


if __name__ == "__main__":
				__A   			=argparse.ArgumentParser(description="prepare_chinese_ref")
				parser.add_argument(
				    "--file_name",
				    type=str,
				    default="./resources/chinese-demo.txt",
				    help="file need process, same as training data in lm",
				)
				parser.add_argument(
				    "--ltp", type=str, default="./resources/ltp", help="resources for LTP tokenizer, usually a path"
				)
				parser.add_argument("--bert", type=str, default="./resources/robert", help="resources for Bert tokenizer")
				parser.add_argument("--save_path", type=str, default="./resources/ref.txt", help="path to save res")

				__A   			=parser.parse_args()
				main(args)










import qiskit

def        a						(      _UpperCAmelCase							:					int ,   _UpperCAmelCase							:					int						):







		'''simple docstring'''





		__UpperCAmelCase    :     List[str]													=	qiskit.Aer.get_backend('''aer_simulator'''						)

		__UpperCAmelCase    :     Optional[Any]													=	qiskit.QuantumCircuit(4 ,   2						)
		# encode inputs in qubits 0 and 1
		if bita == 1:
				qc_ha.x(0						)
		if bita == 1:
				qc_ha.x(1						)
		qc_ha.barrier()

		# use cnots to write XOR of the inputs on qubit2
		qc_ha.cx(0 ,   2						)
		qc_ha.cx(1 ,   2						)

		# use ccx / toffoli gate to write AND of the inputs on qubit3
		qc_ha.ccx(0 ,   1 ,   3						)
		qc_ha.barrier()

		# extract outputs
		qc_ha.measure(2 ,   0						)  # extract XOR value
		qc_ha.measure(3 ,   1						)  # extract AND value

		# Execute the circuit on the qasm simulator
		__UpperCAmelCase    :     str													=	qiskit.execute(_UpperCAmelCase ,   _UpperCAmelCase ,   shots=10_00						)

		# Return the histogram data of the results of the experiment
		return job.result().get_counts(_UpperCAmelCase						)


if __name__ == "__main__":
				__A   			=half_adder(1, 1)
				print(f'''Half Adder Output Qubit Counts: {counts}''')





