evaluatio 0.1.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.
- evaluatio-0.1.0/Cargo.lock +236 -0
- evaluatio-0.1.0/Cargo.toml +3 -0
- evaluatio-0.1.0/PKG-INFO +42 -0
- evaluatio-0.1.0/README.md +27 -0
- evaluatio-0.1.0/evaluatio-bindings/.gitignore +72 -0
- evaluatio-0.1.0/evaluatio-bindings/Cargo.toml +27 -0
- evaluatio-0.1.0/evaluatio-bindings/README.md +5 -0
- evaluatio-0.1.0/evaluatio-bindings/src/base.rs +104 -0
- evaluatio-0.1.0/evaluatio-bindings/src/lib.rs +36 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/alignment.rs +16 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/cer.rs +32 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/mod.rs +5 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/pier.rs +42 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/uer.rs +46 -0
- evaluatio-0.1.0/evaluatio-bindings/src/metrics/wer.rs +32 -0
- evaluatio-0.1.0/evaluatio-core/.gitignore +1 -0
- evaluatio-0.1.0/evaluatio-core/Cargo.toml +12 -0
- evaluatio-0.1.0/evaluatio-core/README.md +5 -0
- evaluatio-0.1.0/evaluatio-core/src/lib.rs +1 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/alignment.rs +95 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/cer.rs +35 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/lcs.rs +24 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/mod.rs +6 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/pier.rs +96 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/uer.rs +108 -0
- evaluatio-0.1.0/evaluatio-core/src/metrics/wer.rs +34 -0
- evaluatio-0.1.0/pyproject.toml +27 -0
- evaluatio-0.1.0/python-src/evaluatio/_bindings.pyi +54 -0
- evaluatio-0.1.0/python-src/evaluatio/metrics/cer.py +43 -0
- evaluatio-0.1.0/python-src/evaluatio/metrics/pier.py +19 -0
- evaluatio-0.1.0/python-src/evaluatio/metrics/uer.py +32 -0
- evaluatio-0.1.0/python-src/evaluatio/metrics/wer.py +42 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cc"
|
|
13
|
+
version = "1.2.50"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "9f50d563227a1c37cc0a263f64eca3334388c01c5e4c4861a9def205c614383c"
|
|
16
|
+
dependencies = [
|
|
17
|
+
"find-msvc-tools",
|
|
18
|
+
"shlex",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[[package]]
|
|
22
|
+
name = "cfg-if"
|
|
23
|
+
version = "1.0.4"
|
|
24
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
25
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
26
|
+
|
|
27
|
+
[[package]]
|
|
28
|
+
name = "either"
|
|
29
|
+
version = "1.15.0"
|
|
30
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
31
|
+
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
|
32
|
+
|
|
33
|
+
[[package]]
|
|
34
|
+
name = "evaluatio-bindings"
|
|
35
|
+
version = "0.1.0"
|
|
36
|
+
dependencies = [
|
|
37
|
+
"evaluatio-core",
|
|
38
|
+
"pyo3",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "evaluatio-core"
|
|
43
|
+
version = "0.1.0"
|
|
44
|
+
dependencies = [
|
|
45
|
+
"itertools",
|
|
46
|
+
"pyo3",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[[package]]
|
|
50
|
+
name = "find-msvc-tools"
|
|
51
|
+
version = "0.1.5"
|
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
53
|
+
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
|
|
54
|
+
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "heck"
|
|
57
|
+
version = "0.5.0"
|
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
59
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
60
|
+
|
|
61
|
+
[[package]]
|
|
62
|
+
name = "indoc"
|
|
63
|
+
version = "2.0.7"
|
|
64
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"rustversion",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
[[package]]
|
|
71
|
+
name = "itertools"
|
|
72
|
+
version = "0.14.0"
|
|
73
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
+
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
|
75
|
+
dependencies = [
|
|
76
|
+
"either",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[[package]]
|
|
80
|
+
name = "libc"
|
|
81
|
+
version = "0.2.182"
|
|
82
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
83
|
+
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "memoffset"
|
|
87
|
+
version = "0.9.1"
|
|
88
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
90
|
+
dependencies = [
|
|
91
|
+
"autocfg",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[[package]]
|
|
95
|
+
name = "once_cell"
|
|
96
|
+
version = "1.21.3"
|
|
97
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
98
|
+
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
99
|
+
|
|
100
|
+
[[package]]
|
|
101
|
+
name = "portable-atomic"
|
|
102
|
+
version = "1.13.1"
|
|
103
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
104
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
105
|
+
|
|
106
|
+
[[package]]
|
|
107
|
+
name = "proc-macro2"
|
|
108
|
+
version = "1.0.106"
|
|
109
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
110
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
111
|
+
dependencies = [
|
|
112
|
+
"unicode-ident",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
[[package]]
|
|
116
|
+
name = "pyo3"
|
|
117
|
+
version = "0.23.5"
|
|
118
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
119
|
+
checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
|
|
120
|
+
dependencies = [
|
|
121
|
+
"cfg-if",
|
|
122
|
+
"indoc",
|
|
123
|
+
"libc",
|
|
124
|
+
"memoffset",
|
|
125
|
+
"once_cell",
|
|
126
|
+
"portable-atomic",
|
|
127
|
+
"pyo3-build-config",
|
|
128
|
+
"pyo3-ffi",
|
|
129
|
+
"pyo3-macros",
|
|
130
|
+
"unindent",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
[[package]]
|
|
134
|
+
name = "pyo3-build-config"
|
|
135
|
+
version = "0.23.5"
|
|
136
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
137
|
+
checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
|
|
138
|
+
dependencies = [
|
|
139
|
+
"once_cell",
|
|
140
|
+
"python3-dll-a",
|
|
141
|
+
"target-lexicon",
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
[[package]]
|
|
145
|
+
name = "pyo3-ffi"
|
|
146
|
+
version = "0.23.5"
|
|
147
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
148
|
+
checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
|
|
149
|
+
dependencies = [
|
|
150
|
+
"libc",
|
|
151
|
+
"pyo3-build-config",
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
[[package]]
|
|
155
|
+
name = "pyo3-macros"
|
|
156
|
+
version = "0.23.5"
|
|
157
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
158
|
+
checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
|
|
159
|
+
dependencies = [
|
|
160
|
+
"proc-macro2",
|
|
161
|
+
"pyo3-macros-backend",
|
|
162
|
+
"quote",
|
|
163
|
+
"syn",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
[[package]]
|
|
167
|
+
name = "pyo3-macros-backend"
|
|
168
|
+
version = "0.23.5"
|
|
169
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
170
|
+
checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
|
|
171
|
+
dependencies = [
|
|
172
|
+
"heck",
|
|
173
|
+
"proc-macro2",
|
|
174
|
+
"pyo3-build-config",
|
|
175
|
+
"quote",
|
|
176
|
+
"syn",
|
|
177
|
+
]
|
|
178
|
+
|
|
179
|
+
[[package]]
|
|
180
|
+
name = "python3-dll-a"
|
|
181
|
+
version = "0.2.14"
|
|
182
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
183
|
+
checksum = "d381ef313ae70b4da5f95f8a4de773c6aa5cd28f73adec4b4a31df70b66780d8"
|
|
184
|
+
dependencies = [
|
|
185
|
+
"cc",
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "quote"
|
|
190
|
+
version = "1.0.44"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
|
193
|
+
dependencies = [
|
|
194
|
+
"proc-macro2",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
[[package]]
|
|
198
|
+
name = "rustversion"
|
|
199
|
+
version = "1.0.22"
|
|
200
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
201
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
202
|
+
|
|
203
|
+
[[package]]
|
|
204
|
+
name = "shlex"
|
|
205
|
+
version = "1.3.0"
|
|
206
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
207
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
208
|
+
|
|
209
|
+
[[package]]
|
|
210
|
+
name = "syn"
|
|
211
|
+
version = "2.0.117"
|
|
212
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
213
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
214
|
+
dependencies = [
|
|
215
|
+
"proc-macro2",
|
|
216
|
+
"quote",
|
|
217
|
+
"unicode-ident",
|
|
218
|
+
]
|
|
219
|
+
|
|
220
|
+
[[package]]
|
|
221
|
+
name = "target-lexicon"
|
|
222
|
+
version = "0.12.16"
|
|
223
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
224
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
225
|
+
|
|
226
|
+
[[package]]
|
|
227
|
+
name = "unicode-ident"
|
|
228
|
+
version = "1.0.24"
|
|
229
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
230
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "unindent"
|
|
234
|
+
version = "0.2.4"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
evaluatio-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evaluatio
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Summary: A library that contains computationally efficient metrics for the valuation of different NLP systems
|
|
9
|
+
Author-email: Preben Vangberg <prv21fgt@bangor.ac.uk>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
13
|
+
Project-URL: homepage, https://codeberg.org/prvinspace/evaluatio
|
|
14
|
+
Project-URL: repository, https://codeberg.org/prvinspace/evaluatio
|
|
15
|
+
|
|
16
|
+
# Evaluatio
|
|
17
|
+
|
|
18
|
+
***Note: The library is under development, so things are likely to change, especially function signatures.***
|
|
19
|
+
|
|
20
|
+
Evaluatio is a library that contains computationally efficient metrics for the valuation of different NLP systems.
|
|
21
|
+
It is the continuation of the [`universal-edit-distance`](https://gitlab.com/prebens-phd-adventures/universal-edit-distance) project, but was renamed and restructured due to the project outgrowing its original purpose.
|
|
22
|
+
|
|
23
|
+
## Etymology
|
|
24
|
+
The name `evaluatio` is a Latin noun and means "evaluation". It also doubles as the English verb "to evaluate" with the Welsh verbal derivational suffix `-io`, so it could also be Welsh slang for "to evaluate".
|
|
25
|
+
|
|
26
|
+
## Components
|
|
27
|
+
|
|
28
|
+
### [evaluatio-core](./evaluatio-core/README.md)
|
|
29
|
+
`evaluatio-core` is a standalone Rust library that implements certain metrics and functions to improve the performance of the main library. This can be used by other Rust projects without requiring PyO3.
|
|
30
|
+
|
|
31
|
+
### [evaluatio-bindings](./evaluatio-bindings/README.md)
|
|
32
|
+
`evaluatio-bindings` contains the Py03 bindings between `evaluatio-core` and the main Python library. It simply exposes the functions and classes in the `evaluatio-core` to the Python library while also containing some helper functions to ensure that Python types are handled properly. All classes and functions are exported to a single Python module.
|
|
33
|
+
|
|
34
|
+
### python-src
|
|
35
|
+
`python-src` contains the main Python library. It contains wrappers for `evaluatio-bindings` to ensure that functions are documented, type-annotated, and sorted into different organised modules.
|
|
36
|
+
|
|
37
|
+
## Contribute to the project
|
|
38
|
+
There is always room for improvements, new metrics, new functionality, etc. If you have any suggestions or requests please feel free to add an issue! The main repository for the project can be found at [https://codeberg.org/prvinspace/evaluatio](codeberg.org/prvinspace/evaluatio)
|
|
39
|
+
|
|
40
|
+
## Maintainer
|
|
41
|
+
|
|
42
|
+
The project is maintained by Preben Vangberg <prv21fgt@bangor.ac.uk>.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Evaluatio
|
|
2
|
+
|
|
3
|
+
***Note: The library is under development, so things are likely to change, especially function signatures.***
|
|
4
|
+
|
|
5
|
+
Evaluatio is a library that contains computationally efficient metrics for the valuation of different NLP systems.
|
|
6
|
+
It is the continuation of the [`universal-edit-distance`](https://gitlab.com/prebens-phd-adventures/universal-edit-distance) project, but was renamed and restructured due to the project outgrowing its original purpose.
|
|
7
|
+
|
|
8
|
+
## Etymology
|
|
9
|
+
The name `evaluatio` is a Latin noun and means "evaluation". It also doubles as the English verb "to evaluate" with the Welsh verbal derivational suffix `-io`, so it could also be Welsh slang for "to evaluate".
|
|
10
|
+
|
|
11
|
+
## Components
|
|
12
|
+
|
|
13
|
+
### [evaluatio-core](./evaluatio-core/README.md)
|
|
14
|
+
`evaluatio-core` is a standalone Rust library that implements certain metrics and functions to improve the performance of the main library. This can be used by other Rust projects without requiring PyO3.
|
|
15
|
+
|
|
16
|
+
### [evaluatio-bindings](./evaluatio-bindings/README.md)
|
|
17
|
+
`evaluatio-bindings` contains the Py03 bindings between `evaluatio-core` and the main Python library. It simply exposes the functions and classes in the `evaluatio-core` to the Python library while also containing some helper functions to ensure that Python types are handled properly. All classes and functions are exported to a single Python module.
|
|
18
|
+
|
|
19
|
+
### python-src
|
|
20
|
+
`python-src` contains the main Python library. It contains wrappers for `evaluatio-bindings` to ensure that functions are documented, type-annotated, and sorted into different organised modules.
|
|
21
|
+
|
|
22
|
+
## Contribute to the project
|
|
23
|
+
There is always room for improvements, new metrics, new functionality, etc. If you have any suggestions or requests please feel free to add an issue! The main repository for the project can be found at [https://codeberg.org/prvinspace/evaluatio](codeberg.org/prvinspace/evaluatio)
|
|
24
|
+
|
|
25
|
+
## Maintainer
|
|
26
|
+
|
|
27
|
+
The project is maintained by Preben Vangberg <prv21fgt@bangor.ac.uk>.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/target
|
|
2
|
+
|
|
3
|
+
# Byte-compiled / optimized / DLL files
|
|
4
|
+
__pycache__/
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
|
|
8
|
+
# C extensions
|
|
9
|
+
*.so
|
|
10
|
+
|
|
11
|
+
# Distribution / packaging
|
|
12
|
+
.Python
|
|
13
|
+
.venv/
|
|
14
|
+
env/
|
|
15
|
+
bin/
|
|
16
|
+
build/
|
|
17
|
+
develop-eggs/
|
|
18
|
+
dist/
|
|
19
|
+
eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
include/
|
|
26
|
+
man/
|
|
27
|
+
venv/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
|
|
32
|
+
# Installer logs
|
|
33
|
+
pip-log.txt
|
|
34
|
+
pip-delete-this-directory.txt
|
|
35
|
+
pip-selfcheck.json
|
|
36
|
+
|
|
37
|
+
# Unit test / coverage reports
|
|
38
|
+
htmlcov/
|
|
39
|
+
.tox/
|
|
40
|
+
.coverage
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
|
|
45
|
+
# Translations
|
|
46
|
+
*.mo
|
|
47
|
+
|
|
48
|
+
# Mr Developer
|
|
49
|
+
.mr.developer.cfg
|
|
50
|
+
.project
|
|
51
|
+
.pydevproject
|
|
52
|
+
|
|
53
|
+
# Rope
|
|
54
|
+
.ropeproject
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
*.pot
|
|
59
|
+
|
|
60
|
+
.DS_Store
|
|
61
|
+
|
|
62
|
+
# Sphinx documentation
|
|
63
|
+
docs/_build/
|
|
64
|
+
|
|
65
|
+
# PyCharm
|
|
66
|
+
.idea/
|
|
67
|
+
|
|
68
|
+
# VSCode
|
|
69
|
+
.vscode/
|
|
70
|
+
|
|
71
|
+
# Pyenv
|
|
72
|
+
.python-version
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# [package]
|
|
2
|
+
# name = "evaluatio_bindings"
|
|
3
|
+
# version = "0.1.0"
|
|
4
|
+
# edition = "2021"
|
|
5
|
+
|
|
6
|
+
# # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
7
|
+
# [lib]
|
|
8
|
+
# name = "evaluatio_bindings"
|
|
9
|
+
# crate-type = ["cdylib"]
|
|
10
|
+
|
|
11
|
+
# [dependencies]
|
|
12
|
+
# pyo3 = "0.23.3"
|
|
13
|
+
# evaluatio-core = { path = "../evaluatio-core", features = ["python"] }
|
|
14
|
+
|
|
15
|
+
[package]
|
|
16
|
+
name = "evaluatio-bindings"
|
|
17
|
+
version = "0.1.0"
|
|
18
|
+
edition = "2021"
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
|
|
21
|
+
[lib]
|
|
22
|
+
name = "_bindings"
|
|
23
|
+
crate-type = ["cdylib"]
|
|
24
|
+
|
|
25
|
+
[dependencies]
|
|
26
|
+
pyo3 = { version = "0.23.3", features = ["extension-module", "abi3", "abi3-py38", "generate-import-lib"] }
|
|
27
|
+
evaluatio-core = { path = "../evaluatio-core", features = ["python"] }
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# evaluatio-bindings
|
|
2
|
+
|
|
3
|
+
This component contains the PyO3 bindings for [evaluatio-core](../evaluatio-core/README.md).
|
|
4
|
+
The bindings are exported to a single module located at `evaluatio._bindings`.
|
|
5
|
+
These bindings are used/wrapped by functions in the main [Python package](../python-src/).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
use pyo3::{
|
|
2
|
+
types::{PyAnyMethods, PyList},
|
|
3
|
+
Bound, FromPyObject, IntoPyObjectExt, Py, PyAny, PyResult, Python,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
#[derive(Debug)]
|
|
7
|
+
pub enum EditDistanceItem {
|
|
8
|
+
String(String),
|
|
9
|
+
Int(i64),
|
|
10
|
+
Float(f64),
|
|
11
|
+
Bool(bool),
|
|
12
|
+
Object(Py<PyAny>),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl PartialEq for EditDistanceItem {
|
|
16
|
+
fn eq(&self, other: &Self) -> bool {
|
|
17
|
+
match (self, other) {
|
|
18
|
+
(EditDistanceItem::String(a), EditDistanceItem::String(b)) => a == b,
|
|
19
|
+
(EditDistanceItem::Int(a), EditDistanceItem::Int(b)) => a == b,
|
|
20
|
+
(EditDistanceItem::Float(a), EditDistanceItem::Float(b)) => a == b,
|
|
21
|
+
(EditDistanceItem::Bool(a), EditDistanceItem::Bool(b)) => a == b,
|
|
22
|
+
(EditDistanceItem::Object(a), EditDistanceItem::Object(b)) => {
|
|
23
|
+
// Use Python's __eq__ by acquiring the GIL
|
|
24
|
+
Python::with_gil(|py| {
|
|
25
|
+
// Bind the Py<PyAny> to this thread-local context
|
|
26
|
+
let a_bound = a.bind(py);
|
|
27
|
+
let b_bound = b.bind(py);
|
|
28
|
+
a_bound.eq(b_bound).unwrap_or(false)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
// If types don't match, defer to Python's eq function
|
|
32
|
+
(a, b) => Python::with_gil(|py| {
|
|
33
|
+
let to_py = |item: &EditDistanceItem| -> Option<Py<PyAny>> {
|
|
34
|
+
match item {
|
|
35
|
+
EditDistanceItem::String(s) => s.into_py_any(py).ok(),
|
|
36
|
+
EditDistanceItem::Int(i) => i.into_py_any(py).ok(),
|
|
37
|
+
EditDistanceItem::Float(f) => f.into_py_any(py).ok(),
|
|
38
|
+
EditDistanceItem::Bool(b) => b.into_py_any(py).ok(),
|
|
39
|
+
EditDistanceItem::Object(obj) => Some(obj.clone_ref(py)),
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
match (to_py(a), to_py(b)) {
|
|
44
|
+
// if both are fine, defer to Python, otherwise assume False
|
|
45
|
+
(Some(a), Some(b)) => a.bind(py).eq(b.bind(py)).unwrap_or(false),
|
|
46
|
+
_ => false,
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl<'source> FromPyObject<'source> for EditDistanceItem {
|
|
54
|
+
fn extract_bound(obj: &Bound<'source, PyAny>) -> PyResult<Self> {
|
|
55
|
+
// Try to extract each supported type in order
|
|
56
|
+
if let Ok(val) = obj.extract::<String>() {
|
|
57
|
+
Ok(EditDistanceItem::String(val))
|
|
58
|
+
} else if let Ok(val) = obj.extract::<i64>() {
|
|
59
|
+
Ok(EditDistanceItem::Int(val))
|
|
60
|
+
} else if let Ok(val) = obj.extract::<f64>() {
|
|
61
|
+
Ok(EditDistanceItem::Float(val))
|
|
62
|
+
} else if let Ok(val) = obj.extract::<bool>() {
|
|
63
|
+
Ok(EditDistanceItem::Bool(val))
|
|
64
|
+
} else {
|
|
65
|
+
// For any other type, store the Python object for later comparison
|
|
66
|
+
let py_obj = obj.clone().unbind();
|
|
67
|
+
Ok(EditDistanceItem::Object(py_obj))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
pub(crate) fn convert_to_edit_distance_vec(
|
|
73
|
+
items: &Vec<Bound<PyAny>>,
|
|
74
|
+
) -> PyResult<Vec<EditDistanceItem>> {
|
|
75
|
+
items
|
|
76
|
+
.iter()
|
|
77
|
+
.map(|item| item.extract::<EditDistanceItem>())
|
|
78
|
+
.collect()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pub fn convert_to_nested_edit_distance_item_vec(
|
|
82
|
+
pylist: &Bound<PyList>,
|
|
83
|
+
) -> PyResult<Vec<Vec<EditDistanceItem>>> {
|
|
84
|
+
// Create vectors to store the converted data
|
|
85
|
+
let mut vecs: Vec<Vec<EditDistanceItem>> = Vec::with_capacity(pylist.len()?);
|
|
86
|
+
|
|
87
|
+
// Extract the data from Python
|
|
88
|
+
for i in 0..pylist.len()? {
|
|
89
|
+
let item = pylist.get_item(i)?;
|
|
90
|
+
let list = item.downcast::<PyList>()?;
|
|
91
|
+
|
|
92
|
+
let mut inner: Vec<EditDistanceItem> = Vec::with_capacity(list.len()?);
|
|
93
|
+
|
|
94
|
+
// Extract items from the inner lists, converting to EditDistanceItem
|
|
95
|
+
for j in 0..list.len()? {
|
|
96
|
+
inner.push(list.get_item(j)?.extract::<EditDistanceItem>()?);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
vecs.push(inner);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Create the vectors of references to vectors that the edit_distance function expects
|
|
103
|
+
Ok(vecs)
|
|
104
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
use pyo3::prelude::*;
|
|
2
|
+
mod base;
|
|
3
|
+
mod metrics;
|
|
4
|
+
use metrics::*;
|
|
5
|
+
|
|
6
|
+
/// A Python module implemented in Rust.
|
|
7
|
+
#[pymodule]
|
|
8
|
+
fn _bindings(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
9
|
+
// Character error rate
|
|
10
|
+
m.add_function(wrap_pyfunction!(cer::character_edit_distance_array_py, m)?)?;
|
|
11
|
+
m.add_function(wrap_pyfunction!(cer::character_error_rate_py, m)?)?;
|
|
12
|
+
m.add_function(wrap_pyfunction!(cer::character_error_rate_array_py, m)?)?;
|
|
13
|
+
|
|
14
|
+
// Match error rate
|
|
15
|
+
//m.add_function(wrap_pyfunction!(mer::match_error_rate_array_py, m)?)?;
|
|
16
|
+
//m.add_function(wrap_pyfunction!(mer::hits_array_py, m)?)?;
|
|
17
|
+
|
|
18
|
+
// Optimal alignment
|
|
19
|
+
m.add_function(wrap_pyfunction!(alignment::optimial_alignment_py, m)?)?;
|
|
20
|
+
m.add_class::<evaluatio_core::metrics::alignment::Alignment>()?;
|
|
21
|
+
|
|
22
|
+
// Points of interest error rate
|
|
23
|
+
m.add_function(wrap_pyfunction!(pier::poi_edit_distance_py, m)?)?;
|
|
24
|
+
m.add_function(wrap_pyfunction!(pier::poi_error_rate_py, m)?)?;
|
|
25
|
+
|
|
26
|
+
// Universal error rate
|
|
27
|
+
m.add_function(wrap_pyfunction!(uer::universal_edit_distance_array_py, m)?)?;
|
|
28
|
+
m.add_function(wrap_pyfunction!(uer::universal_error_rate_array_py, m)?)?;
|
|
29
|
+
|
|
30
|
+
// Word error rate
|
|
31
|
+
m.add_function(wrap_pyfunction!(wer::word_edit_distance_array_py, m)?)?;
|
|
32
|
+
m.add_function(wrap_pyfunction!(wer::word_error_rate_py, m)?)?;
|
|
33
|
+
m.add_function(wrap_pyfunction!(wer::word_error_rate_array_py, m)?)?;
|
|
34
|
+
|
|
35
|
+
Ok(())
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use evaluatio_core::metrics::alignment;
|
|
2
|
+
use pyo3::{pyfunction, Bound, PyAny, PyResult};
|
|
3
|
+
|
|
4
|
+
use crate::base::{convert_to_edit_distance_vec, EditDistanceItem};
|
|
5
|
+
|
|
6
|
+
#[pyfunction(name = "optimal_alignment")]
|
|
7
|
+
pub fn optimial_alignment_py(
|
|
8
|
+
predictions: Vec<Bound<PyAny>>,
|
|
9
|
+
references: Vec<Bound<PyAny>>,
|
|
10
|
+
) -> PyResult<Vec<alignment::Alignment>> {
|
|
11
|
+
let pred: Vec<EditDistanceItem> = convert_to_edit_distance_vec(&predictions)?;
|
|
12
|
+
let ref_: Vec<EditDistanceItem> = convert_to_edit_distance_vec(&references)?;
|
|
13
|
+
|
|
14
|
+
let result = alignment::optimial_aligment(&pred, &ref_);
|
|
15
|
+
Ok(result)
|
|
16
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
use evaluatio_core::metrics::cer;
|
|
2
|
+
use pyo3::{pyfunction, PyResult};
|
|
3
|
+
|
|
4
|
+
#[pyfunction(name = "character_error_rate_array")]
|
|
5
|
+
pub fn character_error_rate_array_py(
|
|
6
|
+
predictions: Vec<String>,
|
|
7
|
+
references: Vec<String>,
|
|
8
|
+
) -> PyResult<Vec<f64>> {
|
|
9
|
+
let left_vec: Vec<&str> = predictions.iter().map(|x| x.as_str()).collect();
|
|
10
|
+
let right_vec: Vec<&str> = references.iter().map(|x| x.as_str()).collect();
|
|
11
|
+
let result = cer::character_error_rate_array(&left_vec, &right_vec);
|
|
12
|
+
Ok(result)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[pyfunction(name = "character_edit_distance_array")]
|
|
16
|
+
pub fn character_edit_distance_array_py(
|
|
17
|
+
predictions: Vec<String>,
|
|
18
|
+
references: Vec<String>,
|
|
19
|
+
) -> PyResult<Vec<usize>> {
|
|
20
|
+
let left_vec: Vec<&str> = predictions.iter().map(|x| x.as_str()).collect();
|
|
21
|
+
let right_vec: Vec<&str> = references.iter().map(|x| x.as_str()).collect();
|
|
22
|
+
let result = cer::character_edit_distance_array(&left_vec, &right_vec);
|
|
23
|
+
Ok(result)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[pyfunction(name = "character_error_rate")]
|
|
27
|
+
pub fn character_error_rate_py(predictions: Vec<String>, references: Vec<String>) -> PyResult<f64> {
|
|
28
|
+
let left_vec: Vec<&str> = predictions.iter().map(|x| x.as_str()).collect();
|
|
29
|
+
let right_vec: Vec<&str> = references.iter().map(|x| x.as_str()).collect();
|
|
30
|
+
let result = cer::character_error_rate(&left_vec, &right_vec);
|
|
31
|
+
Ok(result)
|
|
32
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
use crate::base::{
|
|
2
|
+
convert_to_edit_distance_vec, convert_to_nested_edit_distance_item_vec, EditDistanceItem,
|
|
3
|
+
};
|
|
4
|
+
use evaluatio_core::metrics::pier;
|
|
5
|
+
use pyo3::types::PyList;
|
|
6
|
+
use pyo3::{pyfunction, Bound, PyAny, PyResult};
|
|
7
|
+
|
|
8
|
+
#[pyfunction(name = "poi_edit_distance")]
|
|
9
|
+
pub fn poi_edit_distance_py(
|
|
10
|
+
predictions: Vec<Bound<PyAny>>,
|
|
11
|
+
references: Vec<Bound<PyAny>>,
|
|
12
|
+
points_of_interest: Vec<bool>,
|
|
13
|
+
) -> PyResult<usize> {
|
|
14
|
+
let pred: Vec<EditDistanceItem> = convert_to_edit_distance_vec(&predictions)?;
|
|
15
|
+
let ref_: Vec<EditDistanceItem> = convert_to_edit_distance_vec(&references)?;
|
|
16
|
+
|
|
17
|
+
let result = pier::poi_edit_distance(&pred, &ref_, &points_of_interest);
|
|
18
|
+
Ok(result)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[pyfunction(name = "poi_error_rate")]
|
|
22
|
+
pub fn poi_error_rate_py(
|
|
23
|
+
predictions: &Bound<PyList>,
|
|
24
|
+
references: &Bound<PyList>,
|
|
25
|
+
points_of_interest: Vec<Vec<bool>>,
|
|
26
|
+
) -> PyResult<f64> {
|
|
27
|
+
// Create vectors to store the converted data
|
|
28
|
+
let pred_vecs: Vec<Vec<EditDistanceItem>> =
|
|
29
|
+
convert_to_nested_edit_distance_item_vec(predictions)?;
|
|
30
|
+
let ref_vecs: Vec<Vec<EditDistanceItem>> =
|
|
31
|
+
convert_to_nested_edit_distance_item_vec(references)?;
|
|
32
|
+
|
|
33
|
+
// Create the vectors of references to vectors that the edit_distance function expects
|
|
34
|
+
let pred_vec_refs: Vec<&[EditDistanceItem]> = pred_vecs.iter().map(|v| v.as_slice()).collect();
|
|
35
|
+
let ref_vec_refs: Vec<&[EditDistanceItem]> = ref_vecs.iter().map(|v| v.as_slice()).collect();
|
|
36
|
+
let poi_vec_refs: Vec<&[bool]> = points_of_interest.iter().map(|v| v.as_slice()).collect();
|
|
37
|
+
|
|
38
|
+
// Call a modified edit_distance implementation that works with EditDistanceItem
|
|
39
|
+
let result = pier::poi_error_rate(&pred_vec_refs, &ref_vec_refs, &poi_vec_refs);
|
|
40
|
+
|
|
41
|
+
Ok(result)
|
|
42
|
+
}
|