


"""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_			=      logging.get_logger(__name__)






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 def __init__(   self ,						**__lowerCamelCase  ):



     '''simple docstring'''




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

 def  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						int									=					[]
     __A   :						str									=					[]
     __A   :						Any									=					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  UpperCamelCase__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					BeautifulSoup(__lowerCamelCase ,						'''html.parser'''  )

     __A   :						int									=					[]
     __A   :						List[Any]									=					[]
     __A   :						int									=					[]

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

             __A   :						Optional[int]									=					html.unescape(__lowerCamelCase  ).strip()
             if not text_in_this_tag:
                 continue

             all_doc_strings.append(__lowerCamelCase  )

             __A   :						str									=					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  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase  ):



     '''simple docstring'''




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







 def __call__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     __A   :						List[Any]									=					False

     # Check that strings has a valid type
     if isinstance(__lowerCamelCase ,						__lowerCamelCase  ):
         __A   :						List[Any]									=					True
     elif isinstance(__lowerCamelCase ,						(list, tuple)  ):
         if len(__lowerCamelCase  ) == 0 or isinstance(html_strings[0] ,						__lowerCamelCase  ):
             __A   :						Tuple									=					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[int]									=					bool(isinstance(__lowerCamelCase ,						(list, tuple)  ) and (isinstance(html_strings[0] ,						__lowerCamelCase  ))  )

     if not is_batched:
         __A   :						Any									=					[html_strings]

     # Get nodes + xpaths
     __A   :						Tuple									=					[]
     __A   :						Tuple									=					[]
     for html_string in html_strings:
         __A   :						Optional[int]									=					self.get_three_from_single(__lowerCamelCase  )
         nodes.append(__lowerCamelCase  )
         __A   :						Optional[int]									=					[]
         for node, tag_list, sub_list in zip(__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase  ):
             __A   :						Optional[Any]									=					self.construct_xpath(__lowerCamelCase ,						__lowerCamelCase  )
             xpath_strings.append(__lowerCamelCase  )
         xpaths.append(__lowerCamelCase  )

     # return as Dict
     __A   :						Tuple									=					{'''nodes''': nodes, '''xpaths''': xpaths}
     __A   :						List[Any]									=					BatchFeature(data=__lowerCamelCase ,						tensor_type=__lowerCamelCase  )

     return encoded_inputs











"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


a_			=      {
    """configuration_tapas""": ["""TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TapasConfig"""],
    """tokenization_tapas""": ["""TapasTokenizer"""],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      [
           """TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TapasForMaskedLM""",
           """TapasForQuestionAnswering""",
           """TapasForSequenceClassification""",
           """TapasModel""",
           """TapasPreTrainedModel""",
           """load_tf_weights_in_tapas""",
       ]
try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      [
           """TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFTapasForMaskedLM""",
           """TFTapasForQuestionAnswering""",
           """TFTapasForSequenceClassification""",
           """TFTapasModel""",
           """TFTapasPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_tapas import TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP, TapasConfig
       from .tokenization_tapas import TapasTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tapas import (
                  TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TapasForMaskedLM,
                  TapasForQuestionAnswering,
                  TapasForSequenceClassification,
                  TapasModel,
                  TapasPreTrainedModel,
                  load_tf_weights_in_tapas,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_tapas import (
                  TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFTapasForMaskedLM,
                  TFTapasForQuestionAnswering,
                  TFTapasForSequenceClassification,
                  TFTapasModel,
                  TFTapasPreTrainedModel,
              )


else:
       import sys

       a_			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




