fixpath
Browse files- 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 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
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()
|