-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstemmer.ts
132 lines (123 loc) · 3.17 KB
/
stemmer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// import * as natural from "natural";
export function checkMatchingWords(userText: string) {
const trimmed = userText.trim();
/// console.log("trimmed", trimmed, /[.!?¡¿«»'"]/.test(trimmed));
// if (trimmed.length < 4) return false; // too short to be a question
//check if numver of words is less than 3
// if (trimmed.split(" ").length < 3) {
// console.log("Message too short");
// return false; // too short to be a question
// }
// ignore common face emojis
// if (
// /[😀😃😄😁😆😅😂🤣😊😇🙂🙃😉😌😍😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🤩🥳😏😒😞😔😟😕🙁☹️😣😖😫😩😢😭😤😠😡🤬🤯😳🥺😨😰😥😓🤗🤔🤭🤫🤥😶😐😑😬🙄😯😦😧😮😲😴🤤😪😵🤐🥴🤢🤮🤧😷🤒🤕🤑🤠😈👿👹👺💀👻👽🤖💩😺😸😹😻😼😽🙀😿😾🙈🙉🙊🦄🐶🐱🐭🐹🐰🦊🦝🦙🐻🐼🦘🦡🐨🐯🦁🐮🐷🐽🐗🦓🦒🦏🐴🦌🦄🐑🐘🦏🦛🦘🦙🦒🦍🦧🐵🐒🦖🦕🐉🐲🌵🎄🌲🌳🌴🌱🌿☘️🍀🎍🎋🍃🍂🍁🍄🌾🌺🌻🌹🥀🌷🌼🌸💐🍇🍈🍉🍊🍋🍌🍍🍎🍏🍐🍑🍒🍓🥝🥥🥭🥑🥦🥒]/.test(
// trimmed
// )
// ) {
// console.log("Emoji found");
// return false;
// }
//
if (/[.!?¡¿«»'"]/.test(trimmed)) return true;
// german punctuation
if (/[„“‚‘]/.test(trimmed)) return true;
//true if in keyTriggerAIWords
const trigs = keyTriggerAIWords.some((word) => {
const regexTest = new RegExp("\\b(" + word + ")\\b", "i");
return regexTest.test(trimmed);
});
if (trigs) return true;
return false;
// const stemmedSearchTerm = trimmed
// .toLowerCase()
// .split(/\W+/)
// .map((word) => stemmer.stem(word))
// .join(" ");
// return regexTest.test(stemmedSearchTerm);
}
// export const stemmer = natural.PorterStemmer;
// // To limit the AI running all the time, look for info requests or commands
export const keyTriggerAIWords = [
"report",
"list",
"search",
"have",
"also",
"are",
"whats",
"bot",
"please",
"are there",
"is there",
"show",
"display",
"post",
"print",
"this is",
"this will be",
"store",
"remind",
"know",
"understand",
"save",
"update",
"delete",
"remember",
"remind",
"db",
"set",
"will be",
"tell me",
"going to be",
"announce",
"inform",
"instruct",
"let people know",
"add",
"create",
"merge",
"remove",
"edit",
"change",
"how",
"where",
"what",
"who",
"find",
"when",
"why",
"bug",
"error",
"issue",
"problem",
"fix",
"help",
"support",
"assist",
"troubleshoot",
"lost",
"anyone",
"information",
"hello",
"name is",
"about",
"i am",
"i m",
"what s",
// "will have",
// "are going to have",
"thrive",
"thrivetogether",
"thrive together",
];
// .map((word) =>
// word
// .split(/\W+/)
// .map((word) => stemmer.stem(word))
// .join(" ")
// );
// const regexTest = new RegExp(
// "\\b(" + keyTriggerAIWords.join("|") + ")\\b",
// "i"
// );
// map into regex expression with a list to match