Upload e3c.py
Browse files12345678910111213141516171810 unmodified lines29303132333435363738394041421 unmodified line4445464748495051525354555657585960616263646566676869707172737475767740 unmodified lines11811912012112212312412512612712812913013113213313413513613713813950 unmodified lines19019119219319419519636 unmodified lines233234235236237238239240import osimport datasetsfrom bs4 import ResultSet, BeautifulSoupfrom datasets import DownloadManager_CITATION = """\@report{Magnini2021,author = {Bernardo Magnini and Begoña Altuna and Alberto Lavelli and Manuela Speranzaand Roberto Zanoli and Fondazione Bruno Kessler},keywords = {Clinical data,clinical enti-ties,corpus,multilingual,temporal information},title = {The E3C Project:European Clinical Case Corpus El proyecto E3C: European Clinical Case Corpus},url = {https://uts.nlm.nih.gov/uts/umls/home},year = {2021},}"""10 unmodified linesclass E3CConfig(datasets.BuilderConfig):"""BuilderConfig for SQUAD."""def __init__(self, **kwargs):"""BuilderConfig for SQUAD.Args:**kwargs: keyword arguments forwarded to super."""self.layer = kwargs.pop("layer")super(E3CConfig, self).__init__(**kwargs)1 unmodified lineVERSION = datasets.Version("1.1.0")BUILDER_CONFIGS = [E3CConfig(name="en",version=VERSION,description="this is the split of the layer 1 for English of E3C dataset",layer="1",),E3CConfig(name="es",version=VERSION,description="this is the split of the layer 1 for Spanish of E3C dataset",layer="1",),E3CConfig(name="eu",version=VERSION,description="this is the split of the layer 1 for Basque of E3C dataset",layer="1",),E3CConfig(name="fr",version=VERSION,description="this is the split of the layer 1 for French of E3C dataset",layer="1",),E3CConfig(name="it",version=VERSION,description="this is the split of the layer 1 for Italian of E3C dataset",layer="1",),]40 unmodified lines"""url = _URLdata_dir = dl_manager.download_and_extract(url)language = {"en": "English","es": "Spanish","eu": "Basque","fr": "French","it": "Italian",}[self.config.name]return [datasets.SplitGenerator(name=self.config.name,gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation",language,f"layer{self.config.layer}",),},),50 unmodified lines"TOKENS": self.get_annotations(soup.find_all("type4:Token"), text),}def _generate_examples(self, filepath) -> tuple[str, dict]:"""Yields examples as (key, example) tuples.Args:filepath: The path to the folder containing the files to parse.36 unmodified lineslabels[idx_token] = f"{entity_type}"else:labels[idx_token] = f"{entity_type}"guid += 1yield guid, {"tokens": list(map(lambda tokens: tokens[2], filtered_tokens)),"ner_tags": labels,}1234567891011121314151617181910 unmodified lines303132333435363738394041421 unmodified line44454647484950515240 unmodified lines9394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620750 unmodified lines25825926026126226326436 unmodified lines301302303304305306307308import osfrom typing import Iteratorimport datasetsfrom bs4 import BeautifulSoup, ResultSetfrom datasets import DownloadManager_CITATION = """\@report{Magnini2021,author = {Bernardo Magnini and Begoña Altuna and Alberto Lavelli and Manuela Speranzaand Roberto Zanoli and Fondazione Bruno Kessler},keywords = {Clinical data,clinical enti-ties,corpus,multilingual,temporal information},title = {The E3C Project:European Clinical Case Corpus El proyecto E3C: European Clinical Case Corpus},url = {https://uts.nlm.nih.gov/uts/umls/home},year = {2021},}"""10 unmodified linesclass E3CConfig(datasets.BuilderConfig):"""BuilderConfig for NCBIDisease"""def __init__(self, **kwargs):"""BuilderConfig for NCBIDisease.Args:**kwargs: keyword arguments forwarded to super."""super(E3CConfig, self).__init__(**kwargs)1 unmodified lineVERSION = datasets.Version("1.1.0")BUILDER_CONFIGS = [E3CConfig(name="e3c",version=VERSION,description="this is the split of the layer 1 for English of E3C dataset",),]40 unmodified lines"""url = _URLdata_dir = dl_manager.download_and_extract(url)return [datasets.SplitGenerator(name="en.layer1",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","English","layer1",),},),datasets.SplitGenerator(name="en.layer2",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","English","layer2",),},),datasets.SplitGenerator(name="es.layer1",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Spanish","layer1",),},),datasets.SplitGenerator(name="es.layer2",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Spanish","layer2",),},),datasets.SplitGenerator(name="eu.layer1",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Basque","layer1",),},),datasets.SplitGenerator(name="eu.layer2",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Basque","layer2",),},),datasets.SplitGenerator(name="fr.layer1",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","French","layer1",),},),datasets.SplitGenerator(name="fr.layer2",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","French","layer2",),},),datasets.SplitGenerator(name="it.layer1",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Italian","layer1",),},),datasets.SplitGenerator(name="it.layer2",gen_kwargs={"filepath": os.path.join(data_dir,"E3C-Corpus-2.0.0/data_annotation","Italian","layer2",),},),50 unmodified lines"TOKENS": self.get_annotations(soup.find_all("type4:Token"), text),}def _generate_examples(self, filepath) -> Iterator:"""Yields examples as (key, example) tuples.Args:filepath: The path to the folder containing the files to parse.36 unmodified lineslabels[idx_token] = f"{entity_type}"else:labels[idx_token] = f"{entity_type}"yield guid, {"tokens": list(map(lambda tokens: tokens[2], filtered_tokens)),"ner_tags": labels,}guid += 1
e3c.py+117-49