






import os

from ...utils import logging
from .utils import DataProcessor, InputExample


UpperCamelCase											=      logging.get_logger(__name__)




class 	lowerCamelCase__				(							UpperCAmelCase ):






      def __init__(self					:    List[Any]		,		_snake_case					:    Dict		,		_snake_case					:    Optional[Any]=None		)       ->   List[str]:


       """simple docstring"""






       lowerCamelCase_							:    Any							=     language
       lowerCamelCase_							:    Optional[Any]							=     train_language






      def      UpperCAmelCase_     (self					:    Any		,		_snake_case					:    Optional[Any]		)       ->   Union[str, Any]:


       """simple docstring"""






       lowerCamelCase_							:    List[str]							=     self.language if self.train_language is None else self.train_language
       lowerCamelCase_							:    Optional[Any]							=     self._read_tsv(os.path.join(_snake_case		,		f'XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv'		)		)
       lowerCamelCase_							:    Tuple							=     []
       for i, line in enumerate(_snake_case		):
        if i == 0:
         continue
        lowerCamelCase_							:    Tuple							=     f'train-{i}'
        lowerCamelCase_							:    Optional[Any]							=     line[0]
        lowerCamelCase_							:    List[Any]							=     line[1]
        lowerCamelCase_							:    Tuple							=     'contradiction' if line[2] == 'contradictory' else line[2]
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training input {text_a} is not a string'		)
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training input {text_b} is not a string'		)
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training label {label} is not a string'		)
        examples.append(InputExample(guid=_snake_case		,		text_a=_snake_case		,		text_b=_snake_case		,		label=_snake_case		)		)
       return examples






      def      UpperCAmelCase_     (self					:    List[Any]		,		_snake_case					:    List[Any]		)       ->   Optional[int]:


       """simple docstring"""






       lowerCamelCase_							:    List[Any]							=     self._read_tsv(os.path.join(_snake_case		,		'XNLI-1.0/xnli.test.tsv'		)		)
       lowerCamelCase_							:    Optional[int]							=     []
       for i, line in enumerate(_snake_case		):
        if i == 0:
         continue
        lowerCamelCase_							:    Dict							=     line[0]
        if language != self.language:
         continue
        lowerCamelCase_							:    List[str]							=     f'test-{i}'
        lowerCamelCase_							:    int							=     line[6]
        lowerCamelCase_							:    Optional[int]							=     line[7]
        lowerCamelCase_							:    Tuple							=     line[1]
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training input {text_a} is not a string'		)
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training input {text_b} is not a string'		)
        if not isinstance(_snake_case		,		_snake_case		):
         raise ValueError(f'Training label {label} is not a string'		)
        examples.append(InputExample(guid=_snake_case		,		text_a=_snake_case		,		text_b=_snake_case		,		label=_snake_case		)		)
       return examples






      def      UpperCAmelCase_     (self					:    Optional[int]		)       ->   Optional[int]:


       """simple docstring"""






       return ["contradiction", "entailment", "neutral"]


UpperCamelCase											=      {
    '''xnli''': XnliProcessor,
}

UpperCamelCase											=      {
    '''xnli''': '''classification''',
}

UpperCamelCase											=      {
    '''xnli''': 3,
}








import unittest

from transformers import load_tool
from transformers.tools.agent_types import AGENT_TYPE_MAPPING

from .test_tools_common import ToolTesterMixin, output_types




class 	lowerCamelCase__				(							unittest.TestCase,   UpperCAmelCase ):






      def      UpperCAmelCase_     (self					:    Any		)       ->   Union[str, Any]:


       """simple docstring"""






       lowerCamelCase_							:    str							=     load_tool('translation'		)
       self.tool.setup()
       lowerCamelCase_							:    Optional[int]							=     load_tool('translation'		,		remote=_snake_case		)






      def      UpperCAmelCase_     (self					:    Any		)       ->   Dict:


       """simple docstring"""






       lowerCamelCase_							:    Optional[Any]							=     self.tool('Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Optional[int]		)       ->   Dict:


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     self.remote_tool('Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    List[str]		)       ->   Optional[int]:


       """simple docstring"""






       lowerCamelCase_							:    Union[str, Any]							=     self.tool(text='Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Any		)       ->   Tuple:


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     self.remote_tool(text='Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Union[str, Any]		)       ->   Any:


       """simple docstring"""






       lowerCamelCase_							:    str							=     ['Hey, what\'s up?', 'English', 'Spanish']
       lowerCamelCase_							:    Any							=     self.tool(*_snake_case		)

       # There is a single output
       if len(self.tool.outputs		) == 1:
        lowerCamelCase_							:    Any							=     [outputs]

       self.assertListEqual(output_types(_snake_case		)		,		self.tool.outputs		)






      def      UpperCAmelCase_     (self					:    Tuple		)       ->   Optional[Any]:


       """simple docstring"""






       lowerCamelCase_							:    List[str]							=     ['Hey, what\'s up?', 'English', 'Spanish']
       lowerCamelCase_							:    Optional[Any]							=     self.tool(*_snake_case		)

       if not isinstance(_snake_case		,		_snake_case		):
        lowerCamelCase_							:    List[str]							=     [outputs]

       self.assertEqual(len(_snake_case		)		,		len(self.tool.outputs		)		)

       for output, output_type in zip(_snake_case		,		self.tool.outputs		):
        lowerCamelCase_							:    Optional[int]							=     AGENT_TYPE_MAPPING[output_type]
        self.assertTrue(isinstance(_snake_case		,		_snake_case		)		)






      def      UpperCAmelCase_     (self					:    Any		)       ->   Optional[Any]:


       """simple docstring"""






       lowerCamelCase_							:    Dict							=     ['Hey, what\'s up?', 'English', 'Spanish']

       lowerCamelCase_							:    List[str]							=     []

       for _input, input_type in zip(_snake_case		,		self.tool.inputs		):
        if isinstance(_snake_case		,		_snake_case		):
         _inputs.append([AGENT_TYPE_MAPPING[_input_type](_input		) for _input_type in input_type]		)
        else:
         _inputs.append(AGENT_TYPE_MAPPING[input_type](_input		)		)

        # Should not raise an error
       lowerCamelCase_							:    Any							=     self.tool(*_snake_case		)

       if not isinstance(_snake_case		,		_snake_case		):
        lowerCamelCase_							:    Optional[Any]							=     [outputs]

       self.assertEqual(len(_snake_case		)		,		len(self.tool.outputs		)		)
