mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Merge branch 'master' of https://gitlab.com/YourFriendlyNeighborhoodDealer/question-node-server
This commit is contained in:
commit
ef7066474c
1 changed files with 34 additions and 10 deletions
44
merger.js
44
merger.js
|
@ -22,6 +22,10 @@
|
|||
// join json datas, or raw datas
|
||||
// or something else
|
||||
|
||||
const minMatchAmmount = 55;
|
||||
const minResultMatchPercent = 99;
|
||||
const lengthDiffMultiplier = 10;
|
||||
|
||||
class Question {
|
||||
constructor(q, a, i) {
|
||||
this.Q = q;
|
||||
|
@ -46,19 +50,39 @@ class Question {
|
|||
IsComplete() {
|
||||
return this.HasQuestion() && this.HasAnswer();
|
||||
}
|
||||
Compare(q2) {
|
||||
const qmatchpercent = Question.CompareString(this.Q, q2.Q);
|
||||
const amatchpercent = Question.CompareString(this.A, q2.A);
|
||||
if (this.I != undefined) {
|
||||
const imatchpercent = this.I == undefined ? Question.CompareString(this.I, q2.I) : 0;
|
||||
return (qmatchpercent + amatchpercent + imatchpercent) / 3;
|
||||
// TODO: TEST DIS
|
||||
Compare(q2, i) {
|
||||
if (typeof q2 == 'string') {
|
||||
var qmatchpercent = Question.CompareString(this.Q, q2);
|
||||
|
||||
if (i == undefined || i.length == 0)
|
||||
return qmatchpercent;
|
||||
else {
|
||||
if (this.HasImage()) {
|
||||
const imatchpercent = this.HasImage() ? Question.CompareString(this.I.join(" "), i.join(" ")) :
|
||||
0;
|
||||
return (qmatchpercent + imatchpercent) / 2;
|
||||
} else {
|
||||
qmatchpercent -= 30;
|
||||
if (qmatchpercent < 0)
|
||||
return 0;
|
||||
else
|
||||
return qmatchpercent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return (qmatchpercent + amatchpercent) / 2;
|
||||
const qmatchpercent = Question.CompareString(this.Q, q2.Q);
|
||||
const amatchpercent = Question.CompareString(this.A, q2.A);
|
||||
if (this.I != undefined) {
|
||||
const imatchpercent = this.I == undefined ? Question.CompareString(this.I.join(" "), q2.I.join(
|
||||
" ")) : 0;
|
||||
return (qmatchpercent + amatchpercent + imatchpercent) / 3;
|
||||
} else {
|
||||
return (qmatchpercent + amatchpercent) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
static CompareString(s1, s2) {
|
||||
//if (s1 == undefined || s2 == undefined)
|
||||
// return 0;
|
||||
s1 = SimplifyStringForComparison(s1).split(" ");
|
||||
s2 = SimplifyStringForComparison(s2).split(" ");
|
||||
var match = 0;
|
||||
|
@ -67,7 +91,7 @@ class Question {
|
|||
match++;
|
||||
var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
|
||||
var lengthDifference = Math.abs(s2.length - s1.length);
|
||||
percent -= lengthDifference * 3;
|
||||
percent -= lengthDifference * lengthDiffMultiplier;
|
||||
if (percent < 0)
|
||||
percent = 0;
|
||||
return percent;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue