Datasets:
Matej Klemen commited on
Commit ·
a522dc2
1
Parent(s): 43ed7c5
Fix issue with parsing inconsistently formatted normalized words
Browse files- README.md +2 -2
- janes_tag.py +21 -9
README.md
CHANGED
|
@@ -14,10 +14,10 @@ dataset_info:
|
|
| 14 |
sequence: string
|
| 15 |
splits:
|
| 16 |
- name: train
|
| 17 |
-
num_bytes:
|
| 18 |
num_examples: 2957
|
| 19 |
download_size: 2871765
|
| 20 |
-
dataset_size:
|
| 21 |
task_categories:
|
| 22 |
- token-classification
|
| 23 |
language:
|
|
|
|
| 14 |
sequence: string
|
| 15 |
splits:
|
| 16 |
- name: train
|
| 17 |
+
num_bytes: 2653609
|
| 18 |
num_examples: 2957
|
| 19 |
download_size: 2871765
|
| 20 |
+
dataset_size: 2653609
|
| 21 |
task_categories:
|
| 22 |
- token-classification
|
| 23 |
language:
|
janes_tag.py
CHANGED
|
@@ -46,18 +46,30 @@ def word_info(wordlike_tag, _namespace):
|
|
| 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 |
-
|
| 55 |
-
|
|
|
|
| 56 |
words, lemmas, msds = [], [], []
|
| 57 |
for _child in wordlike_tag:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
return words, lemmas, msds, nes
|
| 63 |
|
|
|
|
| 46 |
|
| 47 |
if wordlike_tag.tag in {f"{_namespace}w", f"{_namespace}pc"}:
|
| 48 |
nes = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
children = list(iter(wordlike_tag))
|
| 51 |
+
if len(children) > 0:
|
| 52 |
+
# If this happens, the word contains nested words indicating its normalized form
|
| 53 |
words, lemmas, msds = [], [], []
|
| 54 |
for _child in wordlike_tag:
|
| 55 |
+
assert _child.tag in {f"{_namespace}w", f"{_namespace}pc"}, _child.tag
|
| 56 |
+
|
| 57 |
+
# Arbitrary words in the text have a normalized form that is formatted inconsistently and so it is
|
| 58 |
+
# unclear how to parse it correctly -> convention: always use information of the normalized words
|
| 59 |
+
if "norm" in _child.attrib:
|
| 60 |
+
words.append(_child.attrib["norm"].strip())
|
| 61 |
+
lemmas.append(_child.attrib["lemma"].strip())
|
| 62 |
+
msds.append(_child.attrib["ana"].strip())
|
| 63 |
+
else:
|
| 64 |
+
# These don't have linguistic annotations ¯\_(ツ)_/¯
|
| 65 |
+
words.append(_child.text.strip())
|
| 66 |
+
lemmas.append(_child.text.strip())
|
| 67 |
+
msds.append("UNK")
|
| 68 |
+
|
| 69 |
+
else:
|
| 70 |
+
words = [wordlike_tag.text.strip()]
|
| 71 |
+
lemmas = [wordlike_tag.attrib["lemma"].strip()]
|
| 72 |
+
msds = [wordlike_tag.attrib["ana"].strip()]
|
| 73 |
|
| 74 |
return words, lemmas, msds, nes
|
| 75 |
|