sparkast/lib/nlp/base.ts
2024-06-17 03:11:17 +08:00

19 lines
592 B
TypeScript

import { NLPResult } from "../onesearch/NLPResult";
import { stopwords } from "./stopwords";
class NLP {
result: NLPResult;
constructor(
public query: String,
public task: String
) {
this.result = new NLPResult();
}
public removeStopwords(str: string, extraStopwords: string[] = [], disableDefault: boolean = false){
const list = disableDefault ? extraStopwords : stopwords.concat(extraStopwords);
for (let word of list){
str = str.replace(new RegExp(`\\b${word}\\b`, 'gi'), '');
}
return str;
}
}