improve: base64 NLP
This commit is contained in:
parent
1d7aaf6a8a
commit
b46f1adddb
@ -87,9 +87,7 @@ export default function () {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
console.log(new Date().getTime());
|
|
||||||
const b64 = base64NLP(query);
|
const b64 = base64NLP(query);
|
||||||
console.log(new Date().getTime());
|
|
||||||
if (b64.suggestion!==null){
|
if (b64.suggestion!==null){
|
||||||
cleanSuggestion("default-link","default","text")
|
cleanSuggestion("default-link","default","text")
|
||||||
updateSuggestion([b64 as suggestionItem]);
|
updateSuggestion([b64 as suggestionItem]);
|
||||||
|
@ -36,7 +36,6 @@ export function base64NLP(str: string) {
|
|||||||
};
|
};
|
||||||
for (let intention of Object.keys(intentions)) {
|
for (let intention of Object.keys(intentions)) {
|
||||||
const pos = str.trim().indexOf(intention);
|
const pos = str.trim().indexOf(intention);
|
||||||
const l = str.length;
|
|
||||||
const w = str.split(" ").length;
|
const w = str.split(" ").length;
|
||||||
if (w > 1 && pos !== -1) {
|
if (w > 1 && pos !== -1) {
|
||||||
result.confidence += intentions[intention];
|
result.confidence += intentions[intention];
|
||||||
@ -44,8 +43,13 @@ export function base64NLP(str: string) {
|
|||||||
break;
|
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 (result.intention === "base64.decode"){
|
||||||
if (validBase64(processedQuery)) {
|
if (validBase64(processedQuery)) {
|
||||||
result.confidence = 1;
|
result.confidence = 1;
|
||||||
@ -53,7 +57,7 @@ export function base64NLP(str: string) {
|
|||||||
result.confidence = 0;
|
result.confidence = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (validBase64(processedQuery)) {
|
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
||||||
result.intention = "base64.decode";
|
result.intention = "base64.decode";
|
||||||
result.confidence += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
result.confidence += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
||||||
result.probability += 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);
|
result.suggestion = btoa(processedQuery);
|
||||||
break;
|
break;
|
||||||
case "base64.decode":
|
case "base64.decode":
|
||||||
result.suggestion = atob(processedQuery);
|
if (result.confidence > 0.1)
|
||||||
|
result.suggestion = atob(processedQuery);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user