Skip to content

Commit

Permalink
fix: Add regex for ug/pg string matches
Browse files Browse the repository at this point in the history
  • Loading branch information
devadathanmb committed Jan 19, 2024
1 parent 2346c12 commit 9c60053
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
43 changes: 29 additions & 14 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,35 @@ const ACADEMIC_CALENDAR_URL =
const TIMETABLE_URL =
"https://api.ktu.edu.in/ktu-web-portal-api/anon/timetable";

const FILTERS_REGEX: Record<string, string> = {
"\\bb\\.? ?tech": "btech",
"\\bm\\.? ?tech": "mtech",
"\\bmca\\b": "mca",
"\\bphd\\b": "phd",
"\\bb\\.? ?des": "bdes",
"\\bmba\\b": "mba",
"\\bb\\. ?arch": "barch",
"\\bm\\.? ?arch": "march",
"\\bb\\.? ?voc": "bvoc",
"\\bm\\.? ?plan": "mplan",
"hotel management": "hmct",
"\\bbhmct": "hmct",
"\\bmhm\\b": "mhm",
const FILTERS_REGEX: Record<string, Array<string>> = {
"\\bb\\.? ?tech": ["btech"],
"\\bm\\.? ?tech": ["mtech"],
"\\bmca\\b": ["mca"],
"\\bphd\\b": ["phd"],
"\\bb\\.? ?des": ["bdes"],
"\\bmba\\b": ["mba"],
"\\bb\\. ?arch": ["barch"],
"\\bm\\.? ?arch": ["march"],
"\\bb\\.? ?voc": ["bvoc"],
"\\bm\\.? ?plan": ["mplan"],
"hotel management": ["hmct"],
"\\bbhmct": ["hmct"],
"\\bmhm\\b": ["mhm"],
"(\\bug\\b)|(\\bundergraduate\\b)": [
"btech",
"bdes",
"barch",
"bvoc",
"hmct",
],
"(\\bpg\\b)|(\\bpostgraduate\\b)": [
"mtech",
"mca",
"mba",
"march",
"mplan",
"mhm",
],
};

const FILTERS: Record<string, string> = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/findFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function findFilters(msg: string): Array<string> {

Object.keys(FILTERS_REGEX).forEach((filter) => {
if (lowerCaseMsg.search(new RegExp(filter)) !== -1) {
matchedFilters.push(FILTERS_REGEX[filter]);
matchedFilters.push(...FILTERS_REGEX[filter]);
}
});

Expand Down

0 comments on commit 9c60053

Please sign in to comment.