





"""simple docstring"""





import datasets

from .evaluate import evaluate


_UpperCamelCase							=      '\\n@article{hendrycks2021cuad,\n      title={CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review},\n      author={Dan Hendrycks and Collin Burns and Anya Chen and Spencer Ball},\n      journal={arXiv preprint arXiv:2103.06268},\n      year={2021}\n}\n'

_UpperCamelCase							=      '\nThis metric wrap the official scoring script for version 1 of the Contract\nUnderstanding Atticus Dataset (CUAD).\nContract Understanding Atticus Dataset (CUAD) v1 is a corpus of more than 13,000 labels in 510\ncommercial legal contracts that have been manually labeled to identify 41 categories of important\nclauses that lawyers look for when reviewing contracts in connection with corporate transactions.\n'

_UpperCamelCase							=      '\nComputes CUAD scores (EM, F1, AUPR, Precision@80%Recall, and Precision@90%Recall).\nArgs:\n    predictions: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair as given in the references (see below)\n        - \'prediction_text\': list of possible texts for the answer, as a list of strings\n        depending on a threshold on the confidence probability of each prediction.\n    references: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair (see above),\n        - \'answers\': a Dict in the CUAD dataset format\n            {\n                \'text\': list of possible texts for the answer, as a list of strings\n                \'answer_start\': list of start positions for the answer, as a list of ints\n            }\n            Note that answer_start values are not taken into account to compute the metric.\nReturns:\n    \'exact_match\': Exact match (the normalized answer exactly match the gold answer)\n    \'f1\': The F-score of predicted tokens versus the gold answer\n    \'aupr\': Area Under the Precision-Recall curve\n    \'prec_at_80_recall\': Precision at 80% recall\n    \'prec_at_90_recall\': Precision at 90% recall\nExamples:\n    >>> predictions = [{\'prediction_text\': [\'The seller:\', \'The buyer/End-User: Shenzhen LOHAS Supply Chain Management Co., Ltd.\'], \'id\': \'LohaCompanyltd_20191209_F-1_EX-10.16_11917878_EX-10.16_Supply Agreement__Parties\'}]\n    >>> references = [{\'answers\': {\'answer_start\': [143, 49], \'text\': [\'The seller:\', \'The buyer/End-User: Shenzhen LOHAS Supply Chain Management Co., Ltd.\']}, \'id\': \'LohaCompanyltd_20191209_F-1_EX-10.16_11917878_EX-10.16_Supply Agreement__Parties\'}]\n    >>> cuad_metric = datasets.load_metric("cuad")\n    >>> results = cuad_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'exact_match\': 100.0, \'f1\': 100.0, \'aupr\': 0.0, \'prec_at_80_recall\': 1.0, \'prec_at_90_recall\': 1.0}\n'
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,  _KWARGS_DESCRIPTION   )
class 		SCREAMING_SNAKE_CASE_							(    datasets.Metric   ):




				def 					__lowercase  (     self  :Union[str, Any]			):
											return datasets.MetricInfo(
											    description=_DESCRIPTION						,    citation=_CITATION						,    inputs_description=_KWARGS_DESCRIPTION						,    features=datasets.Features(
											        {
											            '''predictions''': {
											                '''id''': datasets.Value('''string'''			),
											                '''prediction_text''': datasets.features.Sequence(datasets.Value('''string'''			)			),
											            },
											            '''references''': {
											                '''id''': datasets.Value('''string'''			),
											                '''answers''': datasets.features.Sequence(
											                    {
											                        '''text''': datasets.Value('''string'''			),
											                        '''answer_start''': datasets.Value('''int32'''			),
											                    }			),
											            },
											        }			)						,    codebase_urls=['''https://www.atticusprojectai.org/cuad''']						,    reference_urls=['''https://www.atticusprojectai.org/cuad''']						,    )




				def 					__lowercase  (     self  :List[Any]						,    __lowercase  :str						,    __lowercase  :Optional[int]			):
											__lowerCamelCase      :      Optional[int]         ={prediction['''id''']: prediction['''prediction_text'''] for prediction in predictions}
											__lowerCamelCase      :      Dict         =[
											    {
											        '''paragraphs''': [
											            {
											                '''qas''': [
											                    {
											                        '''answers''': [{'''text''': answer_text} for answer_text in ref['''answers''']['''text''']],
											                        '''id''': ref['''id'''],
											                    }
											                    for ref in references
											                ]
											            }
											        ]
											    }
											]
											__lowerCamelCase      :      List[str]         =evaluate(dataset=__lowercase						,    predictions=__lowercase			)
											return score











"""simple docstring"""





