






import csv
import json
import os

import datasets


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
A__     :      List[Any]             =			'\\n@InProceedings{huggingface:dataset,\ntitle = {A great new dataset},\nauthor={huggingface, Inc.\n},\nyear={2020}\n}\n'

# TODO: Add description of the dataset here
# You can copy an official description
A__     :      int             =			'\\nThis new dataset is designed to solve this great NLP task and is crafted with a lot of care.\n'

# TODO: Add a link to an official homepage for the dataset here
A__     :      Any             =			''

# TODO: Add the licence for the dataset here if you can find it
A__     :      Union[str, Any]             =			''

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
A__     :      str             =			{
    'first_domain': 'https://huggingface.co/great-new-dataset-first_domain.zip',
    'second_domain': 'https://huggingface.co/great-new-dataset-second_domain.zip',
}
class 				_UpperCAmelCase (	datasets.GeneratorBasedBuilder     ):

				"""simple docstring"""




				lowercase__    							=	datasets.Version("""1.1.0"""     )

				# This is an example of a dataset with multiple configurations.
				# If you don't want/need to define several sub-sets in your dataset,
				# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

				# If you need to make complex sub-parts in the datasets with configurable options
				# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
				# BUILDER_CONFIG_CLASS = MyBuilderConfig

				# You will be able to load one or the other configurations in the following list with
				# data = datasets.load_dataset('my_dataset', 'first_domain')
				# data = datasets.load_dataset('my_dataset', 'second_domain')
				lowercase__    							=	[
				    datasets.BuilderConfig(name="""first_domain"""		,version=A__		,description="""This part of my dataset covers a first domain"""     ),
				    datasets.BuilderConfig(name="""second_domain"""		,version=A__		,description="""This part of my dataset covers a second domain"""     ),
				]

				lowercase__    							=	"""first_domain"""  # It's not mandatory to have a default configuration. Just use one if it make sense.




				def     lowercase__       (					self						:   List[Any]  ):

								'''simple docstring'''
								# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
								if self.config.name == "first_domain":  # This is the name of the configuration selected in BUILDER_CONFIGS above
												lowercase__       			=      datasets.Features(
												    {
												        '''sentence''': datasets.Value('''string'''  ),
												        '''option1''': datasets.Value('''string'''  ),
												        '''answer''': datasets.Value('''string'''  )
												        # These are the features of your dataset like images, labels ...
												    }  )
								else:  # This is an example to show how to have different features for "first_domain" and "second_domain"
												lowercase__       			=      datasets.Features(
												    {
												        '''sentence''': datasets.Value('''string'''  ),
												        '''option2''': datasets.Value('''string'''  ),
												        '''second_domain_answer''': datasets.Value('''string'''  )
												        # These are the features of your dataset like images, labels ...
												    }  )
								return datasets.DatasetInfo(
								    # This is the description that will appear on the datasets page.
								    description=_DESCRIPTION,  features=lowerCamelCase,  homepage=_HOMEPAGE,  license=_LICENSE,  citation=_CITATION,  )




				def     lowercase__       (					self						:   Dict,  lowerCamelCase						:   Optional[Any]  ):

								'''simple docstring'''
								# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
								# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name

								# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
								# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
								# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
								lowercase__       			=      _URLS[self.config.name]
								lowercase__       			=      dl_manager.download_and_extract(lowerCamelCase  )
								return [
								    datasets.SplitGenerator(
								        name=datasets.Split.TRAIN,  gen_kwargs={
								            '''filepath''': os.path.join(lowerCamelCase,  '''train.jsonl'''  ),
								            '''split''': '''train''',
								        },  ),
								    datasets.SplitGenerator(
								        name=datasets.Split.VALIDATION,  gen_kwargs={
								            '''filepath''': os.path.join(lowerCamelCase,  '''dev.jsonl'''  ),
								            '''split''': '''dev''',
								        },  ),
								    datasets.SplitGenerator(
								        name=datasets.Split.TEST,  gen_kwargs={
								            '''filepath''': os.path.join(lowerCamelCase,  '''test.jsonl'''  ),
								            '''split''': '''test'''
								        },  ),
								]




				def     lowercase__       (					self						:   Dict,  lowerCamelCase						:   Optional[Any],  lowerCamelCase						:   int  ):

								'''simple docstring'''
								# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
								# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
								with open(lowerCamelCase,  encoding='''utf-8'''  ) as f:
												for key, row in enumerate(lowerCamelCase  ):
																lowercase__       			=      json.loads(lowerCamelCase  )
																if self.config.name == "first_domain":
																				# Yields examples as (key, example) tuples
																				yield key, {
																				    "sentence": data["sentence"],
																				    "option1": data["option1"],
																				    "answer": "" if split == "test" else data["answer"],
																				}
																else:
																				yield key, {
																				    "sentence": data["sentence"],
																				    "option2": data["option2"],
																				    "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
																				}












