From 68baaeac125f2e888481dc5de8e0c0e7d84aa595 Mon Sep 17 00:00:00 2001 From: FongMi Date: Mon, 3 Feb 2025 00:19:12 +0800 Subject: [PATCH] Create similarity.js --- quickjs/src/main/assets/js/lib/similarity.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 quickjs/src/main/assets/js/lib/similarity.js diff --git a/quickjs/src/main/assets/js/lib/similarity.js b/quickjs/src/main/assets/js/lib/similarity.js new file mode 100644 index 000000000..3dfc497d5 --- /dev/null +++ b/quickjs/src/main/assets/js/lib/similarity.js @@ -0,0 +1 @@ +function compareTwoStrings(first,second){if((first=first.replace(/\s+/g,""))===(second=second.replace(/\s+/g,"")))return 1;if(first.length<2||second.length<2)return 0;var firstBigrams=new Map;for(let i=0;iratings[bestMatchIndex].rating&&(bestMatchIndex=i)}return{ratings:ratings,bestMatch:ratings[bestMatchIndex],bestMatchIndex:bestMatchIndex}}function lcs(str1,str2){if(!str1||!str2)return{length:0,sequence:"",offset:0};for(var sequence="",str1Length=str1.length,str2Length=str2.length,num=new Array(str1Length),maxlen=0,lastSubsBegin=0,i=0;imaxlen&&(maxlen=num[i][j],lastSubsBegin===(thisSubsBegin=i-num[i][j]+1)?sequence+=str1[i]:(lastSubsBegin=thisSubsBegin,sequence="",sequence+=str1.substr(lastSubsBegin,i+1-lastSubsBegin))));return{length:maxlen,sequence:sequence,offset:thisSubsBegin}}function findBestLCS(mainString,targetStrings){var results=[];let bestMatchIndex=0;for(let i=0;iresults[bestMatchIndex].lcs.length&&(bestMatchIndex=i)}return{allLCS:results,bestMatch:results[bestMatchIndex],bestMatchIndex:bestMatchIndex}}export{compareTwoStrings,findBestMatch,findBestLCS}; \ No newline at end of file