|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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): |
|
|
|
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 |
|
|