@jjlmoya/utils-developer 1.26.0 → 1.27.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],
|
|
@@ -111,10 +113,26 @@ function findSpanishMarkers(text: string[]): string[] {
|
|
|
111
113
|
);
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
function similarity(left: string, right: string): number {
|
|
117
|
+
const leftTokens = left.split(/\s+/);
|
|
118
|
+
const rightCounts = new Map<string, number>();
|
|
119
|
+
right.split(/\s+/).forEach((token) => rightCounts.set(token, (rightCounts.get(token) ?? 0) + 1));
|
|
120
|
+
const matches = leftTokens.reduce((total, token) => {
|
|
121
|
+
const count = rightCounts.get(token) ?? 0;
|
|
122
|
+
if (count > 0) rightCounts.set(token, count - 1);
|
|
123
|
+
return total + (count > 0 ? 1 : 0);
|
|
124
|
+
}, 0);
|
|
125
|
+
return (2 * matches) / (leftTokens.length + right.split(/\s+/).length);
|
|
126
|
+
}
|
|
127
|
+
|
|
114
128
|
function findCopiedFragments(spanish: string[], translated: string[]): string[] {
|
|
115
|
-
const corpus = translated.join(' ');
|
|
116
129
|
return spanish
|
|
117
|
-
.filter((fragment) => fragment.length >= 80
|
|
130
|
+
.filter((fragment) => fragment.length >= 80)
|
|
131
|
+
.filter((fragment) => translated.some((candidate) =>
|
|
132
|
+
candidate.length >= 80 &&
|
|
133
|
+
Math.min(fragment.length, candidate.length) / Math.max(fragment.length, candidate.length) >= COPY_THRESHOLD &&
|
|
134
|
+
similarity(fragment, candidate) >= COPY_THRESHOLD,
|
|
135
|
+
))
|
|
118
136
|
.sort((a, b) => b.length - a.length)
|
|
119
137
|
.slice(0, 3);
|
|
120
138
|
}
|