mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
String processing polishing
This commit is contained in:
parent
2d0b496f27
commit
d3c93c5b99
2 changed files with 32 additions and 14 deletions
41
main.js
41
main.js
|
@ -34,7 +34,7 @@ function info () { return GM_info }
|
|||
|
||||
var data // all data, which is in the resource txt
|
||||
var addEventListener // add event listener function
|
||||
const lastChangeLog = 'Félév szerinti csoportosítás menüben'
|
||||
const lastChangeLog = 'Kérdés parsolás bugfixek, old school fálj beolvasás kiszedése, részletesebb hibajelentés és egyéb fixek'
|
||||
const serverAdress = 'https://qmining.frylabs.net/'
|
||||
|
||||
// forcing pages for testing. unless you test, do not set these to true!
|
||||
|
@ -60,7 +60,9 @@ const commonUselessAnswerParts = [
|
|||
'A helyes válasz az ',
|
||||
'A helyes válasz a ',
|
||||
'A helyes válaszok: ',
|
||||
'A helyes válaszok:',
|
||||
'A helyes válasz: ',
|
||||
'A helyes válasz:',
|
||||
'The correct answer is:',
|
||||
'\''
|
||||
]
|
||||
|
@ -152,6 +154,10 @@ class StringUtils {
|
|||
assert(s1)
|
||||
assert(s2)
|
||||
|
||||
if (s1 === '' || s2 === '') {
|
||||
return 0
|
||||
}
|
||||
|
||||
s1 = this.SimplifyStringForComparison(s1).split(' ')
|
||||
s2 = this.SimplifyStringForComparison(s2).split(' ')
|
||||
var match = 0
|
||||
|
@ -165,7 +171,7 @@ class StringUtils {
|
|||
return percent
|
||||
}
|
||||
|
||||
QuestionPreProcessor (value) {
|
||||
AnswerPreProcessor (value) {
|
||||
assert(value)
|
||||
|
||||
return this.RemoveStuff(
|
||||
|
@ -184,16 +190,9 @@ class StringUtils {
|
|||
}
|
||||
}
|
||||
|
||||
SimplifyQuestion (value) {
|
||||
SimplifyQA (value, mods) {
|
||||
if (!value) { return }
|
||||
|
||||
let mods = [
|
||||
this.RemoveSpecialChars.bind(this),
|
||||
this.RemoveUnnecesarySpaces.bind(this),
|
||||
this.QuestionPreProcessor.bind(this),
|
||||
this.RemoveAnswerLetters.bind(this)
|
||||
]
|
||||
|
||||
const reducer = (res, fn) => {
|
||||
return fn(res)
|
||||
}
|
||||
|
@ -201,6 +200,26 @@ class StringUtils {
|
|||
return mods.reduce(reducer, value)
|
||||
}
|
||||
|
||||
SimplifyAnswer (value) {
|
||||
return this.SimplifyQA(
|
||||
value,
|
||||
[
|
||||
this.RemoveSpecialChars.bind(this),
|
||||
this.RemoveUnnecesarySpaces.bind(this),
|
||||
this.AnswerPreProcessor.bind(this),
|
||||
this.RemoveAnswerLetters.bind(this)
|
||||
])
|
||||
}
|
||||
|
||||
SimplifyQuestion (value) {
|
||||
return this.SimplifyQA(
|
||||
value,
|
||||
[
|
||||
this.RemoveSpecialChars.bind(this),
|
||||
this.RemoveUnnecesarySpaces.bind(this)
|
||||
])
|
||||
}
|
||||
|
||||
SimplifyStack (stack) {
|
||||
stack = this.SimplifyQuery(stack)
|
||||
let ns = ''
|
||||
|
@ -225,7 +244,7 @@ class StringUtils {
|
|||
class Question {
|
||||
constructor (q, a, i) {
|
||||
this.Q = SUtils.SimplifyQuestion(q)
|
||||
this.A = SUtils.SimplifyQuestion(a)
|
||||
this.A = SUtils.SimplifyAnswer(a)
|
||||
this.I = i
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue