Advertisement
Brord

v1 of checksentence

Jul 12th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. allWordsCorrect
  2. -> missing accent? -.1
  3. -> 1 letter missing? -.2
  4. --> More then one? 0
  5.  
  6. CheckSentence(allowMargin = 0){
  7.  
  8. errors: []
  9. sentence = _.lowerCase(_.deburr(originaSentence));
  10.  
  11. i = 0;
  12. each word of sentence(){
  13. planeWord = _.deburr(word)
  14.  
  15. //Does the word exist in the sentence?
  16. probablyWord = findMostLikeyWord(planeWord, sentence, originaSentence)
  17.  
  18. //Doesnt exist
  19. if (!probablyWord) {\
  20. !allowMargin -> i++
  21. continue;
  22. errors.push({word: word, [{error: "Doesnt exist", subtract: 5}], position: i})
  23. }
  24.  
  25. //We must have the word, Where is it?
  26. position = findPosition(probablyWord, sentence)
  27.  
  28. //We already have used the word (Probably was typed more then once in the sentence)
  29. //For example: The word "the" is once in a sentence, but typed twice.
  30. // Second time, position === 0 because we removed it from the list
  31. position === 0 {
  32. !allowMargin -> i++
  33. errors.push({word: word, error: [{"Duplicate", subtract: 3}], position: i})
  34. continue;
  35. }
  36.  
  37. let wordErrors = [];
  38. //Exists, different place
  39. i !== position {
  40. !allowMargin || (abs position - i) > allowMargin) {
  41. if (!allowMargin) i++
  42. //50% off for good word, but wrong position
  43. wordErrors.push({word: word, [{error: "Wrong position", score: 50});
  44. }
  45. }
  46.  
  47. i++;
  48. //Word seems to be on the correct-ish place, lets check the word itself!
  49.  
  50. let wordErrors = CheckWord().concat(wordErrors);
  51. if (wordErrors.length > 0){
  52. errors.push({word: word, wordErrors, position: i})
  53. } else {
  54. //Correct word, correct place, huray!
  55. }
  56. }
  57. }
  58.  
  59. CheckWord(){
  60. -> missing accent? -.1
  61. -> 1 letter missing? -.2
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement