@jjlmoya/utils-tabletop 1.20.0 → 1.21.0
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.
package/package.json
CHANGED
|
@@ -28,6 +28,8 @@ const TRANSLATABLE_KEYS = [
|
|
|
28
28
|
'schemas',
|
|
29
29
|
] as const;
|
|
30
30
|
|
|
31
|
+
const COPY_THRESHOLD = 0.9;
|
|
32
|
+
|
|
31
33
|
const SPANISH_MARKERS = [
|
|
32
34
|
['sangre', /\bsangre\b/gi],
|
|
33
35
|
['molino', /\bmolino\b/gi],
|
|
@@ -65,12 +67,16 @@ function normalize(value: string): string {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
function isTechnicalInvariant(text: string): boolean {
|
|
70
|
+
const ledUnitMatches = text.match(/\b\d+(?:-\d+)?\s*(?:w|lm)\b/g) ?? [];
|
|
68
71
|
return [
|
|
69
72
|
'data:image/svg+xml;base64',
|
|
70
73
|
'background-image: url',
|
|
71
74
|
'.layout-playground {',
|
|
72
75
|
'const samplerate =',
|
|
73
|
-
].some((pattern) => text.includes(pattern)) ||
|
|
76
|
+
].some((pattern) => text.includes(pattern)) ||
|
|
77
|
+
(text.includes('presets') && text.includes('hz')) ||
|
|
78
|
+
(text.includes('t_rectal') && text.includes('exp(-k * t)')) ||
|
|
79
|
+
(text.includes('led') && ledUnitMatches.length >= 3);
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
function collectString(value: string, output: string[]): void {
|
|
@@ -111,10 +117,26 @@ function findSpanishMarkers(text: string[]): string[] {
|
|
|
111
117
|
);
|
|
112
118
|
}
|
|
113
119
|
|
|
120
|
+
function similarity(left: string, right: string): number {
|
|
121
|
+
const leftTokens = left.split(/\s+/);
|
|
122
|
+
const rightCounts = new Map<string, number>();
|
|
123
|
+
right.split(/\s+/).forEach((token) => rightCounts.set(token, (rightCounts.get(token) ?? 0) + 1));
|
|
124
|
+
const matches = leftTokens.reduce((total, token) => {
|
|
125
|
+
const count = rightCounts.get(token) ?? 0;
|
|
126
|
+
if (count > 0) rightCounts.set(token, count - 1);
|
|
127
|
+
return total + (count > 0 ? 1 : 0);
|
|
128
|
+
}, 0);
|
|
129
|
+
return (2 * matches) / (leftTokens.length + right.split(/\s+/).length);
|
|
130
|
+
}
|
|
131
|
+
|
|
114
132
|
function findCopiedFragments(spanish: string[], translated: string[]): string[] {
|
|
115
|
-
const corpus = translated.join(' ');
|
|
116
133
|
return spanish
|
|
117
|
-
.filter((fragment) => fragment.length >= 80
|
|
134
|
+
.filter((fragment) => fragment.length >= 80)
|
|
135
|
+
.filter((fragment) => translated.some((candidate) =>
|
|
136
|
+
candidate.length >= 80 &&
|
|
137
|
+
Math.min(fragment.length, candidate.length) / Math.max(fragment.length, candidate.length) >= COPY_THRESHOLD &&
|
|
138
|
+
similarity(fragment, candidate) >= COPY_THRESHOLD,
|
|
139
|
+
))
|
|
118
140
|
.sort((a, b) => b.length - a.length)
|
|
119
141
|
.slice(0, 3);
|
|
120
142
|
}
|