File size: 8,852 Bytes
90cbeb0 |
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# coding=utf-8
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
# Copyright 2021 Phonetics and Speech Laboratory, Trinity College, Dublin
#
# 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.
# Lint as: python3
import sys
from pathlib import Path
import datasets
try:
import icu
except ImportError:
sys.exit("ICU not found (hint: pip install pyicu)")
_DESCRIPTION = """\
Linguistic Atlas and Survey of Irish Dialects, volume 1
"""
_CITATION = """\
@book{wagner1958linguistic,
title={Linguistic Atlas and Survey of Irish Dialects: Introduction, 300 maps.},
author={Wagner, H.},
number={v. 1},
year={1958},
publisher={Dublin Institute for Advanced Studies}
}
@phdthesis{mckendry1982computer,
title={Computer-aided contributions to the study of Irish dialects},
author={McKendry, Eugene},
year={1982},
school={Queen's University Belfast}
}
@article{mckendry1998linguistic,
title={The Linguistic Atlas and Survey of Irish Dialects (LASID) and the Computer},
author={McKendry, Eugene},
journal={Studia Celtica Upsaliensia},
volume={2},
pages={345--354},
year={1998}
}
"""
_DATA_URL = "https://www3.smo.uhi.ac.uk/oduibhin/oideasra/lasid/lasid.zip"
LASID_ICU = """
\x07 β α΅ ;
\\\t β α΅ ; # \x09
\x0e β α΄΅ ;
\x11 β Κ° ;
\x12 β β± ;
\x13 β α΅ ;
\x14 β α΅Μ€ ;
\x15 β Κ³ ;
\x16 β Λ’ ;
\x17 β αΆ΄ ;
\x18 β α΅ ;
\x19 β α΅ ;
\x1a β α΅Μ― ;
\x1c β α΅ ;
\x1d β Κ· ;
\x1e β αΆΎ ;
\x1f β α΅ ;
\# β αΆ ; # \x23
\$ β α΅ ; # \x24
\% β α΅ ; # \x25
\& β α΅ ; # \x26 Λ for IPA
\' β β ; # \x27
\: β Λ ; # \x3a
\< β β±Μ ; # \x3c
\= β β±Μ― ; # \x3d
\? β Κ ; # \x3f
\@ β Κ² ; # \x40
E β α΄ ; # \x45
I β Ιͺ ; # \x49
L β Κ ;
N β Ι΄ ;
R β Κ ;
\^ β α΅ ; # \x5e
\_ β Η° ; # crane, 021 # \x5f
\` β ΙΜΜ ; # limekiln, 078: \x60
\| β βΏ ; # lamb, 055: \x7c
\~ β α΅ ; # dreaming, 078; maybe βΏΜ ? # \x7e
\x7f β α΄Μ ;
\x80 β Ο ; # ΙΈ
\x81 β ΓΌ ;
\x83 β Ι \u0300 ;
\x84 β eΜ \u0323 ; # FIXME
\\\x85 β eΜΜ ; # this is οΏ½, so it needs to be escaped
\x86 β uΜΜ ; # lamb, 038
\x87 β uΜ ; # finger-nails, 043
\x88 β Κ ; # looks like tΜ : toothache, 033
\x89 β α΅ ; # eggs, 066
\x8a β Γ¨ ;
\x8b β Γ― ;
\x8c β ΙΜΜ ; # grandmother, 007
\x8d β ΙΜ ;
\x8e β ΙΜ ; # before i go, 078
\x8f β oΜΜ ; # as cute, 062
\x91 β Γ¦ ;
\x92 β oΜ ;
\x93 β Ι ;
\x94 β ΓΆ ;
\x95 β ΙΜΜ ;
\x96 β Γ» ; # milking, 067
\x97 β Ι \u0323 ; # FIXME (maybe Ξ±Μ© or ΙΜ ?)
\x98 β vΜ ;
\x99 β tΜ ; # toothache, 021
\x9a β rΜ ;
\x9b β ΓΈ ;
\x9c β Ι΄Μ ; # sick, 034
\x9d β ΕΜ ; # grazing, 002
\x9e β nΜ ;
\x9f β lΜ ; # plumage, 068
\xa4 β kΜ ; # plumage, 068
\xa5 β gΜ ;
\xa6 β dΜ ; # wedge, 021
\xa7 β uΜ ;
\xa8 β oΜΜ ;
\xa9 β oΜ ;
\xaa β iΜ ;
\xab β ΙΜ ;
\xac β eΜ ;
\xad β oΜ€ ;
\xae β Ξ» ;
\xaf β Ι ; # Ξ± in the software
\xb0 β Ι ;
\xb1 β ΙΜ \u0323 ; # FIXME
\xb2 β Ι ;
\xb4 β α΅ ; # tail, 007
\xb6 β ΙΜ ; # Ξ±Μ in the software
\xb7 β aΜ ;
\xb8 β Ξ» \u0323 ; # FIXME
\xb9 β Ι ;
\xba β Κ \u030c ; # calling, 067
\xbb β Ε‘ ;
\xbc β Ε ;
\xbd β ΙΜ ;
\xbe β eΜ ; # tied, 88N
\xc1 β β² ; # superscript prime
\xc5 β α΄Μ ; # fart, 071
\xc6 β aΜ ; # calf, 046
\xc7 β t \u0323 ; # probably tΜ
\xc8 β Ξ»Μ― ; # mane, 067
\xc9 β oΜ― ; # hare, 088
\xca β β±’ ; # loaf, 001
\xcb β Ι« ; # loaf, 003
\xcc β mΜ₯ ; # awake, 001
\xcd β ΚΜ₯ ; # thieving, 003
\xce β Λ ;
\xcf β Λ ; # cattle, 040
\xd0 β Γ° ; # boar, 88N
\xd1 β s \u0323 ; # FIXME # slime 008
\xd2 β r \u0323 ; # FIXME # bulls 067
\xd3 β ΙͺΜ ; # suit of clothes 039
\xd4 β α΄Μ ;
\xd5 β p \u0323 ; # FIXME # castrating 053
\xd7 β ΙͺΜ ; # slime, 007
\xd8 β ΙͺΜ ; # calf 027
\xdb β o \u0323 ; # FIXME # cow 028
\xdc β Ε \u0323 ; # FIXME # tied 078
\xdd β oΜΜ€ ;
\xde β k \u0323 ; # FIXME
\xdf β i \u0323 ; # FIXME # sick 069
\xe1 β g \u0323 ; # FIXME
\xe2 β e \u0323 ; # FIXME
\xe3 β d \u0323 ; # FIXME # agut 052
\xe4 β oΜ ; # I shall tie 062
\xe5 β b \u0323 ; # FIXME # castrating 071
\xe6 β ΙΜ \u0323 ; #FIXME # barking 049
\xe7 β Ι \u0323 ; # FIXME # slime 008
\xe8 β yΜ ;
\xea β Ξ»Μ ;
\xeb β uΜΜ ; # churn-dash, 011
\xec β uΜ ;
\xed β ΙΜ ; # cow 074
\xee β oΜ€Μ ; # barking 055
\xef β β² ;
\xf0 β β³ ;
\xf1 β oΜΜ€Μ ; # dreaming, 078
\xf2 β oΜΜ ; # sheep shears 074
\xf3 β iΜΜ ; # churn-dash, 034
\xf4 β iΜ ; # sick 001
\xf5 β Ι£Μ ; # tied 075
\xf6 β ΙΜ ; # tied 067
\xf7 β nΜ₯ ; # awake, 059
\xf8 β rΜ₯ ; # slime 002
\xf9 β Κ ;
\xfb β Β· ; # slime 058
\xfa β Ι£ ;
\xfc β Ο ; # limekiln, 080
\xfd β Κ ; # sheep shears 054
\xfe β Ε ;
"""
LASID_TITLES_ICU = """
\xb5 β Γ ;
\xd6 β Γ ;
\x90 β Γ ;
\xe0 β Γ ;
\xe9 β Γ ;
"""
def transliterator_from_rules(name, rules):
fromrules = icu.Transliterator.createFromRules(name, rules)
icu.Transliterator.registerInstance(fromrules)
return icu.Transliterator.createInstance(name)
LASID = transliterator_from_rules('lasid_icu', LASID_ICU)
TITLES = transliterator_from_rules('lasid_titles', LASID_TITLES_ICU)
def translit_phon(text):
# could have been any 8-bit encoding
return LASID.transliterate(text.decode('ISO-8859-1').rstrip())
def translit_irish(text):
return TITLES.transliterate(text.decode('ISO-8859-1').rstrip())
class LasidDataset(datasets.GeneratorBasedBuilder):
"""Scraper dataset for LASID."""
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="lasid"),
]
def _info(self):
features = datasets.Features(
{
"english": datasets.Value("string"),
"irish": datasets.Value("string"),
"map_id": datasets.Value("string"),
"place_ids": datasets.Sequence(datasets.Value("string")),
"transcripts": datasets.Sequence(datasets.Value("string")),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
citation=_CITATION
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
dl_path = dl_manager.download_and_extract(_DATA_URL)
infile = f"{dl_path}/mapdata.dat"
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"split": "train",
"data_file": infile
},
),
]
def _generate_examples(
self, split, data_file
):
""" Yields examples as (key, example) tuples. """
data = process_lasid(data_file)
_id = 1
for map in data.keys():
item = data[map]
place_ids = list(item["data"])
transcripts = [item["data"][a] for a in place_ids]
yield _id, {
"english": item.get("en", ""),
"irish": item.get("ga", ""),
"map_id": item.get("id", ""),
"place_ids": place_ids,
"transcripts": transcripts
}
_id += 1
def process_lasid(filename):
data = {}
cur = {}
en = ''
ga = ''
id = ''
with open(filename, "rb") as file:
for line in file.readlines():
if b'{M' in line:
if en and id:
tmp = {}
tmp['en'] = en
tmp['id'] = id
tmp['ga'] = ga
tmp['data'] = cur
data[id] = tmp
text = line.decode('ISO-8859-1').rstrip()
id = text[3:7].strip()
en = text[7:-1].strip()
cur = {}
elif b'{F' in line:
raw = translit_irish(line)
ga = raw[3:-1].strip()
elif line.decode('ISO-8859-1')[0:1].isnumeric():
pid = line.decode('ISO-8859-1')[0:3]
ptext = translit_phon(line[3:-1])
if ptext[-1] == '*':
ptext = ptext[0:-1]
cur[pid] = ptext.strip()
return data
|