Brord icon

v1 of checksentence

Brord | PRO | 07/12/18 04:25:12 PM UTC | 0 ⭐ | 466 👁️ | Never ⏰ | []
text |

1.97 KB

|

None

|

0 👍

/

0 👎

allWordsCorrect
-> missing accent? -.1
-> 1 letter missing? -.2
--> More then one? 0
 CheckSentence(allowMargin = 0){
     errors: []
    sentence = _.lowerCase(_.deburr(originaSentence));
     i = 0;
    each word of sentence(){
        planeWord = _.deburr(word)
         //Does the word exist in the sentence?
        probablyWord = findMostLikeyWord(planeWord, sentence, originaSentence)
         //Doesnt exist
        if (!probablyWord) {\
            !allowMargin -> i++
            continue;
            errors.push({word: word, [{error: "Doesnt exist", subtract: 5}], position: i})
        }
         //We must have the word, Where is it?
        position = findPosition(probablyWord, sentence)
         //We already have used the word (Probably was typed more then once in the sentence)
        //For example: The word "the" is once in a sentence, but typed twice. 
        // Second time, position === 0 because we removed it from the list
        position === 0 {
            !allowMargin -> i++
            errors.push({word: word, error: [{"Duplicate", subtract: 3}], position: i})
            continue;
        }
         let wordErrors = [];
        //Exists, different place
        i !== position {
            !allowMargin || (abs position - i) > allowMargin) {
                if (!allowMargin) i++
                //50% off for good word, but wrong position
                wordErrors.push({word: word, [{error: "Wrong position", score: 50});
            }
        }
         i++;
        //Word seems to be on the correct-ish place, lets check the word itself!
         let wordErrors = CheckWord().concat(wordErrors);
        if (wordErrors.length > 0){
            errors.push({word: word, wordErrors, position: i})
        } else {
            //Correct word, correct place, huray!
        }
    }
}
 CheckWord(){
-> missing accent? -.1
-> 1 letter missing? -.2
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