mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Checking possible answers in /ask
This commit is contained in:
parent
799930b3e1
commit
5f12284bb8
4 changed files with 51 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ src/extraModules/
|
||||||
duplicateRemovingLog/
|
duplicateRemovingLog/
|
||||||
src/extraModules
|
src/extraModules
|
||||||
/*.sh
|
/*.sh
|
||||||
|
extraSubmodules
|
||||||
|
|
|
@ -4,6 +4,12 @@ export interface QuestionData {
|
||||||
type: string
|
type: string
|
||||||
images?: Array<string>
|
images?: Array<string>
|
||||||
hashedImages?: Array<string>
|
hashedImages?: Array<string>
|
||||||
|
possibleAnswers?:
|
||||||
|
| Array<string>
|
||||||
|
| Array<{
|
||||||
|
text: string
|
||||||
|
selectedByUser: boolean
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Question {
|
export interface Question {
|
||||||
|
|
|
@ -39,6 +39,7 @@ const commonUselessAnswerParts = [
|
||||||
// const commonUselessStringParts = [',', '\\.', ':', '!', '\\+', '\\s*\\.']
|
// const commonUselessStringParts = [',', '\\.', ':', '!', '\\+', '\\s*\\.']
|
||||||
/* Percent minus for length difference */
|
/* Percent minus for length difference */
|
||||||
const lengthDiffMultiplier = 10
|
const lengthDiffMultiplier = 10
|
||||||
|
const noPossibleAnswerMatchPenalty = 5
|
||||||
/* Minimum ammount to consider that two questions match during answering */
|
/* Minimum ammount to consider that two questions match during answering */
|
||||||
const minMatchAmmount = 75
|
const minMatchAmmount = 75
|
||||||
const magicNumber = 0.7 // same as minMatchAmmount, but /100
|
const magicNumber = 0.7 // same as minMatchAmmount, but /100
|
||||||
|
@ -467,7 +468,7 @@ function addQuestion(
|
||||||
function prepareQuestion(
|
function prepareQuestion(
|
||||||
question: string | Question,
|
question: string | Question,
|
||||||
data: string | QuestionData
|
data: string | QuestionData
|
||||||
): Question {
|
): any {
|
||||||
let preparedQuestion: Question
|
let preparedQuestion: Question
|
||||||
|
|
||||||
if (typeof question === 'object') {
|
if (typeof question === 'object') {
|
||||||
|
@ -567,6 +568,11 @@ function doSearch(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = setNoPossibleAnswersPenalties(
|
||||||
|
questionToSearch.possibleAnswers,
|
||||||
|
result
|
||||||
|
)
|
||||||
|
|
||||||
result = result.sort((q1, q2) => {
|
result = result.sort((q1, q2) => {
|
||||||
if (q1.match < q2.match) {
|
if (q1.match < q2.match) {
|
||||||
return 1
|
return 1
|
||||||
|
@ -580,6 +586,42 @@ function doSearch(
|
||||||
return result
|
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
|
// Multi threaded stuff
|
||||||
// ---------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2b491e6bec6eee78400e3e042418def12df3243f
|
Subproject commit 57a7ab9fb7e6148e488cc492a8d8fb55de211bf6
|
Loading…
Add table
Add a link
Reference in a new issue