Datasets:
File size: 6,329 Bytes
79488eb 4727f58 79488eb d2035db 79488eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import xml.etree.ElementTree as ET
from pathlib import Path
import datasets
_CITATION = """\
@Article{Sharjeel2016,
author="Sharjeel, Muhammad
and Nawab, Rao Muhammad Adeel
and Rayson, Paul",
title="COUNTER: corpus of Urdu news text reuse",
journal="Language Resources and Evaluation",
year="2016",
pages="1--27",
issn="1574-0218",
doi="10.1007/s10579-016-9367-2",
url="http://dx.doi.org/10.1007/s10579-016-9367-2"
}
"""
_DESCRIPTION = """\
The COrpus of Urdu News TExt Reuse (COUNTER) corpus contains 1200 documents with real examples of text reuse from the field of journalism. It has been manually annotated at document level with three levels of reuse: wholly derived, partially derived and non derived.
"""
_HOMEPAGE = "http://ucrel.lancs.ac.uk/textreuse/counter.php"
_LICENSE = (
"The corpus is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. "
)
_DOWNLOAD_URL = "http://ucrel.lancs.ac.uk/textreuse/COUNTER.zip"
_NUM_EXAMPLES = 600
_CLASS_NAME_MAP = {"WD": "wholly_derived", "PD": "partially_derived", "ND": "not_derived"}
class Counter(datasets.GeneratorBasedBuilder):
"""Corpus of Urdu News Text Reuse"""
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"source": {
"filename": datasets.Value("string"),
"headline": datasets.Value("string"),
"body": datasets.Value("string"),
"total_number_of_words": datasets.Value("int64"),
"total_number_of_sentences": datasets.Value("int64"),
"number_of_words_with_swr": datasets.Value("int64"),
"newspaper": datasets.Value("string"),
"newsdate": datasets.Value("string"),
"domain": datasets.ClassLabel(
names=[
"business",
"sports",
"national",
"foreign",
"showbiz",
]
),
"classification": datasets.ClassLabel(
names=["wholly_derived", "partially_derived", "not_derived"]
),
},
"derived": {
"filename": datasets.Value("string"),
"headline": datasets.Value("string"),
"body": datasets.Value("string"),
"total_number_of_words": datasets.Value("int64"),
"total_number_of_sentences": datasets.Value("int64"),
"number_of_words_with_swr": datasets.Value("int64"),
"newspaper": datasets.Value("string"),
"newsdate": datasets.Value("string"),
"domain": datasets.ClassLabel(
names=[
"business",
"sports",
"national",
"foreign",
"showbiz",
]
),
"classification": datasets.ClassLabel(
names=["wholly_derived", "partially_derived", "not_derived"]
),
},
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_DOWNLOAD_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"data_dir": data_dir},
)
]
def _generate_examples(self, data_dir):
"""Yields examples."""
def parse_file(file):
tree = ET.parse(file)
root = tree.getroot()
attributes = root.attrib
headline = root.find("headline").text
body = root.find("body").text
parsed = {
"filename": attributes["filename"],
"headline": headline,
"body": body,
"total_number_of_words": int(attributes["totalnoofwords"]),
"total_number_of_sentences": int(attributes["totalnoofsentences"]),
"number_of_words_with_swr": int(attributes["noofwordswithSWR"]),
"newspaper": attributes["newspaper"],
"newsdate": attributes["newsdate"],
"domain": attributes["domain"],
"classification": _CLASS_NAME_MAP[attributes["classification"]],
}
return parsed
base_path = Path(data_dir)
base_path = base_path / "COUNTER"
files = sorted(base_path.glob(r"[0-9][0-9][0-9][0-9].xml"))
for _id, file in enumerate(files):
example = {}
with file.open(encoding="utf-8") as f:
source = parse_file(f)
example["source"] = source
if file.stem == "0032":
derived_file = base_path / (file.stem + "P" + file.suffix)
else:
derived_file = base_path / (file.stem + "p" + file.suffix)
with derived_file.open(encoding="utf-8") as f:
derived = parse_file(f)
example["derived"] = derived
yield _id, example
|