yanyc commited on
Commit
dffa9b9
·
1 Parent(s): dc61339

Update SciGraph.py

Browse files
Files changed (1) hide show
  1. SciGraph.py +18 -5
SciGraph.py CHANGED
@@ -33,6 +33,12 @@ _HOMEPAGE = ""
33
  # The license information was obtained from https://github.com/boudinfl/ake-datasets as the dataset shared over here is taken from here
34
  _LICENSE = ""
35
 
 
 
 
 
 
 
36
  # TODO: Add link to the official dataset URLs here
37
 
38
 
@@ -84,6 +90,7 @@ class SciGraph(datasets.GeneratorBasedBuilder):
84
  )
85
 
86
  def _split_generators(self, dl_manager):
 
87
 
88
  return [
89
  datasets.SplitGenerator(
@@ -91,23 +98,29 @@ class SciGraph(datasets.GeneratorBasedBuilder):
91
  # These kwargs will be passed to _generate_examples
92
  gen_kwargs={
93
  "split": "train",
 
 
 
94
  },
95
  ),
96
  datasets.SplitGenerator(
97
  name=datasets.Split.TEST,
98
  # These kwargs will be passed to _generate_examples
99
  gen_kwargs={
100
- "split": "test"
 
 
 
101
  },
102
  )
103
  ]
104
 
105
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
106
- def _generate_examples(self, split):
107
  if self.config.name == 'function':
108
- with open('class.json', 'r') as f:
109
  functions = list(json.load(f).keys())
110
- data = pd.read_json('assign.json')
111
 
112
  if split == 'train':
113
  data = data.loc[data[functions].sum(axis=1) == 1]
@@ -130,7 +143,7 @@ class SciGraph(datasets.GeneratorBasedBuilder):
130
  }
131
 
132
  if self.config.name == 'topic':
133
- data = pd.read_json('paper_new.json')
134
  data = data.replace(to_replace=r'^\s*$', value=np.nan, regex=True).dropna(subset=['keywords'], axis=0)
135
 
136
  train_data, test_data = train_test_split(data, test_size=0.1, random_state=42)
 
33
  # The license information was obtained from https://github.com/boudinfl/ake-datasets as the dataset shared over here is taken from here
34
  _LICENSE = ""
35
 
36
+ _URLS = {
37
+ 'classes': 'class.json',
38
+ 'function': 'assign.jsonl',
39
+ 'topic': 'paper_new.jsonl'
40
+ }
41
+
42
  # TODO: Add link to the official dataset URLs here
43
 
44
 
 
90
  )
91
 
92
  def _split_generators(self, dl_manager):
93
+ data_dir = dl_manager.download_and_extract(_URLS)
94
 
95
  return [
96
  datasets.SplitGenerator(
 
98
  # These kwargs will be passed to _generate_examples
99
  gen_kwargs={
100
  "split": "train",
101
+ "classes": data_dir['classes'],
102
+ "function": data_dir['function'],
103
+ "topic": data_dir['topic']
104
  },
105
  ),
106
  datasets.SplitGenerator(
107
  name=datasets.Split.TEST,
108
  # These kwargs will be passed to _generate_examples
109
  gen_kwargs={
110
+ "split": "test",
111
+ "classes": data_dir['classes'],
112
+ "function": data_dir['function'],
113
+ "topic": data_dir['topic']
114
  },
115
  )
116
  ]
117
 
118
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
119
+ def _generate_examples(self, split, classes, function, topic):
120
  if self.config.name == 'function':
121
+ with open(classes, 'r') as f:
122
  functions = list(json.load(f).keys())
123
+ data = pd.read_json(function)
124
 
125
  if split == 'train':
126
  data = data.loc[data[functions].sum(axis=1) == 1]
 
143
  }
144
 
145
  if self.config.name == 'topic':
146
+ data = pd.read_json(topic)
147
  data = data.replace(to_replace=r'^\s*$', value=np.nan, regex=True).dropna(subset=['keywords'], axis=0)
148
 
149
  train_data, test_data = train_test_split(data, test_size=0.1, random_state=42)