Codex commited on
Commit ·
36a8733
1
Parent(s): 912d0d6
Improve Circa OCR blob repair
Browse files- src/market-scanner.js +35 -0
src/market-scanner.js
CHANGED
|
@@ -884,6 +884,41 @@ function extractOddsTokensFromSegment(segment) {
|
|
| 884 |
const cleaned = normalizeWhitespace(segment)
|
| 885 |
.toUpperCase()
|
| 886 |
.replace(/[\[\]]/g, ' ')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
.replace(/(\d{5})(\d{3})(\d{5})(\s+[+\-~][0-9BOSI]{2,4})/g, '$1 +$2 $3$4')
|
| 888 |
.replace(/(\d{4,6})(\d{3})(\d{4,6})(\s+[+\-~][0-9BOSI]{2,4})/g, '$1 +$2 $3$4')
|
| 889 |
.replace(/(\d{4,6})([+\-~][0-9BOSI]{2,4})/g, '$1 $2')
|
|
|
|
| 884 |
const cleaned = normalizeWhitespace(segment)
|
| 885 |
.toUpperCase()
|
| 886 |
.replace(/[\[\]]/g, ' ')
|
| 887 |
+
.replace(/\d{12,13}/g, (value) => {
|
| 888 |
+
const candidates = [];
|
| 889 |
+
for (let firstLength = 4; firstLength <= 6; firstLength += 1) {
|
| 890 |
+
for (let thirdLength = 4; thirdLength <= 6; thirdLength += 1) {
|
| 891 |
+
if (firstLength + 3 + thirdLength !== value.length) {
|
| 892 |
+
continue;
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
const odds = value.slice(firstLength, firstLength + 3);
|
| 896 |
+
if (!/^\d{3}$/.test(odds)) {
|
| 897 |
+
continue;
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
const numericOdds = Number(odds);
|
| 901 |
+
if (!Number.isFinite(numericOdds) || numericOdds < 100 || numericOdds > 399) {
|
| 902 |
+
continue;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
candidates.push({
|
| 906 |
+
prefix: value.slice(0, firstLength),
|
| 907 |
+
odds,
|
| 908 |
+
suffix: value.slice(firstLength + 3),
|
| 909 |
+
numericOdds,
|
| 910 |
+
});
|
| 911 |
+
}
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
if (candidates.length === 0) {
|
| 915 |
+
return value;
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
const preferred = candidates
|
| 919 |
+
.sort((left, right) => left.numericOdds - right.numericOdds)[0];
|
| 920 |
+
return `${preferred.prefix} +${preferred.odds} ${preferred.suffix}`;
|
| 921 |
+
})
|
| 922 |
.replace(/(\d{5})(\d{3})(\d{5})(\s+[+\-~][0-9BOSI]{2,4})/g, '$1 +$2 $3$4')
|
| 923 |
.replace(/(\d{4,6})(\d{3})(\d{4,6})(\s+[+\-~][0-9BOSI]{2,4})/g, '$1 +$2 $3$4')
|
| 924 |
.replace(/(\d{4,6})([+\-~][0-9BOSI]{2,4})/g, '$1 $2')
|