Merger comparing update

This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-03-08 13:32:24 +01:00
parent fda034da76
commit 26eed45b08

View file

@ -22,6 +22,10 @@
// join json datas, or raw datas // join json datas, or raw datas
// or something else // or something else
const minMatchAmmount = 55;
const minResultMatchPercent = 99;
const lengthDiffMultiplier = 10;
class Question { class Question {
constructor(q, a, i) { constructor(q, a, i) {
this.Q = q; this.Q = q;
@ -46,19 +50,39 @@ class Question {
IsComplete() { IsComplete() {
return this.HasQuestion() && this.HasAnswer(); return this.HasQuestion() && this.HasAnswer();
} }
Compare(q2) { // 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 {
const qmatchpercent = Question.CompareString(this.Q, q2.Q); const qmatchpercent = Question.CompareString(this.Q, q2.Q);
const amatchpercent = Question.CompareString(this.A, q2.A); const amatchpercent = Question.CompareString(this.A, q2.A);
if (this.I != undefined) { if (this.I != undefined) {
const imatchpercent = this.I == undefined ? Question.CompareString(this.I, q2.I) : 0; const imatchpercent = this.I == undefined ? Question.CompareString(this.I.join(" "), q2.I.join(
" ")) : 0;
return (qmatchpercent + amatchpercent + imatchpercent) / 3; return (qmatchpercent + amatchpercent + imatchpercent) / 3;
} else { } else {
return (qmatchpercent + amatchpercent) / 2; return (qmatchpercent + amatchpercent) / 2;
} }
} }
}
static CompareString(s1, s2) { static CompareString(s1, s2) {
//if (s1 == undefined || s2 == undefined)
// return 0;
s1 = SimplifyStringForComparison(s1).split(" "); s1 = SimplifyStringForComparison(s1).split(" ");
s2 = SimplifyStringForComparison(s2).split(" "); s2 = SimplifyStringForComparison(s2).split(" ");
var match = 0; var match = 0;
@ -67,7 +91,7 @@ class Question {
match++; match++;
var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
var lengthDifference = Math.abs(s2.length - s1.length); var lengthDifference = Math.abs(s2.length - s1.length);
percent -= lengthDifference * 3; percent -= lengthDifference * lengthDiffMultiplier;
if (percent < 0) if (percent < 0)
percent = 0; percent = 0;
return percent; return percent;