aotrautils-srv 0.0.802 → 0.0.803
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (
|
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (21/02/2024-23:22:39)»*/
|
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -4086,6 +4086,122 @@ window.areEquivalentFlatMaps=function(o1,o2,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAM
|
|
|
4086
4086
|
return areEquivalent;
|
|
4087
4087
|
}
|
|
4088
4088
|
|
|
4089
|
+
|
|
4090
|
+
window.overlaps=(delimitedObj1,delimitedObj2)=>{
|
|
4091
|
+
return (delimitedObj2.start<=delimitedObj1.start && delimitedObj1.start<=delimitedObj2.end)
|
|
4092
|
+
|| (delimitedObj2.start<=delimitedObj1.end && delimitedObj1.end <=delimitedObj2.end);
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
|
|
4096
|
+
window.findCommonChunks=(str1,str2,minimalLength=2,invertLogic=false,characterFilterFunction=null)=>{
|
|
4097
|
+
const results=[];
|
|
4098
|
+
|
|
4099
|
+
if(empty(str1)) return results;
|
|
4100
|
+
if(empty(str2)) return results;
|
|
4101
|
+
|
|
4102
|
+
|
|
4103
|
+
// 1) We build a binary correspondances matrix :
|
|
4104
|
+
|
|
4105
|
+
const correspondancesMatrix=[];
|
|
4106
|
+
|
|
4107
|
+
for(let i=0;i<str1.length;i++){
|
|
4108
|
+
|
|
4109
|
+
const currentCharAtRow=str1.charAt(i);
|
|
4110
|
+
|
|
4111
|
+
const row=[];
|
|
4112
|
+
for(let j=0;j<str2.length;j++){
|
|
4113
|
+
|
|
4114
|
+
const currentCharAtColumn=str2.charAt(j);
|
|
4115
|
+
|
|
4116
|
+
if( currentCharAtColumn==currentCharAtRow
|
|
4117
|
+
&& (!characterFilterFunction || characterFilterFunction(currentCharAtColumn)))
|
|
4118
|
+
row.push(true && !invertLogic);
|
|
4119
|
+
else
|
|
4120
|
+
row.push(false || invertLogic);
|
|
4121
|
+
|
|
4122
|
+
}
|
|
4123
|
+
correspondancesMatrix.push(row);
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4126
|
+
// 2) We try to walk through the diagonal of each found correspondance to create each chunk, and removing those already walked along the way :
|
|
4127
|
+
// This way we build the raw chunks dictionnary :
|
|
4128
|
+
for(let i=0;i<correspondancesMatrix.length;i++){
|
|
4129
|
+
|
|
4130
|
+
for(let j=0;j<correspondancesMatrix[i].length;j++){
|
|
4131
|
+
|
|
4132
|
+
if(!correspondancesMatrix[i][j]) continue;
|
|
4133
|
+
|
|
4134
|
+
let newChunk=null;
|
|
4135
|
+
|
|
4136
|
+
// Proximity algorithm : Here it's just a simple diagonal walking
|
|
4137
|
+
// (for blobs in a 2D image detection, instead of hunks in a string detection, it would be a recursive algorithm !)
|
|
4138
|
+
let k;
|
|
4139
|
+
for(k=0;(i+k)<correspondancesMatrix.length && (j+k)<correspondancesMatrix[i].length;k++){
|
|
4140
|
+
|
|
4141
|
+
if(!correspondancesMatrix[i+k][j+k]) break;
|
|
4142
|
+
|
|
4143
|
+
if(k==0){
|
|
4144
|
+
newChunk=str1[i+k];
|
|
4145
|
+
}else{
|
|
4146
|
+
newChunk+=str1[i+k];
|
|
4147
|
+
}
|
|
4148
|
+
correspondancesMatrix[i+k][j+k]=false;
|
|
4149
|
+
}
|
|
4150
|
+
if(newChunk && minimalLength<=newChunk.length){
|
|
4151
|
+
results.push(
|
|
4152
|
+
[
|
|
4153
|
+
{start:i+k-newChunk.length,end:i+k-1,value:newChunk,length:newChunk.length},
|
|
4154
|
+
{start:j+k-newChunk.length,end:j+k-1,value:newChunk,length:newChunk.length}
|
|
4155
|
+
]
|
|
4156
|
+
);
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
// 3) We filter all the overlapping chunks definitions, meaning when chunks overlap, only the biggest is kept !
|
|
4164
|
+
|
|
4165
|
+
const refinedResults=[];
|
|
4166
|
+
for(let i=0;i<results.length;i++){
|
|
4167
|
+
let chunk1=results[i];
|
|
4168
|
+
|
|
4169
|
+
for(let j=0;j<results.length;j++){
|
|
4170
|
+
let chunk2=results[j];
|
|
4171
|
+
|
|
4172
|
+
if(overlaps(chunk1[0],chunk2[0])) continue;
|
|
4173
|
+
|
|
4174
|
+
let chosenChunk=chunk1;
|
|
4175
|
+
if(chunk1[0].length<chunk2[0].length) chosenChunk=chunk2;
|
|
4176
|
+
|
|
4177
|
+
refinedResults.push(chosenChunk);
|
|
4178
|
+
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
|
|
4182
|
+
// (we need to do the adding in both directions :)
|
|
4183
|
+
for(let i=0;i<results.length;i++){
|
|
4184
|
+
let chunk1=results[i];
|
|
4185
|
+
|
|
4186
|
+
for(let j=0;j<results.length;j++){
|
|
4187
|
+
let chunk2=results[j];
|
|
4188
|
+
|
|
4189
|
+
if(overlaps(chunk1[1],chunk2[1])) continue;
|
|
4190
|
+
|
|
4191
|
+
let chosenChunk=chunk1;
|
|
4192
|
+
if(chunk1[1].length<chunk2[1].length) chosenChunk=chunk2;
|
|
4193
|
+
|
|
4194
|
+
refinedResults.push(chosenChunk);
|
|
4195
|
+
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
|
|
4200
|
+
return refinedResults;
|
|
4201
|
+
}
|
|
4202
|
+
|
|
4203
|
+
|
|
4204
|
+
|
|
4089
4205
|
window.areEquivalentSimple=function(obj1Param,obj2Param, caseSensitive=true){
|
|
4090
4206
|
const str1=(isString(obj1Param)?obj1Param:stringifyObject(obj1Param));
|
|
4091
4207
|
const str2=(isString(obj2Param)?obj2Param:stringifyObject(obj2Param));
|
|
@@ -5167,7 +5283,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
|
|
|
5167
5283
|
|
|
5168
5284
|
|
|
5169
5285
|
|
|
5170
|
-
/*utils SERVER library associated with aotra version : «1_29072022-2359 (
|
|
5286
|
+
/*utils SERVER library associated with aotra version : «1_29072022-2359 (21/02/2024-23:22:39)»*/
|
|
5171
5287
|
/*-----------------------------------------------------------------------------*/
|
|
5172
5288
|
|
|
5173
5289
|
|
aotrautils-srv/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils-srv",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.803",
|
|
4
4
|
"main": "aotrautils-srv.build.js",
|
|
5
5
|
"description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
|
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|