"""A dataset script that will hit Snowflake DB and return the results.""" import snowflake.connector as connector import datasets # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @InProceedings{huggingface:dataset, title = {A great new dataset}, author={huggingface, Inc. }, year={2020} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ This new dataset is designed to solve this great NLP task and is crafted with a lot of care. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "" class LoginConfig(datasets.BuilderConfig): """BuilderConfig for Login.""" def __init__(self, username, password, **kwargs): """BuilderConfig for SuperGLUE. Args: username: `string`, User name in Snowflake password: `string`, Snowflake password. **kwargs: keyword arguments forwarded to super. """ super(LoginConfig, self).__init__(version=datasets.Version("1.0.2"), **kwargs) self.username = username self.password = password class NewDataset(datasets.GeneratorBasedBuilder): """TODO: Short description of my dataset.""" BUILDER_CONFIG_CLASS = LoginConfig def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "text": datasets.Value("string"), "label": datasets.ClassLabel(names=['sadness', 'joy', 'love', 'anger', 'fear', 'surprise']), } ), homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): user = self.config.username password = self.config.password conn = connector.connect( user=user, password=password, account='VUA92284', warehouse='RAJIV', database='HUGGINGFACE', schema='PUBLIC', role = 'RAJIV' ) curr = conn.cursor() sql = "select * from EMOTION" curr = curr.execute(sql) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"cursor": curr}, ) ] def _generate_examples(self, cursor): for i, ex in enumerate(cursor): yield str(i), { "text": ex[0], "label": ex[1], } # Probably not necessary but just in case...we close the connection which we can find within the cursor object cursor.connection.close()