From d1074376ea96b2530496e6993c3282b3d33c5830 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Sun, 11 Jul 2021 12:15:56 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactoring=20the=20algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/shared/utils/nlp.utils.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/client/shared/utils/nlp.utils.ts b/src/client/shared/utils/nlp.utils.ts index f620815..8d74f8d 100644 --- a/src/client/shared/utils/nlp.utils.ts +++ b/src/client/shared/utils/nlp.utils.ts @@ -58,11 +58,6 @@ export const preprocess = (inputString: string) => { ); }; -const recursivelyMatch = (regex, inputString) => { - const toReplace = xregexp.replace(inputString, regex, ""); - return toReplace; -}; - /** * Tokenizes a search string * @function @@ -75,24 +70,27 @@ export const tokenize = (inputString: string) => { // regexes to match constituent parts of the search string // and isolate the search terms - + const foo = replaceRecursive( + "jagan sampatkar ((((asdasd)(Asdasd)(3019)))) (123) milun", + "\\(", + "\\)", + (match) => "", + ); + console.log(foo); const chapters = inputString.replace( /ch(a?p?t?e?r?)(\W?)(\_?)(\#?)(\d)/gi, "", ); const volumes = inputString.replace( /(\b(vo?l?u?m?e?)\.?)(\s*-|\s*_)?(\s*[0-9]+[.0-9a-z]*)/gi, + "", ); const pageCounts = inputString.match( /\b[.,]?\s*\d+\s*(p|pg|pgs|pages)\b\s*/gi, ); const parantheses = inputString.match(/\([^\(]*?\)/gi); - const foo = recursivelyMatch( - new RegExp(/\([^\(]*?\)/, "gi"), - "jagan milun sampatkar ((asdasd)(ASDASD)(sadasd))", - ); - console.log(foo); + const curlyBraces = inputString.match(/\{[^\{]*?\}/gi); const squareBrackets = inputString.match(/\[[^\[]*?\]/gi); const genericNumericRange = inputString.match(