import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


A__     :      Dict             =			'none'
A__     :      Optional[Any]             =			'none'






def   a      (						lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				lowercase__       			=      value.split(lowerCamelCase_    )
				return len(lowerCamelCase_    ) > 1 and any((len(lowerCamelCase_    ) == 3 for x in split)    )






def   a      (						lowerCamelCase_    ):






				'''simple docstring'''
				if isinstance(lowerCamelCase_		,       lowerCamelCase_    ):
								return value
				if isinstance(lowerCamelCase_		,       lowerCamelCase_    ):
								return float(lowerCamelCase_    )
				if not isinstance(lowerCamelCase_		,       lowerCamelCase_    ):
								raise ValueError('''Argument value is not a string. Can\'t parse it as float'''    )
				lowercase__       			=      value

				try:
								# Example: 1,000.7
								if "." in sanitized and "," in sanitized:
												return float(sanitized.replace(''','''		,       ''''''    )    )
								# 1,000
								if "," in sanitized and _split_thousands(''','''		,       lowerCamelCase_    ):
												return float(sanitized.replace(''','''		,       ''''''    )    )
								# 5,5556
								if "," in sanitized and sanitized.count(''','''    ) == 1 and not _split_thousands(''','''		,       lowerCamelCase_    ):
												return float(sanitized.replace(''','''		,       '''.'''    )    )
								# 0.0.0.1
								if sanitized.count('''.'''    ) > 1:
												return float(sanitized.replace('''.'''		,       ''''''    )    )
								# 0,0,0,1
								if sanitized.count(''','''    ) > 1:
												return float(sanitized.replace(''','''		,       ''''''    )    )
								return float(lowerCamelCase_    )
				except ValueError:
								# Avoid adding the sanitized value in the error message.
								raise ValueError('''Unable to convert value to float'''    )






def   a      (						lowerCamelCase_    ):






				'''simple docstring'''
				if answer is None:
								return None
				try:
								lowercase__       			=      convert_to_float(lowerCamelCase_    )
								if isinstance(lowerCamelCase_		,       lowerCamelCase_    ) and math.isnan(lowerCamelCase_    ):
												return None
								return value
				except ValueError:
								return answer.lower()


A__     :      Tuple             =			{
    'text': lambda x: x,
    'real': convert_to_float,
}
class 				_UpperCAmelCase (	enum.Enum     ):

				"""simple docstring"""




				lowercase__    							=	0
				lowercase__    							=	1
				lowercase__    							=	2
				lowercase__    							=	3
				lowercase__    							=	4
				lowercase__    							=	5



class 				_UpperCAmelCase (	enum.Enum     ):

				"""simple docstring"""




				lowercase__    							=	0
				lowercase__    							=	1
				lowercase__    							=	2



@dataclasses.dataclass
class 				_UpperCAmelCase :

				"""simple docstring"""




				lowercase__    							=	42
				lowercase__    							=	42
				lowercase__    							=	42



A__     :      str             =			re.compile(r'\w+|[^\w\s]+', re.UNICODE | re.MULTILINE | re.DOTALL)






def   a      (						lowerCamelCase_    ):






				'''simple docstring'''
				return list(_TOKENIZER.findall(x.lower()    )    )






def   a      (						lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				if operator == _Operator.EQUALS:
								return src == tgt
				elif operator == _Operator.GREATER:
								return src > tgt
				elif operator == _Operator.LESSER:
								return src < tgt
				raise ValueError(F"""Unknown operator: {operator}"""    )






def   a      (						lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				lowercase__       			=      table['''types''']
				return _TYPE_CONVERTER[types[column]](lowerCamelCase_    )






def   a      (						lowerCamelCase_    ):






				'''simple docstring'''
				return isinstance(lowerCamelCase_		,       lowerCamelCase_    )






def   a      (						lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				for cond in conditions:
								lowercase__       			=      row[cond.column]

								lowercase__       			=      _parse_value(lowerCamelCase_		,       cond.column		,       cond.cmp_value    )

								if _is_string(lowerCamelCase_    ) and _is_string(lowerCamelCase_    ):
												lowercase__       			=      _normalize_for_match(lowerCamelCase_    )
												lowercase__       			=      _normalize_for_match(lowerCamelCase_    )

								if not isinstance(lowerCamelCase_		,       type(lowerCamelCase_    )    ):
												raise ValueError('''Type difference {} != {}'''.format(type(lowerCamelCase_    )		,       type(lowerCamelCase_    )    )    )

								if not _compare(cond.operator		,       lowerCamelCase_		,       lowerCamelCase_    ):
												return False
				return True






def   a      (						lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				if not answer_coordinates:
								if aggregation_op == _Aggregation.COUNT:
												return 0.0
								else:
												return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
				if aggregation_op == _Aggregation.COUNT:
								return float(len(lowerCamelCase_    )    )

				# If we have just one answer, if float returns it or try a conversion.
				lowercase__       			=      [table['''rows'''][i][j] for (i, j) in answer_coordinates]
				if len(lowerCamelCase_    ) == 1:
								try:
												return convert_to_float(values[0]    )
								except ValueError as e:
												if aggregation_op != _Aggregation.NONE:
																raise e

				if aggregation_op == _Aggregation.NONE:
								return None

				# Other aggregation only support numeric values. Bail out if we have strings.
				if not all((isinstance(lowerCamelCase_		,       (int, float)    ) for v in values)    ):
								return None

				if aggregation_op == _Aggregation.SUM:
								return float(sum(lowerCamelCase_    )    )
				elif aggregation_op == _Aggregation.AVERAGE:
								return sum(lowerCamelCase_    ) / len(lowerCamelCase_    )
				else:
								raise ValueError(F"""Unknown aggregation: {aggregation_op}"""    )






def   a      (						lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				lowercase__       			=      sql_query['''agg''']
				if aggregation_op_index >= 3:
								lowercase__       			=      _Aggregation(lowerCamelCase_    )
				else:
								lowercase__       			=      _Aggregation.NONE

				lowercase__       			=      sql_query['''sel''']
				lowercase__       			=      [
				    _Condition(lowerCamelCase_		,       _Operator(lowerCamelCase_    )		,       lowerCamelCase_    )
				    for column, operator, cmp_value in zip(
				        sql_query['''conds''']['''column_index''']		,       sql_query['''conds''']['''operator_index''']		,       sql_query['''conds''']['''condition''']    )
				]

				lowercase__       			=      []
				for row in range(len(table['''rows''']    )    ):
								if _respect_conditions(lowerCamelCase_		,       table['''rows'''][row]		,       lowerCamelCase_    ):
												indices.append((row, target_column)    )

				if not indices:
								return [], aggregation_op

				if len(lowerCamelCase_    ) == 1:
								return indices, aggregation_op

				# Parsing of MIN/MAX.
				if aggregation_op_index in (1, 2):
								lowercase__       			=      {2: min, 1: max}
								lowercase__       			=      [(table['''rows'''][i][j], index) for index, (i, j) in enumerate(lowerCamelCase_    )]
								lowercase__       			=      functools.reduce(operators[sql_query['''agg''']]		,       lowerCamelCase_    )

								lowercase__       			=      [indices[reduced[1]]]
								return ret, _Aggregation.NONE

				return indices, aggregation_op






def   a      (						lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				if float_answer is not None:
								return [str(lowerCamelCase_    )]
				return [str(table['''real_rows'''][r][c]    ) for r, c in answer_coordinates]






def   a      (						lowerCamelCase_		,       lowerCamelCase_    ):






				'''simple docstring'''
				lowercase__			,						lowercase__       			=      _get_answer_coordinates(lowerCamelCase_		,       lowerCamelCase_    )
				lowercase__       			=      _get_float_answer(lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    )
				lowercase__       			=      _get_answer_text(lowerCamelCase_		,       lowerCamelCase_		,       lowerCamelCase_    )
				# keep the original data the same with TaPas
				if len(lowerCamelCase_    ) == 0:
								lowercase__       			=      [EMPTY_ANSWER]
				return answer_text




