from mteb.abstasks.retrieval import AbsTaskRetrieval
from mteb.abstasks.task_metadata import TaskMetadata

_fever_metadata = dict(
    reference="https://fever.ai/",
    type="Retrieval",
    category="t2t",
    modalities=["text"],
    eval_splits=["test"],
    eval_langs=["eng-Latn"],
    main_score="ndcg_at_10",
    date=None,
    domains=["Encyclopaedic", "Written"],
    task_subtypes=["Claim verification"],
    license="cc-by-nc-sa-3.0",
    annotations_creators="human-annotated",
    dialect=[],
    sample_creation="found",
    bibtex_citation=r"""
@inproceedings{thorne-etal-2018-fever,
  address = {New Orleans, Louisiana},
  author = {Thorne, James  and
Vlachos, Andreas  and
Christodoulopoulos, Christos  and
Mittal, Arpit},
  booktitle = {Proceedings of the 2018 Conference of the North {A}merican Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers)},
  doi = {10.18653/v1/N18-1074},
  editor = {Walker, Marilyn  and
Ji, Heng  and
Stent, Amanda},
  month = jun,
  pages = {809--819},
  publisher = {Association for Computational Linguistics},
  title = {{FEVER}: a Large-scale Dataset for Fact Extraction and {VER}ification},
  url = {https://aclanthology.org/N18-1074},
  year = {2018},
}
""",
)


class FEVER(AbsTaskRetrieval):
    ignore_identical_ids = True

    metadata = TaskMetadata(
        name="FEVER",
        dataset={
            "path": "mteb/fever",
            "revision": "bea83ef9e8fb933d90a2f1d5515737465d613e12",
        },
        description=(
            "FEVER (Fact Extraction and VERification) consists of 185,445 claims generated by altering sentences "
            "extracted from Wikipedia and subsequently verified without knowledge of the sentence they were "
            "derived from."
        ),
        prompt={
            "query": "Given a claim, retrieve documents that support or refute the claim"
        },
        **_fever_metadata,
    )


class FEVERHardNegatives(AbsTaskRetrieval):
    ignore_identical_ids = True

    metadata = TaskMetadata(
        name="FEVERHardNegatives",
        dataset={
            "path": "mteb/FEVER_test_top_250_only_w_correct-v2",
            "revision": "080c9ed6267b65029207906e815d44a9240bafca",
        },
        description=(
            "FEVER (Fact Extraction and VERification) consists of 185,445 claims generated by altering sentences "
            "extracted from Wikipedia and subsequently verified without knowledge of the sentence they were "
            "derived from. The hard negative version has been created by pooling the 250 top documents per query from BM25, e5-multilingual-large and e5-mistral-instruct."
        ),
        adapted_from=["FEVER"],
        superseded_by="FEVERHardNegatives.v2",
        **_fever_metadata,
    )


class FEVERHardNegativesV2(AbsTaskRetrieval):
    ignore_identical_ids = True

    metadata = TaskMetadata(
        name="FEVERHardNegatives.v2",
        dataset={
            "path": "mteb/FEVER_test_top_250_only_w_correct-v2",
            "revision": "080c9ed6267b65029207906e815d44a9240bafca",
        },
        description=(
            "FEVER (Fact Extraction and VERification) consists of 185,445 claims generated by altering sentences "
            "extracted from Wikipedia and subsequently verified without knowledge of the sentence they were "
            "derived from. The hard negative version has been created by pooling the 250 top documents per query from BM25, e5-multilingual-large and e5-mistral-instruct. "
            "V2 uses a more appropriate prompt rather than the default prompt for retrieval. You can get more information on the effect of different prompt in the [PR](https://github.com/embeddings-benchmark/mteb/pull/3469#issuecomment-3436467106)"
        ),
        adapted_from=["FEVER"],
        prompt={
            "query": "Given a claim, retrieve documents that support or refute the claim"
        },
        **_fever_metadata,
    )
