File size: 2,857 Bytes
8842b31
 
9d93156
8842b31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fe9fc4
 
 
 
 
 
 
 
 
 
 
 
8842b31
 
 
 
3fe9fc4
 
8842b31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fe9fc4
 
8842b31
3fe9fc4
 
8842b31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""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()