
'''simple docstring'''







import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata

def 				_snake_case (		lowercase						)       ->       str:
				__a       :     int								=	min(re.search("""^ +"""			,    lowercase						).end() if t.startswith(""" """						) else 0 for t in string.splitlines()						)
				return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(lowercase						)]						)


__SCREAMING_SNAKE_CASE		:  Optional[int]        =      '\\n---\nlanguage:\n- zh\n- en\ntask_ids:\n- sentiment-classification\n---\n# Begin of markdown\n\nSome cool dataset card\n'

__SCREAMING_SNAKE_CASE		:  Tuple        =      '\\n---\n---\n# Begin of markdown\n\nSome cool dataset card\n'


__SCREAMING_SNAKE_CASE		:  Union[str, Any]        =      '\\n# Begin of markdown\n\nSome cool dataset card\n'
class  SCREAMING_SNAKE_CASE__       (  unittest.TestCase   ):
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					with tempfile.TemporaryDirectory() as tmp_dir:
									__a       :     Tuple								=	Path(__UpperCamelCase			) / """README.md"""
									with open(__UpperCamelCase  ,    """w+"""			) as readme_file:
													readme_file.write(__UpperCamelCase			)
									__a       :     Any								=	DatasetMetadata.from_readme(__UpperCamelCase			)
									self.assertDictEqual(__UpperCamelCase  ,    {"""language""": ["""zh""", """en"""], """task_ids""": ["""sentiment-classification"""]}			)

									with open(__UpperCamelCase  ,    """w+"""			) as readme_file:
													readme_file.write(__UpperCamelCase			)
									__a       :     List[str]								=	DatasetMetadata.from_readme(__UpperCamelCase			)
									self.assertDictEqual(__UpperCamelCase  ,    {}			)

									with open(__UpperCamelCase  ,    """w+"""			) as readme_file:
													readme_file.write(__UpperCamelCase			)
									__a       :     Optional[int]								=	DatasetMetadata.from_readme(__UpperCamelCase			)
									self.assertEqual(__UpperCamelCase  ,    {}			)

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	_dedent(
					    """\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            """			)
					assert DatasetMetadata.from_yaml_string(__UpperCamelCase			)

					__a       :     Dict								=	_dedent(
					    """\
            annotations_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            task_ids:
            - open-domain-qa
            """			)
					with self.assertRaises(__UpperCamelCase			):
									DatasetMetadata.from_yaml_string(__UpperCamelCase			)

					__a       :     Tuple								=	_dedent(
					    """\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - text-classification
            task_ids:
            - multi-class-classification
            paperswithcode_id:
            - squad
            configs:
            - en
            train-eval-index:
            - config: en
              task: text-classification
              task_id: multi_class_classification
              splits:
                train_split: train
                eval_split: test
              col_mapping:
                text: text
                label: target
              metrics:
                - type: accuracy
                  name: Accuracy
            extra_gated_prompt: |
              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:
              [RESEARCHER_FULLNAME] (the \"Researcher\") has requested permission to use the ImageNet database (the \"Database\") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:
              1. Researcher shall use the Database only for non-commercial research and educational purposes.
            extra_gated_fields:
              Company: text
              Country: text
              I agree to use this model for non-commerical use ONLY: checkbox
            """			)
					assert DatasetMetadata.from_yaml_string(__UpperCamelCase			)

'''simple docstring'''







from typing import List

from tokenizers import NormalizedString, PreTokenizedString, normalizers
class  SCREAMING_SNAKE_CASE__       :
	def __init__(				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	vocab
					__a       :     int								=	normalizers.BertNormalizer(
					    clean_text=__UpperCamelCase  ,    handle_chinese_chars=__UpperCamelCase  ,    strip_accents=__UpperCamelCase  ,    lowercase=__UpperCamelCase  ,    )
					try:
									import rjieba
					except ImportError:
									raise ImportError(
									    """You need to install rjieba to use RoFormerTokenizer. """
									    """See https://pypi.org/project/rjieba/ for installation."""			)
					__a       :     Optional[Any]								=	rjieba
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	[]

					# this code slice normalized_string is too slow (6s) but test_alignement_methods can pass
					for token, start, end in self.jieba.tokenize(str(__UpperCamelCase			)  ,    hmm=__UpperCamelCase			):
									if token in self.vocab:
													splits.append(normalized_string[start:end]			)
									else:
													__a       :     str								=	self.normalizers.normalize_str(__UpperCamelCase			).split()
													for token in token_list:
																	if token:
																					__a       :     str								=	start + len(__UpperCamelCase			)
																					splits.append(normalized_string[start:end]			)
																					__a       :     Union[str, Any]								=	end

        # this code test_alignement_methods can't pass but fast (300ms)
        # for token in self.jieba.cut(str(normalized_string), False):
        #     if token in self.vocab:
        #         splits.append(NormalizedString(token))
        #     else:
        #         token_list = self.normalizers.normalize_str(token).split()
        #         for token in token_list:
        #             if token:
        #                 splits.append(NormalizedString(token))

					return splits

	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					pretok.split(self.jieba_split			)