Datasets:
Matej Klemen
commited on
Commit
•
d32236e
1
Parent(s):
4af9bd9
Add first version of dataset script
Browse files- README.md +18 -0
- janes_tag.py +157 -0
README.md
CHANGED
@@ -1,3 +1,21 @@
|
|
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: lemmas
|
10 |
+
sequence: string
|
11 |
+
- name: msds
|
12 |
+
sequence: string
|
13 |
+
- name: nes
|
14 |
+
sequence: string
|
15 |
+
splits:
|
16 |
+
- name: train
|
17 |
+
num_bytes: 2652674
|
18 |
+
num_examples: 2957
|
19 |
+
download_size: 2871765
|
20 |
+
dataset_size: 2652674
|
21 |
---
|
janes_tag.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import xml.etree.ElementTree as ET
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
|
8 |
+
_CITATION = """\
|
9 |
+
@misc{janes_tag,
|
10 |
+
title = {{CMC} training corpus Janes-Tag 3.0},
|
11 |
+
author = {Lenardi{\v c}, Jakob and {\v C}ibej, Jaka and Arhar Holdt, {\v S}pela and Erjavec, Toma{\v z} and Fi{\v s}er, Darja and Ljube{\v s}i{\'c}, Nikola and Zupan, Katja and Dobrovoljc, Kaja},
|
12 |
+
url = {http://hdl.handle.net/11356/1732},
|
13 |
+
note = {Slovenian language resource repository {CLARIN}.{SI}},
|
14 |
+
copyright = {Creative Commons - Attribution-{ShareAlike} 4.0 International ({CC} {BY}-{SA} 4.0)},
|
15 |
+
year = {2022}
|
16 |
+
}
|
17 |
+
"""
|
18 |
+
|
19 |
+
|
20 |
+
_DESCRIPTION = """\
|
21 |
+
Janes-Tag is a manually annotated corpus of Slovene Computer-Mediated Communication (CMC) consisting of mostly tweets
|
22 |
+
but also blogs, forums and news comments.
|
23 |
+
"""
|
24 |
+
|
25 |
+
_HOMEPAGE = "https://nl.ijs.si/janes/"
|
26 |
+
|
27 |
+
_LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
|
28 |
+
|
29 |
+
_URLS = {
|
30 |
+
"janes_tag_tei": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1732/Janes-Tag.3.0.TEI.zip"
|
31 |
+
}
|
32 |
+
|
33 |
+
XML_NAMESPACE = "{http://www.w3.org/XML/1998/namespace}"
|
34 |
+
DEFAULT_NE = "O"
|
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, None, None
|
46 |
+
|
47 |
+
if wordlike_tag.tag in {f"{_namespace}w", f"{_namespace}pc"}:
|
48 |
+
nes = None
|
49 |
+
if "lemma" in wordlike_tag.attrib:
|
50 |
+
words = [wordlike_tag.text.strip()]
|
51 |
+
lemmas = [wordlike_tag.attrib["lemma"].strip()]
|
52 |
+
msds = [wordlike_tag.attrib["ana"].strip()]
|
53 |
+
|
54 |
+
# If this happens, the word contains nested words indicating its normalized form
|
55 |
+
else:
|
56 |
+
words, lemmas, msds = [], [], []
|
57 |
+
for _child in wordlike_tag:
|
58 |
+
words.append(_child.attrib["norm"].strip())
|
59 |
+
lemmas.append(_child.attrib["lemma"].strip())
|
60 |
+
msds.append(_child.attrib["ana"].strip())
|
61 |
+
|
62 |
+
return words, lemmas, msds, nes
|
63 |
+
|
64 |
+
words, lemmas, msds, nes = [], [], [], []
|
65 |
+
|
66 |
+
if wordlike_tag.tag == f"{_namespace}seg":
|
67 |
+
ne_tag = wordlike_tag.attrib["subtype"].strip().upper()
|
68 |
+
|
69 |
+
for _child in wordlike_tag:
|
70 |
+
_child_words, _child_lemmas, _child_msds, _child_nes = word_info(_child, _namespace)
|
71 |
+
|
72 |
+
if _child_words is None:
|
73 |
+
continue
|
74 |
+
|
75 |
+
words.extend(_child_words)
|
76 |
+
lemmas.extend(_child_lemmas)
|
77 |
+
msds.extend(_child_msds)
|
78 |
+
|
79 |
+
nes = [f"B-{ne_tag}" if _i == 0 else f"I-{ne_tag}" for _i, _ in enumerate(words)]
|
80 |
+
|
81 |
+
return words, lemmas, msds, nes
|
82 |
+
|
83 |
+
|
84 |
+
class JanesTag(datasets.GeneratorBasedBuilder):
|
85 |
+
"""Janes-Tag is a manually annotated corpus of Slovene Computer-Mediated Communication"""
|
86 |
+
|
87 |
+
VERSION = datasets.Version("3.0.0")
|
88 |
+
|
89 |
+
def _info(self):
|
90 |
+
features = datasets.Features(
|
91 |
+
{
|
92 |
+
"id": datasets.Value("string"),
|
93 |
+
"words": datasets.Sequence(datasets.Value("string")),
|
94 |
+
"lemmas": datasets.Sequence(datasets.Value("string")),
|
95 |
+
"msds": datasets.Sequence(datasets.Value("string")),
|
96 |
+
"nes": datasets.Sequence(datasets.Value("string"))
|
97 |
+
}
|
98 |
+
)
|
99 |
+
|
100 |
+
return datasets.DatasetInfo(
|
101 |
+
description=_DESCRIPTION,
|
102 |
+
features=features,
|
103 |
+
homepage=_HOMEPAGE,
|
104 |
+
license=_LICENSE,
|
105 |
+
citation=_CITATION,
|
106 |
+
)
|
107 |
+
|
108 |
+
def _split_generators(self, dl_manager):
|
109 |
+
urls = _URLS["janes_tag_tei"]
|
110 |
+
data_dir = dl_manager.download_and_extract(urls)
|
111 |
+
return [
|
112 |
+
datasets.SplitGenerator(
|
113 |
+
name=datasets.Split.TRAIN,
|
114 |
+
gen_kwargs={"file_path": os.path.join(data_dir, "Janes-Tag.3.0.TEI", "janes-tag.xml")}
|
115 |
+
)
|
116 |
+
]
|
117 |
+
|
118 |
+
def _generate_examples(self, file_path):
|
119 |
+
curr_doc = ET.parse(file_path)
|
120 |
+
root = curr_doc.getroot()
|
121 |
+
NAMESPACE = namespace(root)
|
122 |
+
root = root.find(f"{NAMESPACE}text").find(f"{NAMESPACE}body")
|
123 |
+
|
124 |
+
idx_ex = 0
|
125 |
+
for curr_ex in root.iterfind(f"{NAMESPACE}ab"): # anonymous block
|
126 |
+
curr_id = curr_ex.attrib[f"{XML_NAMESPACE}id"]
|
127 |
+
ex_words, ex_lemmas, ex_msds, ex_nes = [], [], [], []
|
128 |
+
for child_tag in curr_ex:
|
129 |
+
if child_tag.tag not in {f"{NAMESPACE}s", f"{NAMESPACE}c"}:
|
130 |
+
continue
|
131 |
+
|
132 |
+
if child_tag.tag == f"{NAMESPACE}c":
|
133 |
+
continue
|
134 |
+
|
135 |
+
# Iterate over elements of a <s>entence
|
136 |
+
for word_or_seg_tag in child_tag:
|
137 |
+
_words, _lemmas, _msds, _nes = word_info(word_or_seg_tag, NAMESPACE)
|
138 |
+
|
139 |
+
if _words is None:
|
140 |
+
continue
|
141 |
+
|
142 |
+
if _nes is None:
|
143 |
+
_nes = [DEFAULT_NE for _ in range(len(_words))]
|
144 |
+
|
145 |
+
ex_words.extend(_words)
|
146 |
+
ex_lemmas.extend(_lemmas)
|
147 |
+
ex_msds.extend(_msds)
|
148 |
+
ex_nes.extend(_nes)
|
149 |
+
|
150 |
+
yield idx_ex, {
|
151 |
+
"id": curr_id,
|
152 |
+
"words": ex_words,
|
153 |
+
"lemmas": ex_lemmas,
|
154 |
+
"msds": ex_msds,
|
155 |
+
"nes": ex_nes
|
156 |
+
}
|
157 |
+
idx_ex += 1
|