mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Switch to a different algroithm.
This commit is contained in:
parent
25927ad13c
commit
f8879b307c
9 changed files with 72 additions and 16 deletions
|
@ -1,14 +1,16 @@
|
|||
import NewsAnalyzer from "~/components/newsAnalyzer";
|
||||
const newsAnalyzer = new NewsAnalyzer();
|
||||
// Trying out the ahocorasick algorithm
|
||||
// Recommended by: https://www.threads.com/@hsinspeng/post/DJ3yVGQxBg7
|
||||
import AhoCorasick from "ahocorasick";
|
||||
|
||||
async function checkUnsafeContent(title: string) {
|
||||
try {
|
||||
const req = await fetch("/api/contentcheck/kidunfriendlycontent");
|
||||
const res = await req.json();
|
||||
const patterns = res.words.map((word) => new RegExp(word, "i"));
|
||||
console.log(patterns);
|
||||
newsAnalyzer.setSensitivePatterns(patterns);
|
||||
const kidfriendly = newsAnalyzer.isKidFriendly(title);
|
||||
return !kidfriendly;
|
||||
console.log(res.words);
|
||||
const ac = new AhoCorasick(res.words);
|
||||
const kidfriendly = ac.search(title);
|
||||
console.log(kidfriendly);
|
||||
return kidfriendly;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue