

'''simple docstring'''
import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


lowerCamelCase :      Dict					 =     "\\n    Text data.\n    Second line of data."

lowerCamelCase :      List[str]					 =     "file"


@pytest.fixture(scope='session'				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     Dict				)      ->			Dict:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =tmp_path_factory.mktemp('data'				) / (FILE_PATH + '.zstd')
     _SCREAMING_SNAKE_CASE							    =bytes(_UpperCamelCase							, 'utf-8'				)
     with zstd.open(_UpperCamelCase							, 'wb'				) as f:
          f.write(_UpperCamelCase				)
     return path


@pytest.fixture
def        _lowerCAmelCase					(						_UpperCamelCase						:     List[str]				)      ->			Dict:
     """simple docstring"""




     with open(os.path.join(tmpfs.local_root_dir							, _UpperCamelCase				)							, 'w'				) as f:
          f.write(_UpperCamelCase				)
     return FILE_PATH


@pytest.mark.parametrize('compression_format'							, ['gzip', 'xz', 'zstd']				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     Optional[int]							, _UpperCamelCase						:     Optional[Any]							, _UpperCamelCase						:     Optional[Any]							, _UpperCamelCase						:     Any							, _UpperCamelCase						:     Union[str, Any]							, _UpperCamelCase						:     str				)      ->			List[str]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    ={'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
     _SCREAMING_SNAKE_CASE							    =input_paths[compression_format]
     _SCREAMING_SNAKE_CASE							    =tmp_path / 'cache'
     _SCREAMING_SNAKE_CASE							    =DownloadConfig(cache_dir=_UpperCamelCase							, extract_compressed_file=_UpperCamelCase				)
     _SCREAMING_SNAKE_CASE							    =cached_path(_UpperCamelCase							, download_config=_UpperCamelCase				)
     with open(_UpperCamelCase				) as f:
          _SCREAMING_SNAKE_CASE							    =f.read()
     with open(_UpperCamelCase				) as f:
          _SCREAMING_SNAKE_CASE							    =f.read()
     assert extracted_file_content == expected_file_content


@pytest.mark.parametrize('default_extracted'							, [True, False]				)
@pytest.mark.parametrize('default_cache_dir'							, [True, False]				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     List[str]							, _UpperCamelCase						:     str							, _UpperCamelCase						:     Tuple							, _UpperCamelCase						:     List[str]							, _UpperCamelCase						:     Optional[int]				)      ->			Dict:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    ='custom_cache'
     _SCREAMING_SNAKE_CASE							    ='custom_extracted_dir'
     _SCREAMING_SNAKE_CASE							    =tmp_path / 'custom_extracted_path'
     if default_extracted:
          _SCREAMING_SNAKE_CASE							    =('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
     else:
          monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'							, _UpperCamelCase				)
          monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'							, str(_UpperCamelCase				)				)
          _SCREAMING_SNAKE_CASE							    =custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

     _SCREAMING_SNAKE_CASE							    =xz_file
     _SCREAMING_SNAKE_CASE							    =(
         DownloadConfig(extract_compressed_file=_UpperCamelCase				)
         if default_cache_dir
         else DownloadConfig(cache_dir=tmp_path / custom_cache_dir							, extract_compressed_file=_UpperCamelCase				)
     )
     _SCREAMING_SNAKE_CASE							    =cached_path(_UpperCamelCase							, download_config=_UpperCamelCase				)
     assert Path(_UpperCamelCase				).parent.parts[-2:] == expected


def        _lowerCAmelCase					(						_UpperCamelCase						:     Optional[Any]				)      ->			int:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =str(Path(_UpperCamelCase				).resolve()				)
     assert cached_path(_UpperCamelCase				) == text_file
     # relative path
     _SCREAMING_SNAKE_CASE							    =str(Path(_UpperCamelCase				).resolve().relative_to(Path(os.getcwd()				)				)				)
     assert cached_path(_UpperCamelCase				) == text_file


def        _lowerCAmelCase					(						_UpperCamelCase						:     List[str]				)      ->			List[Any]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =str(tmp_path.resolve() / '__missing_file__.txt'				)
     with pytest.raises(_UpperCamelCase				):
          cached_path(_UpperCamelCase				)
     # relative path
     _SCREAMING_SNAKE_CASE							    ='./__missing_file__.txt'
     with pytest.raises(_UpperCamelCase				):
          cached_path(_UpperCamelCase				)


def        _lowerCAmelCase					(						_UpperCamelCase						:     Optional[Any]				)      ->			List[str]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =get_from_cache(f"tmp://{tmpfs_file}"				)
     with open(_UpperCamelCase				) as f:
          _SCREAMING_SNAKE_CASE							    =f.read()
     assert output_file_content == FILE_CONTENT


@patch('datasets.config.HF_DATASETS_OFFLINE'							, _UpperCamelCase				)
def        _lowerCAmelCase					(						)      ->			Union[str, Any]:
     """simple docstring"""




     with pytest.raises(_UpperCamelCase				):
          cached_path('https://huggingface.co'				)


@patch('datasets.config.HF_DATASETS_OFFLINE'							, _UpperCamelCase				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     List[str]				)      ->			Tuple:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =tmp_path_factory.mktemp('data'				) / 'file.html'
     with pytest.raises(_UpperCamelCase				):
          http_get('https://huggingface.co'							, temp_file=_UpperCamelCase				)
     with pytest.raises(_UpperCamelCase				):
          http_head('https://huggingface.co'				)


@patch('datasets.config.HF_DATASETS_OFFLINE'							, _UpperCamelCase				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     List[Any]				)      ->			Union[str, Any]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =tmp_path_factory.mktemp('data'				) / 'file.html'
     with pytest.raises(_UpperCamelCase				):
          ftp_get('ftp://huggingface.co'							, temp_file=_UpperCamelCase				)
     with pytest.raises(_UpperCamelCase				):
          ftp_head('ftp://huggingface.co'				)







@patch('datasets.config.HF_DATASETS_OFFLINE'							, _UpperCamelCase				)
def        _lowerCAmelCase					(						_UpperCamelCase						:     Tuple				)      ->			Union[str, Any]:
     """simple docstring"""




     _SCREAMING_SNAKE_CASE							    =tmp_path_factory.mktemp('data'				) / 'file.html'
     with pytest.raises(_UpperCamelCase				):
          fsspec_get('s3://huggingface.co'							, temp_file=_UpperCamelCase				)
     with pytest.raises(_UpperCamelCase				):
          fsspec_head('s3://huggingface.co'				)



'''simple docstring'''
import numpy as np
from nltk.translate import meteor_score

import datasets
from datasets.config import importlib_metadata, version


lowerCamelCase :      List[Any]					 =     version.parse(importlib_metadata.version("nltk"))
if NLTK_VERSION >= version.Version("3.6.4"):
     from nltk import word_tokenize


lowerCamelCase :      Any					 =     "\\n@inproceedings{banarjee2005,\n  title     = {{METEOR}: An Automatic Metric for {MT} Evaluation with Improved Correlation with Human Judgments},\n  author    = {Banerjee, Satanjeev  and Lavie, Alon},\n  booktitle = {Proceedings of the {ACL} Workshop on Intrinsic and Extrinsic Evaluation Measures for Machine Translation and/or Summarization},\n  month     = jun,\n  year      = {2005},\n  address   = {Ann Arbor, Michigan},\n  publisher = {Association for Computational Linguistics},\n  url       = {https://www.aclweb.org/anthology/W05-0909},\n  pages     = {65--72},\n}\n"

lowerCamelCase :      Optional[Any]					 =     "\\nMETEOR, an automatic metric for machine translation evaluation\nthat is based on a generalized concept of unigram matching between the\nmachine-produced translation and human-produced reference translations.\nUnigrams can be matched based on their surface forms, stemmed forms,\nand meanings; furthermore, METEOR can be easily extended to include more\nadvanced matching strategies. Once all generalized unigram matches\nbetween the two strings have been found, METEOR computes a score for\nthis matching using a combination of unigram-precision, unigram-recall, and\na measure of fragmentation that is designed to directly capture how\nwell-ordered the matched words in the machine translation are in relation\nto the reference.\n\nMETEOR gets an R correlation value of 0.347 with human evaluation on the Arabic\ndata and 0.331 on the Chinese data. This is shown to be an improvement on\nusing simply unigram-precision, unigram-recall and their harmonic F1\ncombination.\n"

lowerCamelCase :      Optional[Any]					 =     "\nComputes METEOR score of translated segments against one or more references.\nArgs:\n    predictions: list of predictions to score. Each prediction\n        should be a string with tokens separated by spaces.\n    references: list of reference for each prediction. Each\n        reference should be a string with tokens separated by spaces.\n    alpha: Parameter for controlling relative weights of precision and recall. default: 0.9\n    beta: Parameter for controlling shape of penalty as a function of fragmentation. default: 3\n    gamma: Relative weight assigned to fragmentation penalty. default: 0.5\nReturns:\n    'meteor': meteor score.\nExamples:\n\n    >>> meteor = datasets.load_metric('meteor')\n    >>> predictions = [\"It is a guide to action which ensures that the military always obeys the commands of the party\"]\n    >>> references = [\"It is a guide to action that ensures that the military will forever heed Party commands\"]\n    >>> results = meteor.compute(predictions=predictions, references=references)\n    >>> print(round(results[\"meteor\"], 4))\n    0.6944\n"







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION     ,   _KWARGS_DESCRIPTION  )
class 							A__    (       datasets.Metric  ):





  def 						A  (		self      :	Tuple )	->    str:





       '''simple docstring'''






       return datasets.MetricInfo(
           description=_DESCRIPTION							,					citation=_CITATION							,					inputs_description=_KWARGS_DESCRIPTION							,					features=datasets.Features(
               {
                   'predictions': datasets.Value('string'							,					id='sequence' ),
                   'references': datasets.Value('string'							,					id='sequence' ),
               } )							,					codebase_urls=['https://github.com/nltk/nltk/blob/develop/nltk/translate/meteor_score.py']							,					reference_urls=[
               'https://www.nltk.org/api/nltk.translate.html#module-nltk.translate.meteor_score',
               'https://en.wikipedia.org/wiki/METEOR',
           ]							,					)





  def 						A  (		self      :	Union[str, Any]							,					_a      :	Union[str, Any] )	->    Optional[int]:





       '''simple docstring'''






       import nltk

       nltk.download('wordnet' )
       if NLTK_VERSION >= version.Version('3.6.5' ):
            nltk.download('punkt' )
       if NLTK_VERSION >= version.Version('3.6.6' ):
            nltk.download('omw-1.4' )





  def 						A  (		self      :	int							,					_a      :	Tuple							,					_a      :	List[str]							,					_a      :	List[str]=0.9							,					_a      :	Dict=3							,					_a      :	Optional[int]=0.5 )	->    Optional[int]:





       '''simple docstring'''






       if NLTK_VERSION >= version.Version('3.6.5' ):
            _SCREAMING_SNAKE_CASE							    =[
                meteor_score.single_meteor_score(
                    word_tokenize(_a )							,					word_tokenize(_a )							,					alpha=_a							,					beta=_a							,					gamma=_a )
                for ref, pred in zip(_a							,					_a )
            ]
       else:
            _SCREAMING_SNAKE_CASE							    =[
                meteor_score.single_meteor_score(_a							,					_a							,					alpha=_a							,					beta=_a							,					gamma=_a )
                for ref, pred in zip(_a							,					_a )
            ]

       return {"meteor": np.mean(_a )}
