UTS_Dictionary / UTS_Dictionary.py
rain1024's picture
update
72deff8
raw
history blame contribute delete
No virus
1.58 kB
import os
import re
from itertools import chain
import datasets
_DESCRIPTION = """\
UTSText
"""
_CITATION = """\
"""
_BASE_URL = "https://huggingface.co/datasets/undertheseanlp/UTS_Dictionary/resolve/main/data/"
DATA_FILE = "data.txt"
class UTSDictionaryConfig(datasets.BuilderConfig):
"""BuilderConfig"""
def __init__(self, **kwargs):
super(UTSDictionaryConfig, self).__init__(**kwargs)
class UTSText(datasets.GeneratorBasedBuilder):
"""UTS Word Tokenize datasets"""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
}
),
supervised_keys=None,
homepage=None,
citation=_CITATION
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_file = dl_manager.download(os.path.join(_BASE_URL, DATA_FILE))
splits = [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": data_file}
)
]
return splits
def _generate_examples(self, filepath):
guid = 0
with open(filepath, encoding="utf-8") as f:
for line in f:
if line.strip() != "":
item = {
"text": line.strip()
}
yield guid, item
guid += 1