Datasets:
Matej Klemen commited on
Commit ·
04a1a15
1
Parent(s): 86dabe7
Group together metaphor annotations for phrases
Browse files- dataset_infos.json +1 -1
- vuamc.py +36 -7
dataset_infos.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"default": {"description": "The resource contains a selection of excerpts from BNC-Baby files that have been annotated for metaphor. \nThere are four registers, each comprising about 50,000 words: academic texts, news texts, fiction, and conversations. \nWords have been separately labelled as participating in multi-word expressions (about 1.5%) or as discarded for \nmetaphor analysis (0.02%). Main categories include words that are related to metaphor (MRW), words that signal \nmetaphor (MFlag), and words that are not related to metaphor. For metaphor-related words, subdivisions have been made \nbetween clear cases of metaphor versus borderline cases (WIDLII, When In Doubt, Leave It In). Another parameter of \nmetaphor-related words makes a distinction between direct metaphor, indirect metaphor, and implicit metaphor.\n", "citation": "@book{steen2010method,\n title={A method for linguistic metaphor identification: From MIP to MIPVU},\n author={Steen, Gerard and Dorst, Lettie and Herrmann, J. and Kaal, Anna and Krennmayr, Tina and Pasma, Trijntje},\n volume={14},\n year={2010},\n publisher={John Benjamins Publishing}\n}\n", "homepage": "https://hdl.handle.net/20.500.12024/2541", "license": "Available for non-commercial use on condition that the terms of the BNC Licence are observed and that this header is included in its entirety with any copy distributed.", "features": {"document_name": {"dtype": "string", "id": null, "_type": "Value"}, "words": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "pos_tags": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "met_type": [{"type": {"dtype": "string", "id": null, "_type": "Value"}, "word_indices": {"feature": {"dtype": "uint32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}], "meta": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "vuamc", "config_name": "default", "version": {"version_str": "1.0.
|
|
|
|
| 1 |
+
{"default": {"description": "The resource contains a selection of excerpts from BNC-Baby files that have been annotated for metaphor. \nThere are four registers, each comprising about 50,000 words: academic texts, news texts, fiction, and conversations. \nWords have been separately labelled as participating in multi-word expressions (about 1.5%) or as discarded for \nmetaphor analysis (0.02%). Main categories include words that are related to metaphor (MRW), words that signal \nmetaphor (MFlag), and words that are not related to metaphor. For metaphor-related words, subdivisions have been made \nbetween clear cases of metaphor versus borderline cases (WIDLII, When In Doubt, Leave It In). Another parameter of \nmetaphor-related words makes a distinction between direct metaphor, indirect metaphor, and implicit metaphor.\n", "citation": "@book{steen2010method,\n title={A method for linguistic metaphor identification: From MIP to MIPVU},\n author={Steen, Gerard and Dorst, Lettie and Herrmann, J. and Kaal, Anna and Krennmayr, Tina and Pasma, Trijntje},\n volume={14},\n year={2010},\n publisher={John Benjamins Publishing}\n}\n", "homepage": "https://hdl.handle.net/20.500.12024/2541", "license": "Available for non-commercial use on condition that the terms of the BNC Licence are observed and that this header is included in its entirety with any copy distributed.", "features": {"document_name": {"dtype": "string", "id": null, "_type": "Value"}, "words": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "pos_tags": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "met_type": [{"type": {"dtype": "string", "id": null, "_type": "Value"}, "word_indices": {"feature": {"dtype": "uint32", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}], "meta": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "vuamc", "config_name": "default", "version": {"version_str": "1.0.1", "description": null, "major": 1, "minor": 0, "patch": 1}, "splits": {"train": {"name": "train", "num_bytes": 6487858, "num_examples": 16740, "dataset_name": "vuamc"}}, "download_checksums": {"https://ota.bodleian.ox.ac.uk/repository/xmlui/bitstream/handle/20.500.12024/2541/VUAMC.xml": {"num_bytes": 16820946, "checksum": "0ac1a77cc1879aa0c87e2879481d0e1e3f28e36b1701893c096a33ff11aa6e0d"}}, "download_size": 16820946, "post_processing_size": null, "dataset_size": 6487858, "size_in_bytes": 23308804}}
|
vuamc.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
""" English metaphor-annotated corpus. """
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
import datasets
|
| 6 |
import logging
|
|
@@ -90,7 +91,15 @@ def resolve_recursively(el, ns):
|
|
| 90 |
words.append(_w_text)
|
| 91 |
pos_tags.append(el.attrib["type"])
|
| 92 |
meta_tags.append(NA_STR)
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
idx_word += 1
|
| 95 |
|
| 96 |
if not parse_tail:
|
|
@@ -198,23 +207,43 @@ def resolve_recursively(el, ns):
|
|
| 198 |
return words, pos_tags, met_type, meta_tags
|
| 199 |
|
| 200 |
|
| 201 |
-
def parse_sent(sent_el, ns) -> Tuple[List[str], List[str], List[
|
| 202 |
all_words, all_pos_tags, all_met_types, all_metas = [], [], [], []
|
| 203 |
for child_el in sent_el:
|
| 204 |
word, pos, mtype, meta = resolve_recursively(child_el, ns=ns)
|
| 205 |
# Need to remap local (index inside the word group) `word_indices` to global (index inside the sentence)
|
| 206 |
if len(mtype) > 0:
|
| 207 |
base = len(all_words)
|
| 208 |
-
|
| 209 |
-
"
|
| 210 |
-
"word_indices": list(map(lambda _i: base + _i, met_info["word_indices"]))
|
| 211 |
-
}, mtype))
|
| 212 |
|
| 213 |
all_words.extend(word)
|
| 214 |
all_pos_tags.extend(pos)
|
| 215 |
all_met_types.extend(mtype)
|
| 216 |
all_metas.extend(meta)
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
return all_words, all_pos_tags, all_met_types, all_metas
|
| 219 |
|
| 220 |
|
|
@@ -268,7 +297,7 @@ def parse_text_body(body_el, ns):
|
|
| 268 |
class VUAMC(datasets.GeneratorBasedBuilder):
|
| 269 |
"""English metaphor-annotated corpus. """
|
| 270 |
|
| 271 |
-
VERSION = datasets.Version("1.0.
|
| 272 |
|
| 273 |
def _info(self):
|
| 274 |
features = datasets.Features(
|
|
|
|
| 1 |
""" English metaphor-annotated corpus. """
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
from copy import deepcopy
|
| 5 |
|
| 6 |
import datasets
|
| 7 |
import logging
|
|
|
|
| 91 |
words.append(_w_text)
|
| 92 |
pos_tags.append(el.attrib["type"])
|
| 93 |
meta_tags.append(NA_STR)
|
| 94 |
+
|
| 95 |
+
met_dict = {"type": curr_met_type, "word_indices": [idx_word]}
|
| 96 |
+
# Multi-word metaphors are annotated with xml:id="..." or corresp="..."
|
| 97 |
+
if f"{XML_NAMESPACE}id" in met_el.attrib:
|
| 98 |
+
met_dict["id"] = met_el.attrib[f"{XML_NAMESPACE}id"]
|
| 99 |
+
elif "corresp" in met_el.attrib:
|
| 100 |
+
met_dict["id"] = met_el.attrib["corresp"][1:] # remove the "#" in front
|
| 101 |
+
|
| 102 |
+
met_type.append(met_dict)
|
| 103 |
idx_word += 1
|
| 104 |
|
| 105 |
if not parse_tail:
|
|
|
|
| 207 |
return words, pos_tags, met_type, meta_tags
|
| 208 |
|
| 209 |
|
| 210 |
+
def parse_sent(sent_el, ns) -> Tuple[List[str], List[str], List[Dict], List[str]]:
|
| 211 |
all_words, all_pos_tags, all_met_types, all_metas = [], [], [], []
|
| 212 |
for child_el in sent_el:
|
| 213 |
word, pos, mtype, meta = resolve_recursively(child_el, ns=ns)
|
| 214 |
# Need to remap local (index inside the word group) `word_indices` to global (index inside the sentence)
|
| 215 |
if len(mtype) > 0:
|
| 216 |
base = len(all_words)
|
| 217 |
+
for idx_met, met_info in enumerate(mtype):
|
| 218 |
+
mtype[idx_met]["word_indices"] = list(map(lambda _i: base + _i, met_info["word_indices"]))
|
|
|
|
|
|
|
| 219 |
|
| 220 |
all_words.extend(word)
|
| 221 |
all_pos_tags.extend(pos)
|
| 222 |
all_met_types.extend(mtype)
|
| 223 |
all_metas.extend(meta)
|
| 224 |
|
| 225 |
+
# Check if any of the independent metaphor annotations belong to the same word group (e.g., "taking" and "over")
|
| 226 |
+
if len(all_met_types) > 0:
|
| 227 |
+
grouped_met_type = {}
|
| 228 |
+
for met_info in all_met_types:
|
| 229 |
+
curr_id = met_info.get("id", f"met{len(grouped_met_type)}")
|
| 230 |
+
|
| 231 |
+
if curr_id in grouped_met_type:
|
| 232 |
+
existing_data = grouped_met_type[curr_id]
|
| 233 |
+
existing_data["word_indices"].extend(met_info["word_indices"])
|
| 234 |
+
else:
|
| 235 |
+
existing_data = deepcopy(met_info)
|
| 236 |
+
|
| 237 |
+
grouped_met_type[curr_id] = existing_data
|
| 238 |
+
|
| 239 |
+
new_met_types = []
|
| 240 |
+
for _, met_info in grouped_met_type.items():
|
| 241 |
+
if "id" in met_info:
|
| 242 |
+
del met_info["id"]
|
| 243 |
+
new_met_types.append(met_info)
|
| 244 |
+
|
| 245 |
+
all_met_types = new_met_types
|
| 246 |
+
|
| 247 |
return all_words, all_pos_tags, all_met_types, all_metas
|
| 248 |
|
| 249 |
|
|
|
|
| 297 |
class VUAMC(datasets.GeneratorBasedBuilder):
|
| 298 |
"""English metaphor-annotated corpus. """
|
| 299 |
|
| 300 |
+
VERSION = datasets.Version("1.0.1")
|
| 301 |
|
| 302 |
def _info(self):
|
| 303 |
features = datasets.Features(
|