improve: base64 NLP

This commit is contained in:
Alikia2x 2024-04-26 18:21:52 +08:00
parent 1d7aaf6a8a
commit b46f1adddb
2 changed files with 10 additions and 7 deletions

View File

@ -87,9 +87,7 @@ export default function () {
}
]);
}
console.log(new Date().getTime());
const b64 = base64NLP(query);
console.log(new Date().getTime());
if (b64.suggestion!==null){
cleanSuggestion("default-link","default","text")
updateSuggestion([b64 as suggestionItem]);

View File

@ -36,7 +36,6 @@ export function base64NLP(str: string) {
};
for (let intention of Object.keys(intentions)) {
const pos = str.trim().indexOf(intention);
const l = str.length;
const w = str.split(" ").length;
if (w > 1 && pos !== -1) {
result.confidence += intentions[intention];
@ -44,8 +43,13 @@ export function base64NLP(str: string) {
break;
}
}
let processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions))).trim();
let processedQuery = "";
if (result.intention==="base64.encode"){
processedQuery = str.split(" ")[str.split(" ").length-1];
} else if (result.intention==="base64.decode") {
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions))).trim();
}
if (result.intention === "base64.decode"){
if (validBase64(processedQuery)) {
result.confidence = 1;
@ -53,7 +57,7 @@ export function base64NLP(str: string) {
result.confidence = 0;
}
}
else if (validBase64(processedQuery)) {
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
result.intention = "base64.decode";
result.confidence += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
result.probability += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
@ -64,7 +68,8 @@ export function base64NLP(str: string) {
result.suggestion = btoa(processedQuery);
break;
case "base64.decode":
result.suggestion = atob(processedQuery);
if (result.confidence > 0.1)
result.suggestion = atob(processedQuery);
break;
default:
break;