





"""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


a		:				Union[str, Any]  			=    logging.get_logger(__name__)


class  __UpperCamelCase       (		a__		):






							def __init__(     self   ,      **lowerCAmelCase__   )			->				int:
								requires_backends(self   ,      ["bs4"]   )
								super().__init__(**lowerCAmelCase__   )






							def 					__a     (     self   ,      lowerCAmelCase__   )			->				Union[str, Any]:
								a   :	Optional[int]			=       []
								a   :	Optional[Any]			=       []
								a   :	Dict			=       element if element.name else element.parent
								for parent in child.parents:  # type: bs4.element.Tag
									a   :	List[str]			=       parent.find_all(child.name   ,      recursive=lowerCAmelCase__   )
									xpath_tags.append(child.name   )
									xpath_subscripts.append(
									    0 if 1 == len(lowerCAmelCase__   ) else next(i for i, s in enumerate(lowerCAmelCase__   ,      1   ) if s is child   )   )
									a   :	Optional[int]			=       parent
								xpath_tags.reverse()
								xpath_subscripts.reverse()
								return xpath_tags, xpath_subscripts






							def 					__a     (     self   ,      lowerCAmelCase__   )			->				int:
								a   :	str			=       BeautifulSoup(lowerCAmelCase__   ,      "html.parser"   )

								a   :	Optional[int]			=       []
								a   :	List[Any]			=       []
								a   :	List[str]			=       []

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

										a   :	List[Any]			=       html.unescape(lowerCAmelCase__   ).strip()
										if not text_in_this_tag:
											continue

										all_doc_strings.append(lowerCAmelCase__   )

										a, a   :	List[Any]			=       self.xpath_soup(lowerCAmelCase__   )
										stringaxtag_seq.append(lowerCAmelCase__   )
										stringaxsubs_seq.append(lowerCAmelCase__   )

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

								return all_doc_strings, stringaxtag_seq, stringaxsubs_seq






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )			->				Union[str, Any]:
								a   :	int			=       ""
								for tagname, subs in zip(lowerCAmelCase__   ,      lowerCAmelCase__   ):
									xpath += f"""/{tagname}"""
									if subs != 0:
										xpath += f"""[{subs}]"""
								return xpath






							def __call__(     self   ,      lowerCAmelCase__   )			->				BatchFeature:
								a   :	List[Any]			=       False

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

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

								a   :	Optional[Any]			=       bool(isinstance(lowerCAmelCase__   ,      (list, tuple)   ) and (isinstance(html_strings[0]   ,      lowerCAmelCase__   ))   )

								if not is_batched:
									a   :	Dict			=       [html_strings]

								# Get nodes + xpaths
								a   :	Optional[Any]			=       []
								a   :	Dict			=       []
								for html_string in html_strings:
									a, a, a   :	str			=       self.get_three_from_single(lowerCAmelCase__   )
									nodes.append(lowerCAmelCase__   )
									a   :	Dict			=       []
									for node, tag_list, sub_list in zip(lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ):
										a   :	Union[str, Any]			=       self.construct_xpath(lowerCAmelCase__   ,      lowerCAmelCase__   )
										xpath_strings.append(lowerCAmelCase__   )
									xpaths.append(lowerCAmelCase__   )

								# return as Dict
								a   :	Optional[Any]			=       {"nodes": nodes, "xpaths": xpaths}
								a   :	List[Any]			=       BatchFeature(data=lowerCAmelCase__   ,      tensor_type=lowerCAmelCase__   )

								return encoded_inputs









"""simple docstring"""




import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
		from .tokenization_albert import AlbertTokenizer
else:
		a		:				Tuple  			=    None

a		:				Any  			=    logging.get_logger(__name__)
a		:				List[Any]  			=    {'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

a		:				str  			=    {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    },
    '''tokenizer_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/tokenizer.json''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/tokenizer.json''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/tokenizer.json''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/tokenizer.json''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/tokenizer.json''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/tokenizer.json''',
    },
}

a		:				str  			=    {
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

a		:				Union[str, Any]  			=    '''▁'''


class  __UpperCamelCase       (		a__		):
							lowerCamelCase     :      Union[str, Any]         =VOCAB_FILES_NAMES
							lowerCamelCase     :      Dict         =PRETRAINED_VOCAB_FILES_MAP
							lowerCamelCase     :      List[Any]         =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowerCamelCase     :      List[Any]         =AlbertTokenizer






							def __init__(     self   ,      lowerCAmelCase__=None   ,      lowerCAmelCase__=None   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=False   ,      lowerCAmelCase__="[CLS]"   ,      lowerCAmelCase__="[SEP]"   ,      lowerCAmelCase__="<unk>"   ,      lowerCAmelCase__="[SEP]"   ,      lowerCAmelCase__="<pad>"   ,      lowerCAmelCase__="[CLS]"   ,      lowerCAmelCase__="[MASK]"   ,      **lowerCAmelCase__   ,      )			->				Union[str, Any]:
								# Mask token behave like a normal word, i.e. include the space before it and
								# is included in the raw text, there should be a match in a non-normalized sentence.
								a   :	Optional[int]			=       (
								    AddedToken(lowerCAmelCase__   ,      lstrip=lowerCAmelCase__   ,      rstrip=lowerCAmelCase__   ,      normalized=lowerCAmelCase__   )
								    if isinstance(lowerCAmelCase__   ,      lowerCAmelCase__   )
								    else mask_token
								)

								super().__init__(
								    lowerCAmelCase__   ,      tokenizer_file=lowerCAmelCase__   ,      do_lower_case=lowerCAmelCase__   ,      remove_space=lowerCAmelCase__   ,      keep_accents=lowerCAmelCase__   ,      bos_token=lowerCAmelCase__   ,      eos_token=lowerCAmelCase__   ,      unk_token=lowerCAmelCase__   ,      sep_token=lowerCAmelCase__   ,      pad_token=lowerCAmelCase__   ,      cls_token=lowerCAmelCase__   ,      mask_token=lowerCAmelCase__   ,      **lowerCAmelCase__   ,      )

								a   :	Dict			=       do_lower_case
								a   :	Any			=       remove_space
								a   :	Optional[Any]			=       keep_accents
								a   :	List[str]			=       vocab_file
								a   :	Optional[Any]			=       False if not self.vocab_file else True






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				List[int]:
								a   :	Optional[Any]			=       [self.sep_token_id]
								a   :	int			=       [self.cls_token_id]
								if token_ids_a is None:
									return cls + token_ids_a + sep
								return cls + token_ids_a + sep + token_ids_a + sep






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				List[int]:
								a   :	Optional[Any]			=       [self.sep_token_id]
								a   :	int			=       [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 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				Tuple[str]:
								if not self.can_save_slow_tokenizer:
									raise ValueError(
									    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
									    "tokenizer."   )

								if not os.path.isdir(lowerCAmelCase__   ):
									logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""   )
									return
								a   :	Dict			=       os.path.join(
								    lowerCAmelCase__   ,      (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )

								if os.path.abspath(self.vocab_file   ) != os.path.abspath(lowerCAmelCase__   ):
									copyfile(self.vocab_file   ,      lowerCAmelCase__   )

								return (out_vocab_file,)