from typing import Any
class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __init__(     self  :Tuple						,    __lowercase  :Any			):
											__lowerCamelCase      :      str         =data
											__lowerCamelCase      :      Any         =None




				def __repr__(     self  :Optional[Any]			):
											return f'Node({self.data})'

class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __init__(     self  :Optional[int]			):
											__lowerCamelCase      :      Union[str, Any]         =None




				def __iter__(     self  :Optional[int]			):
											__lowerCamelCase      :      Optional[Any]         =self.head
											while node:
																		yield node.data
																		__lowerCamelCase      :      str         =node.next




				def __len__(     self  :Any			):
											return sum(1 for _ in self			)




				def __repr__(     self  :Any			):
											return "->".join([str(__lowercase			) for item in self]			)




				def __getitem__(     self  :Dict						,    __lowercase  :int			):
											if not 0 <= index < len(self			):
																		raise ValueError('''list index out of range.'''			)
											for i, node in enumerate(self			):
																		if i == index:
																									return node
											return None




				def __setitem__(     self  :Dict						,    __lowercase  :int						,    __lowercase  :Any			):
											if not 0 <= index < len(self			):
																		raise ValueError('''list index out of range.'''			)
											__lowerCamelCase      :      Optional[Any]         =self.head
											for _ in range(__lowercase			):
																		__lowerCamelCase      :      List[str]         =current.next
											__lowerCamelCase      :      Optional[int]         =data




				def 					__lowercase  (     self  :Tuple						,    __lowercase  :Any			):
											self.insert_nth(len(self			)						,    __lowercase			)




				def 					__lowercase  (     self  :int						,    __lowercase  :Any			):
											self.insert_nth(0						,    __lowercase			)




				def 					__lowercase  (     self  :Dict						,    __lowercase  :int						,    __lowercase  :Any			):
											if not 0 <= index <= len(self			):
																		raise IndexError('''list index out of range'''			)
											__lowerCamelCase      :      List[Any]         =Node(__lowercase			)
											if self.head is None:
																		__lowerCamelCase      :      List[Any]         =new_node
											elif index == 0:
																		__lowerCamelCase      :      Optional[Any]         =self.head  # link new_node to head
																		__lowerCamelCase      :      Optional[Any]         =new_node
											else:
																		__lowerCamelCase      :      str         =self.head
																		for _ in range(index - 1			):
																									__lowerCamelCase      :      Any         =temp.next
																		__lowerCamelCase      :      List[Any]         =temp.next
																		__lowerCamelCase      :      List[Any]         =new_node




				def 					__lowercase  (     self  :Tuple			):  # print every node data
											print(self			)




				def 					__lowercase  (     self  :List[str]			):
											return self.delete_nth(0			)




				def 					__lowercase  (     self  :Any			):  # delete from tail
											return self.delete_nth(len(self			) - 1			)




				def 					__lowercase  (     self  :Dict						,    __lowercase  :int = 0			):
											if not 0 <= index <= len(self			) - 1:  # test if index is valid
																		raise IndexError('''List index out of range.'''			)
											__lowerCamelCase      :      List[Any]         =self.head  # default first node
											if index == 0:
																		__lowerCamelCase      :      int         =self.head.next
											else:
																		__lowerCamelCase      :      int         =self.head
																		for _ in range(index - 1			):
																									__lowerCamelCase      :      str         =temp.next
																		__lowerCamelCase      :      int         =temp.next
																		__lowerCamelCase      :      Optional[Any]         =temp.next.next
											return delete_node.data




				def 					__lowercase  (     self  :Any			):
											return self.head is None




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Any         =None
											__lowerCamelCase      :      Optional[int]         =self.head

											while current:
																		# Store the current node's next node.
																		__lowerCamelCase      :      Any         =current.next
																		# Make the current node's next point backwards
																		__lowerCamelCase      :      Optional[Any]         =prev
																		# Make the previous node be the current node
																		__lowerCamelCase      :      List[str]         =current
																		# Make the current node the next node (to progress iteration)
																		__lowerCamelCase      :      Tuple         =next_node
											# Return prev in order to put the head at the end
											__lowerCamelCase      :      List[str]         =prev



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      Tuple         =LinkedList()
							assert linked_list.is_empty() is True
							assert str(SCREAMING_SNAKE_CASE   ) == ""

							try:
														linked_list.delete_head()
														raise AssertionError  # This should not happen.
							except IndexError:
														assert True  # This should happen.

							try:
														linked_list.delete_tail()
														raise AssertionError  # This should not happen.
							except IndexError:
														assert True  # This should happen.

							for i in range(10   ):
														assert len(SCREAMING_SNAKE_CASE   ) == i
														linked_list.insert_nth(SCREAMING_SNAKE_CASE    ,						i + 1   )
							assert str(SCREAMING_SNAKE_CASE   ) == "->".join(str(SCREAMING_SNAKE_CASE   ) for i in range(1    ,						11   )   )

							linked_list.insert_head(0   )
							linked_list.insert_tail(11   )
							assert str(SCREAMING_SNAKE_CASE   ) == "->".join(str(SCREAMING_SNAKE_CASE   ) for i in range(0    ,						12   )   )

							assert linked_list.delete_head() == 0
							assert linked_list.delete_nth(9   ) == 10
							assert linked_list.delete_tail() == 11
							assert len(SCREAMING_SNAKE_CASE   ) == 9
							assert str(SCREAMING_SNAKE_CASE   ) == "->".join(str(SCREAMING_SNAKE_CASE   ) for i in range(1    ,						10   )   )

							assert all(linked_list[i] == i + 1 for i in range(0    ,						9   )   ) is True

							for i in range(0    ,						9   ):
														__lowerCamelCase      :      List[Any]         =-i
							assert all(linked_list[i] == -i for i in range(0    ,						9   )   ) is True

							linked_list.reverse()
							assert str(SCREAMING_SNAKE_CASE   ) == "->".join(str(SCREAMING_SNAKE_CASE   ) for i in range(-8    ,						1   )   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      Any         =[
							    -9,
							    100,
							    Node(77345112   ),
							    '''dlrow olleH''',
							    7,
							    5555,
							    0,
							    -192.55_555,
							    '''Hello, world!''',
							    77.9,
							    Node(10   ),
							    None,
							    None,
							    12.20,
							]
							__lowerCamelCase      :      str         =LinkedList()

							for i in test_input:
														linked_list.insert_tail(SCREAMING_SNAKE_CASE   )

							# Check if it's empty or not
							assert linked_list.is_empty() is False
							assert (
							    str(SCREAMING_SNAKE_CASE   ) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
							    "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
							)

							# Delete the head
							__lowerCamelCase      :      str         =linked_list.delete_head()
							assert result == -9
							assert (
							    str(SCREAMING_SNAKE_CASE   ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
							    "Hello, world!->77.9->Node(10)->None->None->12.2"
							)

							# Delete the tail
							__lowerCamelCase      :      Union[str, Any]         =linked_list.delete_tail()
							assert result == 12.2
							assert (
							    str(SCREAMING_SNAKE_CASE   ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
							    "Hello, world!->77.9->Node(10)->None->None"
							)

							# Delete a node in specific location in linked list
							__lowerCamelCase      :      Union[str, Any]         =linked_list.delete_nth(10   )
							assert result is None
							assert (
							    str(SCREAMING_SNAKE_CASE   ) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
							    "Hello, world!->77.9->Node(10)->None"
							)

							# Add a Node instance to its head
							linked_list.insert_head(Node('''Hello again, world!'''   )   )
							assert (
							    str(SCREAMING_SNAKE_CASE   )
							    == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
							    "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
							)

							# Add None to its tail
							linked_list.insert_tail(SCREAMING_SNAKE_CASE   )
							assert (
							    str(SCREAMING_SNAKE_CASE   )
							    == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
							    "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
							)

							# Reverse the linked list
							linked_list.reverse()
							assert (
							    str(SCREAMING_SNAKE_CASE   )
							    == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
							    "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
							)



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							from doctest import testmod

							testmod()

							__lowerCamelCase      :      Optional[Any]         =LinkedList()
							linked_list.insert_head(input('''Inserting 1st at head '''   ).strip()   )
							linked_list.insert_head(input('''Inserting 2nd at head '''   ).strip()   )
							print('''\nPrint list:'''   )
							linked_list.print_list()
							linked_list.insert_tail(input('''\nInserting 1st at tail '''   ).strip()   )
							linked_list.insert_tail(input('''Inserting 2nd at tail '''   ).strip()   )
							print('''\nPrint list:'''   )
							linked_list.print_list()
							print('''\nDelete head'''   )
							linked_list.delete_head()
							print('''Delete tail'''   )
							linked_list.delete_tail()
							print('''\nPrint list:'''   )
							linked_list.print_list()
							print('''\nReverse linked list'''   )
							linked_list.reverse()
							print('''\nPrint list:'''   )
							linked_list.print_list()
							print('''\nString representation of linked list:'''   )
							print(SCREAMING_SNAKE_CASE   )
							print('''\nReading/changing Node data using indexing:'''   )
							print(F'Element at Position 1: {linked_list[1]}'   )
							__lowerCamelCase      :      Any         =input('''Enter New Value: '''   ).strip()
							print('''New list:'''   )
							print(SCREAMING_SNAKE_CASE   )
							print(F'length of linked_list is : {len(SCREAMING_SNAKE_CASE   )}'   )


if __name__ == "__main__":
							main()




