From 5f12284bb82b0e044223c4a05981638dab8f23bd Mon Sep 17 00:00:00 2001 From: mrfry Date: Mon, 21 Feb 2022 20:43:52 +0100 Subject: [PATCH] Checking possible answers in /ask --- .gitignore | 1 + src/types/basicTypes.ts | 6 ++++++ src/utils/classes.ts | 44 ++++++++++++++++++++++++++++++++++++++++- submodules/qmining-page | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d272e6c..db5cef4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ src/extraModules/ duplicateRemovingLog/ src/extraModules /*.sh +extraSubmodules diff --git a/src/types/basicTypes.ts b/src/types/basicTypes.ts index fe75332..64cb794 100644 --- a/src/types/basicTypes.ts +++ b/src/types/basicTypes.ts @@ -4,6 +4,12 @@ export interface QuestionData { type: string images?: Array hashedImages?: Array + possibleAnswers?: + | Array + | Array<{ + text: string + selectedByUser: boolean + }> } export interface Question { diff --git a/src/utils/classes.ts b/src/utils/classes.ts index 28f76bb..1f9e1a3 100755 --- a/src/utils/classes.ts +++ b/src/utils/classes.ts @@ -39,6 +39,7 @@ const commonUselessAnswerParts = [ // const commonUselessStringParts = [',', '\\.', ':', '!', '\\+', '\\s*\\.'] /* Percent minus for length difference */ const lengthDiffMultiplier = 10 +const noPossibleAnswerMatchPenalty = 5 /* Minimum ammount to consider that two questions match during answering */ const minMatchAmmount = 75 const magicNumber = 0.7 // same as minMatchAmmount, but /100 @@ -467,7 +468,7 @@ function addQuestion( function prepareQuestion( question: string | Question, data: string | QuestionData -): Question { +): any { let preparedQuestion: Question if (typeof question === 'object') { @@ -567,6 +568,11 @@ function doSearch( } } + result = setNoPossibleAnswersPenalties( + questionToSearch.possibleAnswers, + result + ) + result = result.sort((q1, q2) => { if (q1.match < q2.match) { return 1 @@ -580,6 +586,42 @@ function doSearch( return result } +function setNoPossibleAnswersPenalties( + possibleAnswers: any, + result: any[] +): any { + if (!Array.isArray(possibleAnswers)) { + return result + } + const noneHasPossibleAnswers = result.every((x) => { + return !Array.isArray(x.q.data.possibleAnswers) + }) + if (noneHasPossibleAnswers) return result + + let possibleAnswerMatch = false + const updated = result.map((result) => { + const hasMatch = result.q.data.possibleAnswers.some((possibleAnswer) => { + return possibleAnswers.some((questionPossibleAnswer) => { + return questionPossibleAnswer.includes(questionPossibleAnswer) + }) + }) + if (hasMatch) { + possibleAnswerMatch = true + } else { + result.match = result.match - noPossibleAnswerMatchPenalty + result.detailedMatch.qMatch = + result.detailedMatch.qMatch - noPossibleAnswerMatchPenalty + } + return result + }) + + if (possibleAnswerMatch) { + return updated + } else { + return result + } +} + // --------------------------------------------------------------------------------------------------------- // Multi threaded stuff // --------------------------------------------------------------------------------------------------------- diff --git a/submodules/qmining-page b/submodules/qmining-page index 2b491e6..57a7ab9 160000 --- a/submodules/qmining-page +++ b/submodules/qmining-page @@ -1 +1 @@ -Subproject commit 2b491e6bec6eee78400e3e042418def12df3243f +Subproject commit 57a7ab9fb7e6148e488cc492a8d8fb55de211bf6