Matej Klemen commited on
Commit
b70a641
1 Parent(s): 53626e5

Add first version of SloWNet

Browse files
Files changed (2) hide show
  1. dataset_infos.json +1 -0
  2. slownet.py +165 -0
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"default": {"description": "sloWNet is the Slovene WordNet developed in the expand approach: it contains the complete Princeton WordNet 3.0 and \nover 70 000 Slovene literals. These literals have been added automatically using different types of existing resources, \nsuch as bilingual dictionaries, parallel corpora and Wikipedia. 33 000 literals have been subsequently hand-validated.\n", "citation": "@inproceedings{fiser2012slownet,\n title={sloWNet 3.0: development, extension and cleaning},\n author={Fi{\u000b{s}}er, Darja and Novak, Jernej and Erjavec, Toma{\u000b{z}}},\n booktitle={Proceedings of 6th International Global Wordnet Conference (GWC 2012)},\n pages={113--117},\n year={2012}\n}\n", "homepage": "http://hdl.handle.net/11356/1026", "license": "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "pos": {"dtype": "string", "id": null, "_type": "Value"}, "bcs": {"dtype": "int32", "id": null, "_type": "Value"}, "en_synonyms": {"words": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "senses": {"feature": {"dtype": "int32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "pwnids": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "sl_synonyms": {"words": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "is_validated": {"feature": {"dtype": "bool", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "en_def": {"dtype": "string", "id": null, "_type": "Value"}, "sl_def": {"dtype": "string", "id": null, "_type": "Value"}, "en_usages": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "sl_usages": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "ilrs": {"types": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "id_synsets": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "semeval07_cluster": {"dtype": "string", "id": null, "_type": "Value"}, "domains": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "slownet", "config_name": "default", "version": {"version_str": "3.1.0", "description": null, "major": 3, "minor": 1, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 40339406, "num_examples": 117658, "dataset_name": "slownet"}}, "download_checksums": {"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1026/slownet.zip": {"num_bytes": 9937124, "checksum": "9e9b87ad98daf92143016183a2a81615906f02901939cf28a5b7a5e6cba5abfb"}}, "download_size": 9937124, "post_processing_size": null, "dataset_size": 40339406, "size_in_bytes": 50276530}}
slownet.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SloWNet is a semantic lexicon of Slovene."""
2
+
3
+
4
+ import os
5
+ import xml.etree.ElementTree as ET
6
+ import datasets
7
+
8
+
9
+ _CITATION = """\
10
+ @inproceedings{fiser2012slownet,
11
+ title={sloWNet 3.0: development, extension and cleaning},
12
+ author={Fi{\v{s}}er, Darja and Novak, Jernej and Erjavec, Toma{\v{z}}},
13
+ booktitle={Proceedings of 6th International Global Wordnet Conference (GWC 2012)},
14
+ pages={113--117},
15
+ year={2012}
16
+ }
17
+ """
18
+
19
+ _DESCRIPTION = """\
20
+ sloWNet is the Slovene WordNet developed in the expand approach: it contains the complete Princeton WordNet 3.0 and
21
+ over 70 000 Slovene literals. These literals have been added automatically using different types of existing resources,
22
+ such as bilingual dictionaries, parallel corpora and Wikipedia. 33 000 literals have been subsequently hand-validated.
23
+ """
24
+
25
+ _HOMEPAGE = "http://hdl.handle.net/11356/1026"
26
+
27
+ _LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
28
+
29
+ _URLS = {
30
+ "slownet": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1026/slownet.zip"
31
+ }
32
+
33
+ XML_NAMESPACE = "{http://www.w3.org/XML/1998/namespace}"
34
+ UNK_INT = -1
35
+ UNK_STR = "N/A"
36
+
37
+
38
+ class SloWNet(datasets.GeneratorBasedBuilder):
39
+ """SloWNet is a semantic lexicon of Slovene."""
40
+
41
+ VERSION = datasets.Version("3.1.0")
42
+
43
+ def _info(self):
44
+ features = datasets.Features(
45
+ {
46
+ "id": datasets.Value("string"),
47
+ "pos": datasets.Value("string"),
48
+ "bcs": datasets.Value("int32"),
49
+ "en_synonyms": {
50
+ "words": datasets.Sequence(datasets.Value("string")),
51
+ "senses": datasets.Sequence(datasets.Value("int32")),
52
+ "pwnids": datasets.Sequence(datasets.Value("string"))
53
+ },
54
+ "sl_synonyms": {
55
+ "words": datasets.Sequence(datasets.Value("string")),
56
+ "is_validated": datasets.Sequence(datasets.Value("bool"))
57
+ },
58
+ "en_def": datasets.Value("string"),
59
+ "sl_def": datasets.Value("string"),
60
+ "en_usages": datasets.Sequence(datasets.Value("string")),
61
+ "sl_usages": datasets.Sequence(datasets.Value("string")),
62
+ "ilrs": {
63
+ "types": datasets.Sequence(datasets.Value("string")),
64
+ "id_synsets": datasets.Sequence(datasets.Value("string"))
65
+ },
66
+ "semeval07_cluster": datasets.Value("string"),
67
+ "domains": datasets.Sequence(datasets.Value("string"))
68
+ }
69
+ )
70
+
71
+ return datasets.DatasetInfo(
72
+ description=_DESCRIPTION,
73
+ features=features,
74
+ homepage=_HOMEPAGE,
75
+ license=_LICENSE,
76
+ citation=_CITATION
77
+ )
78
+
79
+ def _split_generators(self, dl_manager):
80
+ urls = _URLS["slownet"]
81
+ data_dir = dl_manager.download_and_extract(urls)
82
+ return [
83
+ datasets.SplitGenerator(
84
+ name=datasets.Split.TRAIN,
85
+ gen_kwargs={"file_path": os.path.join(data_dir, "slownet-2015-05-07.xml")}
86
+ )
87
+ ]
88
+
89
+ def _generate_examples(self, file_path):
90
+ curr_doc = ET.parse(file_path)
91
+ root = curr_doc.getroot()
92
+
93
+ for idx_synset, synset in enumerate(root.iterfind("SYNSET")):
94
+ id_synset = synset.find("ID").text.strip()
95
+ pos_tag = synset.find("POS").text.strip()
96
+
97
+ # <BCS>
98
+ base_concept_set = synset.find("BCS")
99
+ if base_concept_set is not None:
100
+ base_concept_set = int(base_concept_set.text.strip())
101
+ else:
102
+ base_concept_set = UNK_INT
103
+
104
+ en_synonyms = {"words": [], "senses": [], "pwnids": []}
105
+ sl_synonyms = {"words": [], "is_validated": []}
106
+ # <SYNONYM>
107
+ for curr_synonyms in synset.findall("SYNONYM"):
108
+ lang = curr_synonyms.attrib[f"{XML_NAMESPACE}lang"]
109
+
110
+ if lang == "en":
111
+ for syn in curr_synonyms.iterfind("LITERAL"):
112
+ en_synonyms["words"].append(syn.text.strip())
113
+ en_synonyms["senses"].append(int(syn.attrib["sense"]))
114
+ en_synonyms["pwnids"].append(syn.attrib["pwnid"])
115
+ else:
116
+ for syn in curr_synonyms.iterfind("LITERAL"):
117
+ sl_synonyms["words"].append(syn.text.strip())
118
+ sl_synonyms["is_validated"].append(syn.attrib.get("lnote", "auto") == "manual")
119
+
120
+ # <DEF>: 1 or 2
121
+ sl_def, en_def = UNK_STR, UNK_STR
122
+ for curr_def in synset.findall("DEF"):
123
+ lang = curr_def.attrib[f"{XML_NAMESPACE}lang"]
124
+ if lang == "en":
125
+ en_def = curr_def.text.strip()
126
+ else:
127
+ sl_def = curr_def.text.strip()
128
+
129
+ en_usages, sl_usages = [], []
130
+ # <USAGE> - TODO: what does "lnote" indicate in Slovene usages? (some kind of ID?)
131
+ for curr_usage in synset.findall("USAGE"):
132
+ lang = curr_usage.attrib[f"{XML_NAMESPACE}lang"]
133
+ TARGET_LIST = en_usages if lang == "en" else sl_usages
134
+ TARGET_LIST.append(curr_usage.text.strip())
135
+
136
+ # <ILR>
137
+ ilrs = {"types": [], "id_synsets": []}
138
+ for curr_ilr in synset.findall("ILR"):
139
+ ilrs["types"].append(curr_ilr.attrib["type"])
140
+ ilrs["id_synsets"].append(curr_ilr.text.strip())
141
+
142
+ # <CLUSTER>
143
+ semeval07_cluster = synset.find("CLUSTER")
144
+ if semeval07_cluster is not None:
145
+ semeval07_cluster = semeval07_cluster.text.strip()
146
+ else:
147
+ semeval07_cluster = UNK_STR
148
+
149
+ # <DOMAIN>
150
+ domains = list(map(lambda el: el.text.strip(), synset.findall("DOMAIN")))
151
+
152
+ yield idx_synset, {
153
+ "id": id_synset,
154
+ "pos": pos_tag,
155
+ "bcs": base_concept_set,
156
+ "en_synonyms": en_synonyms,
157
+ "sl_synonyms": sl_synonyms,
158
+ "en_def": en_def,
159
+ "sl_def": sl_def,
160
+ "en_usages": en_usages,
161
+ "sl_usages": sl_usages,
162
+ "ilrs": ilrs,
163
+ "semeval07_cluster": semeval07_cluster,
164
+ "domains": domains
165
+ }