KeithG33 commited on
Commit
7a57da1
·
1 Parent(s): 907747c
Files changed (1) hide show
  1. ChessBot-Dataset.py +14 -7
ChessBot-Dataset.py CHANGED
@@ -24,12 +24,19 @@ class ChessPGNDataset(GeneratorBasedBuilder):
24
  )
25
 
26
  def _split_generators(self, dl_manager: DownloadManager):
27
- from pathlib import Path
28
-
29
- repo_root = Path(__file__).parent
30
-
31
- train_shards = sorted((repo_root/ 'train').glob("*.pgn"))
32
- test_shards = sorted((repo_root/ 'test').glob("*.pgn"))
 
 
 
 
 
 
 
33
  train_paths = dl_manager.download([str(p) for p in train_shards])
34
  test_paths = dl_manager.download([str(p) for p in test_shards])
35
 
@@ -47,7 +54,7 @@ class ChessPGNDataset(GeneratorBasedBuilder):
47
  import chess.pgn
48
  uid = 0
49
 
50
- for path in sorted(shards):
51
  with open(path, "r") as f:
52
  while (game := chess.pgn.read_game(f)) is not None:
53
  board = game.board()
 
24
  )
25
 
26
  def _split_generators(self, dl_manager: DownloadManager):
27
+ from pathlib import Path, os
28
+
29
+ if not self.config.data_dir:
30
+ repo_root = Path(__file__).parent
31
+ else:
32
+ repo_root = Path(self.config.data_dir)
33
+
34
+ # Get files in the train and test directories
35
+ train_shards = [repo_root / 'train' / f for f in os.listdir(repo_root / 'train')]
36
+ test_shards = [repo_root / 'test' / f for f in os.listdir(repo_root / 'test')]
37
+
38
+ train_shards = sorted((repo_root / 'train').glob("*.pgn"))
39
+ test_shards = sorted((repo_root / 'test').glob("*.pgn"))
40
  train_paths = dl_manager.download([str(p) for p in train_shards])
41
  test_paths = dl_manager.download([str(p) for p in test_shards])
42
 
 
54
  import chess.pgn
55
  uid = 0
56
 
57
+ for path in shards:
58
  with open(path, "r") as f:
59
  while (game := chess.pgn.read_game(f)) is not None:
60
  board = game.board()