Matej Klemen commited on
Commit
9763e6d
1 Parent(s): b720c96

Add first version of script for loading Slovene collocations

Browse files
Files changed (2) hide show
  1. dataset_infos.json +1 -0
  2. slo_collocations.py +116 -0
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"default": {"description": "The database of the Collocations Dictionary of Modern Slovene 1.0 contains collocations that were automatically \nextracted from the Gigafida 1.0 corpus and then postprocessed.\n", "citation": "@inproceedings{kosem2018collocations,\n title={Collocations dictionary of modern Slovene},\n author={Kosem, Iztok and Krek, Simon and Gantar, Polona and Arhar Holdt, {\u000b{S}}pela and {\u000b{C}}ibej, Jaka and Laskowski, Cyprian},\n booktitle={Proceedings of the XVIII EURALEX International Congress: Lexicography in Global Contexts},\n pages={989--997},\n year={2018},\n organization={Znanstvena zalo{\u000b{z}}ba Filozofske fakultete Univerze v Ljubljani}\n}", "homepage": "https://www.cjvt.si/kssj/en/", "license": "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)", "features": {"collocation": {"dtype": "string", "id": null, "_type": "Value"}, "cluster": {"dtype": "uint32", "id": null, "_type": "Value"}, "words": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "sloleks_ids": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "gramrel": {"dtype": "string", "id": null, "_type": "Value"}, "sense": {"dtype": "uint32", "id": null, "_type": "Value"}, "id_lex_unit": {"dtype": "string", "id": null, "_type": "Value"}, "lex_unit": {"dtype": "string", "id": null, "_type": "Value"}, "lex_unit_category": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "slo_collocations", "config_name": "default", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 1499870912, "num_examples": 7310983, "dataset_name": "slo_collocations"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1250/KSSS.zip": {"num_bytes": 326435342, "checksum": "8d830d6257f7144a87169bd537831a448dbdf94ebc532938d8e684105b94eb77"}}, "download_size": 326435342, "post_processing_size": null, "dataset_size": 1499870912, "size_in_bytes": 1826306254}}
slo_collocations.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """A collocations dictionary of modern Slovene"""
2
+
3
+ import xml.etree.ElementTree as ET
4
+ import json
5
+ import os
6
+
7
+ import datasets
8
+
9
+
10
+ _CITATION = """\
11
+ @inproceedings{kosem2018collocations,
12
+ title={Collocations dictionary of modern Slovene},
13
+ author={Kosem, Iztok and Krek, Simon and Gantar, Polona and Arhar Holdt, {\v{S}}pela and {\v{C}}ibej, Jaka and Laskowski, Cyprian},
14
+ booktitle={Proceedings of the XVIII EURALEX International Congress: Lexicography in Global Contexts},
15
+ pages={989--997},
16
+ year={2018},
17
+ organization={Znanstvena zalo{\v{z}}ba Filozofske fakultete Univerze v Ljubljani}
18
+ }"""
19
+
20
+ _DESCRIPTION = """\
21
+ The database of the Collocations Dictionary of Modern Slovene 1.0 contains collocations that were automatically
22
+ extracted from the Gigafida 1.0 corpus and then postprocessed.
23
+ """
24
+
25
+ _HOMEPAGE = "https://www.cjvt.si/kssj/en/"
26
+
27
+ _LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
28
+
29
+ _URLS = {
30
+ "slo_collocations": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1250/KSSS.zip"
31
+ }
32
+
33
+
34
+ class SloCollocations(datasets.GeneratorBasedBuilder):
35
+ """A collocations dictionary of modern Slovene"""
36
+
37
+ VERSION = datasets.Version("1.0.0")
38
+
39
+ def _info(self):
40
+ features = datasets.Features({
41
+ "collocation": datasets.Value("string"),
42
+ "cluster": datasets.Value("uint32"),
43
+ "words": datasets.Sequence(datasets.Value("string")),
44
+ "sloleks_ids": datasets.Sequence(datasets.Value("string")),
45
+ "gramrel": datasets.Value("string"),
46
+ "sense": datasets.Value("uint32"),
47
+ "id_lex_unit": datasets.Value("string"),
48
+ "lex_unit": datasets.Value("string"),
49
+ "lex_unit_category": datasets.Value("string")
50
+ })
51
+
52
+ return datasets.DatasetInfo(
53
+ description=_DESCRIPTION,
54
+ features=features,
55
+ homepage=_HOMEPAGE,
56
+ license=_LICENSE,
57
+ citation=_CITATION
58
+ )
59
+
60
+ def _split_generators(self, dl_manager):
61
+ urls = _URLS["slo_collocations"]
62
+ data_dir = dl_manager.download_and_extract(urls)
63
+ return [
64
+ datasets.SplitGenerator(
65
+ name=datasets.Split.TRAIN,
66
+ gen_kwargs={"data_dir": os.path.join(data_dir, "KSSS")}
67
+ )
68
+ ]
69
+
70
+ def _generate_examples(self, data_dir):
71
+ # Map Slovene category (coarse POS tag) to its English translation
72
+ CATEGORY_MAPPING = {"samostalnik": "noun", "glagol": "verb", "pridevnik": "adjective", "prislov": "adverb"}
73
+
74
+ all_file_paths = []
75
+ for cat_slo in ["glagol", "pridevnik", "prislov", "samostalnik"]:
76
+ _curr_dir = os.path.join(data_dir, cat_slo)
77
+ for _fname in os.listdir(_curr_dir):
78
+ if os.path.isfile(os.path.join(_curr_dir, _fname)) and _fname.endswith(".xml"):
79
+ all_file_paths.append(os.path.join(_curr_dir, _fname))
80
+
81
+ idx_ex = 0
82
+ for file_path in all_file_paths:
83
+ curr_doc = ET.parse(file_path)
84
+ root = curr_doc.getroot()
85
+
86
+ header_tag = root.find("header")
87
+ lu_tag = header_tag.find("lexical_unit")
88
+
89
+ id_lu = lu_tag.attrib["id"]
90
+ lu_form = lu_tag.text
91
+ category = CATEGORY_MAPPING[header_tag.find("category").text.strip()]
92
+
93
+ for idx_sense, sense_tag in enumerate(root.findall(".//sense")):
94
+ for gramrel_tag in sense_tag.findall(".//gramrel"):
95
+ gramrel = gramrel_tag.attrib["name"]
96
+ for colloc_tag in gramrel_tag.findall(".//collocation"):
97
+ colloc_form = colloc_tag.attrib["form"]
98
+ colloc_cluster = colloc_tag.attrib["cluster"]
99
+
100
+ colloc_words, sloleks_ids = [], []
101
+ for comp_tag in colloc_tag.findall("comp"):
102
+ colloc_words.append(comp_tag.text)
103
+ sloleks_ids.append(comp_tag.attrib["sloleks"])
104
+
105
+ yield idx_ex, {
106
+ "collocation": colloc_form,
107
+ "cluster": int(colloc_cluster),
108
+ "words": colloc_words,
109
+ "sloleks_ids": sloleks_ids,
110
+ "gramrel": gramrel,
111
+ "sense": idx_sense,
112
+ "id_lex_unit": id_lu,
113
+ "lex_unit": lu_form,
114
+ "lex_unit_category": category,
115
+ }
116
+ idx_ex += 1