rust-pgn-reader-python-binding 1.0.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/Cargo.lock +3 -3
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/Cargo.toml +1 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/PKG-INFO +1 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/bench.py +1 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/bench_parquet.py +1 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/comment_parsing.rs +13 -3
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/example.py +2 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/lib.rs +16 -5
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/test.py +1 -1
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/.github/workflows/CI.yml +0 -0
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/.gitignore +0 -0
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/README.md +0 -0
- {rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/pyproject.toml +0 -0
|
@@ -212,7 +212,7 @@ dependencies = [
|
|
|
212
212
|
|
|
213
213
|
[[package]]
|
|
214
214
|
name = "rust_pgn_reader_python_binding"
|
|
215
|
-
version = "
|
|
215
|
+
version = "2.0.0"
|
|
216
216
|
dependencies = [
|
|
217
217
|
"nom",
|
|
218
218
|
"pgn-reader",
|
|
@@ -234,9 +234,9 @@ dependencies = [
|
|
|
234
234
|
|
|
235
235
|
[[package]]
|
|
236
236
|
name = "syn"
|
|
237
|
-
version = "2.0.
|
|
237
|
+
version = "2.0.91"
|
|
238
238
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
239
|
-
checksum = "
|
|
239
|
+
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
|
|
240
240
|
dependencies = [
|
|
241
241
|
"proc-macro2",
|
|
242
242
|
"quote",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rust_pgn_reader_python_binding
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -21,7 +21,7 @@ file_path = "lichess_db_standard_rated_2013-07.pgn"
|
|
|
21
21
|
|
|
22
22
|
a = datetime.now()
|
|
23
23
|
for game_pgn in split_pgn(file_path):
|
|
24
|
-
extractor = rust_pgn_reader_python_binding.
|
|
24
|
+
extractor = rust_pgn_reader_python_binding.parse_game(game_pgn)
|
|
25
25
|
moves = extractor.moves
|
|
26
26
|
comments = extractor.comments
|
|
27
27
|
|
{rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/bench_parquet.py
RENAMED
|
@@ -13,7 +13,7 @@ pf = ParquetFile(file_path)
|
|
|
13
13
|
|
|
14
14
|
for df in pf.iter_row_groups():
|
|
15
15
|
for row in df.movetext:
|
|
16
|
-
extractor = rust_pgn_reader_python_binding.
|
|
16
|
+
extractor = rust_pgn_reader_python_binding.parse_game(row)
|
|
17
17
|
moves = extractor.moves
|
|
18
18
|
comments = extractor.comments
|
|
19
19
|
|
{rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/comment_parsing.rs
RENAMED
|
@@ -12,7 +12,7 @@ use nom::{
|
|
|
12
12
|
pub enum CommentContent {
|
|
13
13
|
Text(String),
|
|
14
14
|
Eval(f64),
|
|
15
|
-
ClkTime((u32,
|
|
15
|
+
ClkTime((u32, u8, f64)),
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
pub fn parse_comments(input: &str) -> IResult<&str, Vec<CommentContent>> {
|
|
@@ -133,7 +133,7 @@ mod tests {
|
|
|
133
133
|
vec![
|
|
134
134
|
CommentContent::Eval(123.0),
|
|
135
135
|
CommentContent::Text(" some text ".to_string()),
|
|
136
|
-
CommentContent::ClkTime((12, 34, 56))
|
|
136
|
+
CommentContent::ClkTime((12, 34, 56.0))
|
|
137
137
|
]
|
|
138
138
|
);
|
|
139
139
|
assert_eq!(remaining, "");
|
|
@@ -148,13 +148,23 @@ mod tests {
|
|
|
148
148
|
assert_eq!(
|
|
149
149
|
parsed,
|
|
150
150
|
vec![
|
|
151
|
-
CommentContent::ClkTime((12, 34, 56)),
|
|
151
|
+
CommentContent::ClkTime((12, 34, 56.0)),
|
|
152
152
|
CommentContent::Text(" some text ".to_string())
|
|
153
153
|
]
|
|
154
154
|
);
|
|
155
155
|
assert_eq!(remaining, "");
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
#[test]
|
|
159
|
+
fn test_comment_fractional_sec() {
|
|
160
|
+
let input = "[%clk 12:34:56.0123]";
|
|
161
|
+
let result = parse_comments(input);
|
|
162
|
+
assert!(result.is_ok());
|
|
163
|
+
let (remaining, parsed) = result.unwrap();
|
|
164
|
+
assert_eq!(parsed, vec![CommentContent::ClkTime((12, 34, 56.0123)),]);
|
|
165
|
+
assert_eq!(remaining, "");
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
#[test]
|
|
159
169
|
fn test_tag_parser() {
|
|
160
170
|
let input = "[%eval 123]";
|
{rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/src/example.py
RENAMED
|
@@ -16,10 +16,11 @@ pgn_moves = """
|
|
|
16
16
|
13. b3?? { [%eval -4.14] [%clk 0:00:02] } 13... Nf4? { [%eval -2.73] [%clk 0:00:21] } 0-1
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
|
-
extractor = rust_pgn_reader_python_binding.
|
|
19
|
+
extractor = rust_pgn_reader_python_binding.parse_game(pgn_moves)
|
|
20
20
|
|
|
21
21
|
print(extractor.moves)
|
|
22
22
|
print(extractor.comments)
|
|
23
23
|
print(extractor.valid_moves)
|
|
24
24
|
print(extractor.evals)
|
|
25
25
|
print(extractor.clock_times)
|
|
26
|
+
print(extractor.outcome)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use shakmaty::{uci::UciMove, Chess, Position};
|
|
1
|
+
use shakmaty::{uci::UciMove, Chess, Outcome, Position};
|
|
2
2
|
|
|
3
3
|
use crate::comment_parsing::parse_comments;
|
|
4
4
|
use crate::comment_parsing::CommentContent;
|
|
@@ -24,7 +24,10 @@ struct MoveExtractor {
|
|
|
24
24
|
evals: Vec<f64>,
|
|
25
25
|
|
|
26
26
|
#[pyo3(get)]
|
|
27
|
-
clock_times: Vec<(u32,
|
|
27
|
+
clock_times: Vec<(u32, u8, f64)>,
|
|
28
|
+
|
|
29
|
+
#[pyo3(get)]
|
|
30
|
+
outcome: Option<String>,
|
|
28
31
|
|
|
29
32
|
pos: Chess,
|
|
30
33
|
}
|
|
@@ -40,6 +43,7 @@ impl MoveExtractor {
|
|
|
40
43
|
comments: Vec::with_capacity(100),
|
|
41
44
|
evals: Vec::with_capacity(100),
|
|
42
45
|
clock_times: Vec::with_capacity(100),
|
|
46
|
+
outcome: None,
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}
|
|
@@ -124,14 +128,21 @@ impl Visitor for MoveExtractor {
|
|
|
124
128
|
Skip(true) // stay in the mainline
|
|
125
129
|
}
|
|
126
130
|
|
|
131
|
+
fn outcome(&mut self, _outcome: Option<Outcome>) {
|
|
132
|
+
self.outcome = _outcome.map(|o| match o {
|
|
133
|
+
Outcome::Decisive { winner } => format!("{:?}", winner),
|
|
134
|
+
Outcome::Draw => "Draw".to_string(),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
fn end_game(&mut self) -> Self::Result {
|
|
128
139
|
self.valid_moves
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
|
|
132
|
-
/// Parses PGN
|
|
143
|
+
/// Parses a full PGN game and returns a list of SAN moves and parsed comments
|
|
133
144
|
#[pyfunction]
|
|
134
|
-
fn
|
|
145
|
+
fn parse_game(pgn: &str) -> PyResult<MoveExtractor> {
|
|
135
146
|
let mut reader = BufferedReader::new(Cursor::new(pgn));
|
|
136
147
|
let mut extractor = MoveExtractor::new();
|
|
137
148
|
|
|
@@ -150,6 +161,6 @@ fn parse_moves(pgn: &str) -> PyResult<MoveExtractor> {
|
|
|
150
161
|
/// A Python module implemented in Rust.
|
|
151
162
|
#[pymodule]
|
|
152
163
|
fn rust_pgn_reader_python_binding(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
153
|
-
m.add_function(wrap_pyfunction!(
|
|
164
|
+
m.add_function(wrap_pyfunction!(parse_game, m)?)?;
|
|
154
165
|
Ok(())
|
|
155
166
|
}
|
|
@@ -4,7 +4,7 @@ import rust_pgn_reader_python_binding
|
|
|
4
4
|
|
|
5
5
|
class TestPgnExtraction(unittest.TestCase):
|
|
6
6
|
def run_extractor(self, pgn_string):
|
|
7
|
-
extractor = rust_pgn_reader_python_binding.
|
|
7
|
+
extractor = rust_pgn_reader_python_binding.parse_game(pgn_string)
|
|
8
8
|
return extractor
|
|
9
9
|
|
|
10
10
|
def test_short_pgn(self):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rust_pgn_reader_python_binding-1.0.0 → rust_pgn_reader_python_binding-2.0.0}/pyproject.toml
RENAMED
|
File without changes
|