Datasets:
cjvt
/

Modalities:
Text
Languages:
Slovenian
Libraries:
Datasets
License:
Matej Klemen commited on
Commit
a9293ec
1 Parent(s): 262fce9

Add first version of dataset script

Browse files
Files changed (2) hide show
  1. README.md +46 -0
  2. janes_preklop.py +162 -0
README.md CHANGED
@@ -1,3 +1,49 @@
1
  ---
2
  license: cc-by-sa-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-4.0
3
+ dataset_info:
4
+ features:
5
+ - name: id
6
+ dtype: string
7
+ - name: words
8
+ sequence: string
9
+ - name: language
10
+ sequence: string
11
+ splits:
12
+ - name: train
13
+ num_bytes: 412672
14
+ num_examples: 1104
15
+ download_size: 623816
16
+ dataset_size: 412672
17
  ---
18
+
19
+ # Dataset Card for Janes-Preklop
20
+
21
+ ### Dataset Summary
22
+
23
+ Janes-Preklop is a corpus of Slovene tweets that is manually annotated for code-switching: the use of words from two
24
+ or more languages within one sentence or utterance.
25
+
26
+ ### Languages
27
+
28
+ Code-switched Slovenian.
29
+
30
+ ## Dataset Structure
31
+
32
+ ### Data Instances
33
+
34
+ A sample instance from the dataset - each word is annotated with its language, either `"default"`
35
+ (Slovenian/unclassifiable), `en` (English), `de` (German), `hbs` (Serbo-Croatian), `sp` (Spanish),
36
+ `la` (Latin), `ar` (Arabic), `fr` (French), `it` (Italian), or `pt` (Portuguese).
37
+ ```
38
+ {
39
+ 'id': 'tid.397447931558895616',
40
+ 'words': ['Brad', 'Pitt', 'na', 'Planet', 'TV', '.', 'U', 'are', 'welcome', ';)'],
41
+ 'language': ['default', 'default', 'default', 'default', 'default', 'default', 'en', 'en', 'en', 'en']
42
+ }
43
+ ```
44
+
45
+ ### Data Fields
46
+
47
+ - `id`: unique identifier of the example;
48
+ - `words`: words in the sentence;
49
+ - `language`: language of each word.
janes_preklop.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import xml.etree.ElementTree as ET
4
+
5
+ import datasets
6
+
7
+ XML_NAMESPACE = "{http://www.w3.org/XML/1998/namespace}"
8
+ DEFAULT_LANG = "default"
9
+
10
+
11
+ _CITATION = """\
12
+ @misc{janes_preklop,
13
+ title = {Tweet code-switching corpus Janes-Preklop 1.0},
14
+ author = {Reher, {\v S}pela and Erjavec, Toma{\v z} and Fi{\v s}er, Darja},
15
+ url = {http://hdl.handle.net/11356/1154},
16
+ note = {Slovenian language resource repository {CLARIN}.{SI}},
17
+ copyright = {Creative Commons - Attribution-{ShareAlike} 4.0 International ({CC} {BY}-{SA} 4.0)},
18
+ issn = {2820-4042},
19
+ year = {2017}
20
+ }
21
+ """
22
+
23
+ _DESCRIPTION = """\
24
+ Janes-Preklop is a corpus of Slovene tweets that is manually annotated for code-switching (the use of words from two
25
+ or more languages within one sentence or utterance), according to the supplied typology.
26
+ """
27
+
28
+ _HOMEPAGE = "http://nl.ijs.si/janes/"
29
+
30
+ _LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
31
+
32
+ _URLS = {
33
+ "janes_preklop_tei": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1154/Janes-Preklop.TEI.zip"
34
+ }
35
+
36
+
37
+ def namespace(element):
38
+ # https://stackoverflow.com/a/12946675
39
+ m = re.match(r'\{.*\}', element.tag)
40
+ return m.group(0) if m else ''
41
+
42
+
43
+ def word_info(wordlike_tag, _namespace):
44
+ if wordlike_tag.tag == f"{_namespace}c":
45
+ return None, None
46
+
47
+ elif wordlike_tag.tag in {f"{_namespace}w", f"{_namespace}pc"}:
48
+ _word = wordlike_tag.text.strip()
49
+ return [_word], None
50
+
51
+ words, lang = [], []
52
+ if wordlike_tag.tag == f"{_namespace}choice":
53
+ # Ignore <orig>, keep <reg>ularized text
54
+ reg_tag = wordlike_tag.find(f"{_namespace}reg")
55
+
56
+ for _child in reg_tag:
57
+ _child_words, _child_langs = word_info(_child, _namespace)
58
+
59
+ if _child_words is None:
60
+ continue
61
+
62
+ words.extend(_child_words)
63
+
64
+ if _child_langs is None:
65
+ _child_langs = [DEFAULT_LANG for _ in range(len(_child_words))]
66
+ lang.extend(_child_langs)
67
+
68
+ return words, lang
69
+
70
+ elif wordlike_tag.tag == f"{_namespace}seg":
71
+ codeswitch_lang = wordlike_tag.attrib.get(f"{XML_NAMESPACE}lang", DEFAULT_LANG)
72
+ _seg_words, _seg_langs = [], []
73
+
74
+ for _child in wordlike_tag:
75
+ _child_words, _child_langs = word_info(_child, _namespace)
76
+
77
+ if _child_words is None:
78
+ continue
79
+
80
+ _seg_words.extend(_child_words)
81
+
82
+ if _child_langs is None:
83
+ _child_langs = [codeswitch_lang for _ in range(len(_child_words))]
84
+ _seg_langs.extend(_child_langs)
85
+
86
+ if codeswitch_lang != DEFAULT_LANG:
87
+ _seg_langs[0] = f"B-{_seg_langs[0]}"
88
+ for _i in range(1, len(_seg_words)):
89
+ _seg_langs[_i] = f"I-{_seg_langs[_i]}"
90
+
91
+ words.extend(_seg_words)
92
+ lang.extend(_seg_langs)
93
+
94
+ return words, lang
95
+
96
+
97
+ class JanesPreklop(datasets.GeneratorBasedBuilder):
98
+ """Code-switched Slovene tweet dataset. """
99
+
100
+ VERSION = datasets.Version("1.0.0")
101
+
102
+ def _info(self):
103
+ features = datasets.Features(
104
+ {
105
+ "id": datasets.Value("string"),
106
+ "words": datasets.Sequence(datasets.Value("string")),
107
+ "language": datasets.Sequence(datasets.Value("string"))
108
+ }
109
+ )
110
+
111
+ return datasets.DatasetInfo(
112
+ description=_DESCRIPTION,
113
+ features=features,
114
+ homepage=_HOMEPAGE,
115
+ license=_LICENSE,
116
+ citation=_CITATION,
117
+ )
118
+
119
+ def _split_generators(self, dl_manager):
120
+ urls = _URLS["janes_preklop_tei"]
121
+ data_dir = dl_manager.download_and_extract(urls)
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ gen_kwargs={"file_path": os.path.join(data_dir, "Janes-Preklop.TEI", "janes.preklop.body.xml")},
126
+ )
127
+ ]
128
+
129
+ def _generate_examples(self, file_path):
130
+ curr_doc = ET.parse(file_path)
131
+ root = curr_doc.getroot()
132
+ NAMESPACE = namespace(root)
133
+
134
+ idx_ex = 0
135
+ for curr_ex in root.iterfind(f"{NAMESPACE}ab"):
136
+ ex_words, ex_langs = [], []
137
+ for child_tag in curr_ex:
138
+ if child_tag.tag not in {f"{NAMESPACE}s", f"{NAMESPACE}c"}:
139
+ continue
140
+
141
+ if child_tag.tag == f"{NAMESPACE}c":
142
+ continue
143
+
144
+ # Iterate over elements of a <s>entence
145
+ for word_or_seg_tag in child_tag:
146
+ _words, _langs = word_info(word_or_seg_tag, NAMESPACE)
147
+
148
+ if _words is None:
149
+ continue
150
+
151
+ if _langs is None:
152
+ _langs = [DEFAULT_LANG for _ in range(len(_words))]
153
+
154
+ ex_words.extend(_words)
155
+ ex_langs.extend(_langs)
156
+
157
+ yield idx_ex, {
158
+ "id": curr_ex.attrib[f"{XML_NAMESPACE}id"],
159
+ "words": ex_words,
160
+ "language": ex_langs
161
+ }
162
+ idx_ex += 1