|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition""" |
|
|
|
import re |
|
|
|
import datasets |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@Article{SETH2016, |
|
Title= {SETH detects and normalizes genetic variants in text.}, |
|
Author= {Thomas, Philippe and Rockt{\"{a}}schel, Tim and Hakenberg, J{\"{o}}rg and Lichtblau, Yvonne and Leser, Ulf}, |
|
Journal= {Bioinformatics}, |
|
Year= {2016}, |
|
Month= {Jun}, |
|
Doi= {10.1093/bioinformatics/btw234}, |
|
Language = {eng}, |
|
Medline-pst = {aheadofprint}, |
|
Pmid = {27256315}, |
|
Url = {http://dx.doi.org/10.1093/bioinformatics/btw234} Titel anhand dieser DOI in Citavi-Projekt übernehmen |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This Dataset is used to for the Advanced Machine Learning and XAI course of the DHBW CAS in Heilbronn |
|
""" |
|
|
|
|
|
|
|
class SethConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for Seth Dataset""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for Seth. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(SethConfig, self).__init__(**kwargs) |
|
|
|
|
|
class Seth(datasets.GeneratorBasedBuilder): |
|
"""Seth dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
SethConfig(name="Seth", version=datasets.Version("1.0.0"), description="Seth dataset"), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"tokens": datasets.Sequence(datasets.Value("string")), |
|
"labels": datasets.Sequence( |
|
datasets.features.ClassLabel( |
|
names=[ |
|
"O", |
|
"B-Gene", |
|
"B-SNP", |
|
"I-SNP", |
|
"I-Gene", |
|
"B-RS", |
|
"I-RS" |
|
] |
|
) |
|
) |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="https://rockt.github.io/SETH/", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
downloaded_files = dl_manager.download({ |
|
"train": "https://raw.githubusercontent.com/Erechtheus/mutationCorpora/master/corpora/IOB/SETH-train.iob", |
|
"test": "https://raw.githubusercontent.com/Erechtheus/mutationCorpora/master/corpora/IOB/SETH-test.iob", |
|
}) |
|
|
|
|
|
logger.info(f"Train file downloaded to: {downloaded_files['train']}") |
|
logger.info(f"Test file downloaded to: {downloaded_files['test']}") |
|
|
|
|
|
with open(downloaded_files["train"], 'r') as train_file: |
|
logger.info(f"First few lines of train file: {train_file.readlines()[:5]}") |
|
with open(downloaded_files["test"], 'r') as test_file: |
|
logger.info(f"First few lines of test file: {test_file.readlines()[:5]}") |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
logger.info("⏳ Generating examples from = %s", filepath) |
|
with open(filepath, encoding="utf-8") as f: |
|
guid = 0 |
|
document = {"id":None, |
|
"tokens":[], |
|
"labels":[] |
|
} |
|
documents = [] |
|
pattern = r"#\d+" |
|
for idx, line in enumerate(f): |
|
match = re.match(pattern, line) |
|
|
|
if idx == 0: |
|
continue |
|
|
|
if match: |
|
if document["id"] != None: |
|
|
|
documents.append(document) |
|
yield guid,document |
|
guid+=1 |
|
document = {"id":int(line[1:]), |
|
"tokens":[], |
|
"labels":[] |
|
} |
|
else: |
|
|
|
document = {"id":int(line[1:]), |
|
"tokens":[], |
|
"labels":[] |
|
} |
|
|
|
elif len(line.split(",")) >2: |
|
|
|
if(line.split(",")[0] == "" and line.split(",")[1]==""): |
|
document["tokens"].append(",") |
|
document["labels"].append(line.split(",")[2].split("\n")[0]) |
|
|
|
else: |
|
document["tokens"].append(",".join(line.split(",")[0:-1])) |
|
document["labels"].append(line.split(",")[-1].split("\n")[0]) |
|
|
|
else: |
|
word_tag = line.split(",") |
|
|
|
if word_tag[0] == " " and word_tag[1] == " \n": |
|
continue |
|
document["tokens"].append(word_tag[0]) |
|
document["labels"].append(word_tag[1].split("\n")[0]) |
|
documents.append(document) |
|
yield guid,document |