Chesscorner commited on
Commit
a15365e
·
verified ·
1 Parent(s): b2620a8

Update chess_ground-targz.py

Browse files
Files changed (1) hide show
  1. chess_ground-targz.py +20 -3
chess_ground-targz.py CHANGED
@@ -88,11 +88,12 @@ class ChessImageTextDataset(datasets.GeneratorBasedBuilder):
88
  # Clean the text to keep only chess notation
89
  cleaned_texts = [self._extract_chess_notation(text) for text in texts]
90
 
91
- # Join the cleaned notations related to the same image
92
- combined_text = " ".join(cleaned_texts)
 
93
  yield idx, {
94
  "image": image_file,
95
- "text": combined_text, # Link all related cleaned notations together
96
  }
97
  idx += 1
98
  else:
@@ -126,3 +127,19 @@ class ChessImageTextDataset(datasets.GeneratorBasedBuilder):
126
  # Assuming the chess notation comes after the filename and space, e.g., '001_0_30_white.png Rxc6'
127
  notation = text.split(" ", 1)[-1] # Extract everything after the first space
128
  return notation.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # Clean the text to keep only chess notation
89
  cleaned_texts = [self._extract_chess_notation(text) for text in texts]
90
 
91
+ # Add numbering to the moves in pairs
92
+ numbered_text = self._add_numeration(cleaned_texts)
93
+
94
  yield idx, {
95
  "image": image_file,
96
+ "text": numbered_text, # Link all related cleaned notations together with numeration
97
  }
98
  idx += 1
99
  else:
 
127
  # Assuming the chess notation comes after the filename and space, e.g., '001_0_30_white.png Rxc6'
128
  notation = text.split(" ", 1)[-1] # Extract everything after the first space
129
  return notation.strip()
130
+
131
+ def _add_numeration(self, notations):
132
+ """Adds numeration to chess notations, pairing moves and numbering them."""
133
+ numbered_text = []
134
+ counter = 1
135
+
136
+ # Pair every two moves and add numeration
137
+ for i in range(0, len(notations), 2):
138
+ # Grab two moves if available, otherwise just take the remaining one
139
+ move_pair = notations[i:i+2]
140
+ numbered_move = f"{counter}. " + " ".join(move_pair)
141
+ numbered_text.append(numbered_move)
142
+ counter += 1
143
+
144
+ # Join all numbered moves into a single text
145
+ return " ".join(numbered_text)