KeithG33 commited on
Commit
d153237
·
1 Parent(s): 56f9d69

move imports into builder class

Browse files
Files changed (1) hide show
  1. ChessBot-Dataset.py +7 -3
ChessBot-Dataset.py CHANGED
@@ -1,4 +1,3 @@
1
- import glob, os, chess.pgn
2
  from datasets import (
3
  GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
4
  Features, Value, Array2D
@@ -19,21 +18,26 @@ class ChessPGNDataset(GeneratorBasedBuilder):
19
  )
20
 
21
  def _split_generators(self, dl_manager):
 
22
  # data_dir is the root of your dataset repo
23
  data_dir = self.config.data_dir
24
  return [
25
  SplitGenerator(
26
  name=Split.TRAIN,
27
- gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"train","*.pgn"))}
 
28
  ),
29
  SplitGenerator(
30
  name=Split.TEST,
31
- gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"test","*.pgn"))}
 
32
  ),
33
  ]
34
 
35
  def _generate_examples(self, shards):
 
36
  uid = 0
 
37
  for path in sorted(shards):
38
  with open(path, "r") as f:
39
  while (game := chess.pgn.read_game(f)) is not None:
 
 
1
  from datasets import (
2
  GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
3
  Features, Value, Array2D
 
18
  )
19
 
20
  def _split_generators(self, dl_manager):
21
+ import os
22
  # data_dir is the root of your dataset repo
23
  data_dir = self.config.data_dir
24
  return [
25
  SplitGenerator(
26
  name=Split.TRAIN,
27
+ gen_kwargs={"shards": [pgn.path for pgn in os.scandir(os.path.join(data_dir,"train")) if pgn.name.endswith(".pgn")]},
28
+ # gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"train","*.pgn"))}
29
  ),
30
  SplitGenerator(
31
  name=Split.TEST,
32
+ gen_kwargs={"shards": [pgn.path for pgn in os.scandir(os.path.join(data_dir,"test")) if pgn.name.endswith(".pgn")]},
33
+ # gen_kwargs={"shards": glob.glob(os.path.join(data_dir,"test","*.pgn"))}
34
  ),
35
  ]
36
 
37
  def _generate_examples(self, shards):
38
+ import chess.pgn
39
  uid = 0
40
+
41
  for path in sorted(shards):
42
  with open(path, "r") as f:
43
  while (game := chess.pgn.read_game(f)) is not None: