|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .annotations_parser import load_yedda_annotations |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@misc{tajik-text-segmentation, |
|
title = {Tajik text segmentation dataset}, |
|
author={Sobir Bobiev}, |
|
year={2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This dataset contains tajik texts with sentences annotated. Can be useful for sentence boundary detection, segmenting text and many NLP tasks. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
class TajikTextSegmentation(datasets.GeneratorBasedBuilder): |
|
"""A dataset of sentence-wise text segmentation in Tajik language.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"file": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"annotated_text": datasets.Value("string"), |
|
"number_of_labels": datasets.Value("int32"), |
|
"positions": [[datasets.Value("int32")]], |
|
"labels": [datasets.Value("string")] |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"directory_path": './annotations', |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, directory_path): |
|
"""This function returns the examples.""" |
|
|
|
annotations = load_yedda_annotations(directory_path) |
|
|
|
for idx, file_annotation in enumerate(annotations): |
|
file = file_annotation['file'] |
|
text = file_annotation['text'] |
|
annotated_text = file_annotation['annotated_text'] |
|
number_of_labels = len(file_annotation['labels']) |
|
|
|
yield idx, { |
|
"file": file, |
|
"text": text, |
|
"annotated_text": annotated_text, |
|
"positions": file_annotation['positions'], |
|
"labels": file_annotation['labels'], |
|
"number_of_labels": number_of_labels, |
|
} |
|
|