


"""simple docstring"""



import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
		import bsa
		from bsa import BeautifulSoup


lowercase_							=							logging.get_logger(__name__)







class    __a						( __snake_case							):







				def __init__( self      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					requires_backends(self      ,	['''bs4''']   )
					super().__init__(**UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[]
					lowerCAmelCase_      							=			[]
					lowerCAmelCase_      							=			element if element.name else element.parent
					for parent in child.parents:  # type: bs4.element.Tag
						lowerCAmelCase_      							=			parent.find_all(child.name      ,	recursive=UpperCAmelCase   )
						xpath_tags.append(child.name   )
						xpath_subscripts.append(
						    0 if 1 == len(UpperCAmelCase   ) else next(i for i, s in enumerate(UpperCAmelCase      ,	1   ) if s is child   )   )
						lowerCAmelCase_      							=			parent
					xpath_tags.reverse()
					xpath_subscripts.reverse()
					return xpath_tags, xpath_subscripts







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			BeautifulSoup(UpperCAmelCase      ,	'''html.parser'''   )

					lowerCAmelCase_      							=			[]
					lowerCAmelCase_      							=			[]
					lowerCAmelCase_      							=			[]

					for element in html_code.descendants:
						if type(UpperCAmelCase   ) == bsa.element.NavigableString:
							if type(element.parent   ) != bsa.element.Tag:
								continue

							lowerCAmelCase_      							=			html.unescape(UpperCAmelCase   ).strip()
							if not text_in_this_tag:
								continue

							all_doc_strings.append(UpperCAmelCase   )

							lowerCAmelCase_							,	lowerCAmelCase_      							=			self.xpath_soup(UpperCAmelCase   )
							stringaxtag_seq.append(UpperCAmelCase   )
							stringaxsubs_seq.append(UpperCAmelCase   )

					if len(UpperCAmelCase   ) != len(UpperCAmelCase   ):
						raise ValueError('''Number of doc strings and xtags does not correspond'''   )
					if len(UpperCAmelCase   ) != len(UpperCAmelCase   ):
						raise ValueError('''Number of doc strings and xsubs does not correspond'''   )

					return all_doc_strings, stringaxtag_seq, stringaxsubs_seq







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			''''''
					for tagname, subs in zip(UpperCAmelCase      ,	UpperCAmelCase   ):
						xpath += F"""/{tagname}"""
						if subs != 0:
							xpath += F"""[{subs}]"""
					return xpath







				def __call__( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			False

					# Check that strings has a valid type
					if isinstance(UpperCAmelCase      ,	UpperCAmelCase   ):
						lowerCAmelCase_      							=			True
					elif isinstance(UpperCAmelCase      ,	(list, tuple)   ):
						if len(UpperCAmelCase   ) == 0 or isinstance(html_strings[0]      ,	UpperCAmelCase   ):
							lowerCAmelCase_      							=			True

					if not valid_strings:
						raise ValueError(
						    '''HTML strings must of type `str`, `List[str]` (batch of examples), '''
						    F"""but is of type {type(UpperCAmelCase   )}."""   )

					lowerCAmelCase_      							=			bool(isinstance(UpperCAmelCase      ,	(list, tuple)   ) and (isinstance(html_strings[0]      ,	UpperCAmelCase   ))   )

					if not is_batched:
						lowerCAmelCase_      							=			[html_strings]

					# Get nodes + xpaths
					lowerCAmelCase_      							=			[]
					lowerCAmelCase_      							=			[]
					for html_string in html_strings:
						lowerCAmelCase_							,	lowerCAmelCase_							,	lowerCAmelCase_      							=			self.get_three_from_single(UpperCAmelCase   )
						nodes.append(UpperCAmelCase   )
						lowerCAmelCase_      							=			[]
						for node, tag_list, sub_list in zip(UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):
							lowerCAmelCase_      							=			self.construct_xpath(UpperCAmelCase      ,	UpperCAmelCase   )
							xpath_strings.append(UpperCAmelCase   )
						xpaths.append(UpperCAmelCase   )

					# return as Dict
					lowerCAmelCase_      							=			{'''nodes''': nodes, '''xpaths''': xpaths}
					lowerCAmelCase_      							=			BatchFeature(data=UpperCAmelCase      ,	tensor_type=UpperCAmelCase   )

					return encoded_inputs



"""simple docstring"""



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{'vocab_file': 'vocab.txt'}

lowercase_							=							{
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

lowercase_							=							{
    'YituTech/conv-bert-base': 5_12,
    'YituTech/conv-bert-medium-small': 5_12,
    'YituTech/conv-bert-small': 5_12,
}


lowercase_							=							{
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Optional[int]			       =VOCAB_FILES_NAMES
				lowerCamelCase     :       List[str]			       =PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase     :       str			       =PRETRAINED_INIT_CONFIGURATION
				lowerCamelCase     :       Any			       =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase     :       List[str]			       =ConvBertTokenizer







				def __init__( self      ,	UpperCAmelCase=None      ,	UpperCAmelCase=None      ,	UpperCAmelCase=True      ,	UpperCAmelCase="[UNK]"      ,	UpperCAmelCase="[SEP]"      ,	UpperCAmelCase="[PAD]"      ,	UpperCAmelCase="[CLS]"      ,	UpperCAmelCase="[MASK]"      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					super().__init__(
					    UpperCAmelCase      ,	tokenizer_file=UpperCAmelCase      ,	do_lower_case=UpperCAmelCase      ,	unk_token=UpperCAmelCase      ,	sep_token=UpperCAmelCase      ,	pad_token=UpperCAmelCase      ,	cls_token=UpperCAmelCase      ,	mask_token=UpperCAmelCase      ,	tokenize_chinese_chars=UpperCAmelCase      ,	strip_accents=UpperCAmelCase      ,	**UpperCAmelCase      ,	)

					lowerCAmelCase_      							=			json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
					if (
					    normalizer_state.get('''lowercase'''      ,	UpperCAmelCase   ) != do_lower_case
					    or normalizer_state.get('''strip_accents'''      ,	UpperCAmelCase   ) != strip_accents
					    or normalizer_state.get('''handle_chinese_chars'''      ,	UpperCAmelCase   ) != tokenize_chinese_chars
					):
						lowerCAmelCase_      							=			getattr(UpperCAmelCase      ,	normalizer_state.pop('''type'''   )   )
						lowerCAmelCase_      							=			do_lower_case
						lowerCAmelCase_      							=			strip_accents
						lowerCAmelCase_      							=			tokenize_chinese_chars
						lowerCAmelCase_      							=			normalizer_class(**UpperCAmelCase   )

					lowerCAmelCase_      							=			do_lower_case







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase=None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[self.cls_token_id] + token_ids_a + [self.sep_token_id]

					if token_ids_a:
						output += token_ids_a + [self.sep_token_id]

					return output







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[self.sep_token_id]
					lowerCAmelCase_      							=			[self.cls_token_id]
					if token_ids_a is None:
						return len(cls + token_ids_a + sep   ) * [0]
					return len(cls + token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self._tokenizer.model.save(UpperCAmelCase      ,	name=UpperCAmelCase   )
					return tuple(UpperCAmelCase   )