Voytek's Recent Forum Activity

  • [SOLVED] Can someone demonstrate how Levenshtein distance can be translated into Construct 2?

    What i want to achieve is the following:

    1. I would like to have an array of sentences.

    2. The user is supposed to enter one sentence, one at a time, and this sentence is meant to be compared with a correspoding model sentence stored in the array. No need to search through.

    3. It is anticipated that the user will make some typos while entering the sentence. i want to allow such mistakes to happen like this:

    Model sentence: "This text is awesome"

    User input: "This next is awesome"

    Result: comparison accepted.

    It would be good if i could set the comparison threshold.

    Taking all of the above into consideration, i have stumpled upon multiple times on this code below. I believe it could do what i want. Sadly i am not smart enough to translate it into construct 2. Can someone do it and help me achieve the goal described above?

    // Compute the edit distance between the two given strings

    exports.getEditDistance = function(a, b){

    if(a.length == 0) return b.length;

    if(b.length == 0) return a.length;

    var matrix = [];

    // increment along the first column of each row

    var i;

    for(i = 0; i <= b.length; i++){

    matrix = ;

    }

    // increment each column in the first row

    var j;

    for(j = 0; j <= a.length; j++){

    matrix[0][j] = j;

    }

    // Fill in the rest of the matrix

    for(i = 1; i <= b.length; i++){

    for(j = 1; j <= a.length; j++){

    if(b.charAt(i-1) == a.charAt(j-1)){

    matrix[j] = matrix[i-1][j-1];

    } else {

    matrix[j] = Math.min(matrix[i-1][j-1] + 1, // substitution

    Math.min(matrix[j-1] + 1, // insertion

    matrix[i-1][j] + 1)); // deletion

    }

    }

    }

    return matrix[b.length][a.length];

    };

    source page of the code: gist.github.com/andrei-m/982927

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks Chad for all your effort and the caps. At the moment of writing this reply i have not viewed them yet but i definitely will. Good luck on your exams! Up unti now, I have been trying to implement Animmaniac's suggestion. Unfortunately what i managed to come up with is pretty miserable. I could not turn the code into "neat loops" and i cannot imagine how i could possibly come up with all the possibilities of user typos in the "pre-processing" procedure.

    Here is my "production":

    Could anyone improve the code, help me learn as well as get this thing done while following Animmaniac's suggestion?

    One question is bugging me a lot, namely: how to divide the user input into the pairs to compare? I assume that user input is stored in the Array2. I hope i did not get what Animmaniac suggested at the wrong end. Anyway I am sorry if anything i have done/written is retarded. I am just an aspiring programmer.

  • Thanks Chad for your reply, i really appreciate it!

    With reference to: "Well, I think what you are trying to achieve here is a game that analyzes the user inputs if they have a typo and the input is close to the required text then it will accept it." Yes! this is exactly what i am aiming at. You are on the same wavelength with me on this.

    With reference to: "If you are asking for a .capx file, I'll be glad to make it for you, just say the word." Yes, I am humbly asking for the .capx file. I will do my research on the methods suggested by you but having a solution handed would make me sleep better Therefore, I will greately appreciate your .capx contribution. I am only a strong beginner in javascript programming and in construct 2 programming as well. It will be something new to learn for me. Thank you in advance.

    By the way, i have anticipated someone suggesting using so called "regular expressions" and i am moderately happy there is something neater than getting my head around the "elusive" regex.

    I am looking forward to your next relpy!

  • Is there a way to compare two String values in the form of sentences so that the end result of comparison would accept "natural" typos or some typos within some measure like this?

    Model string stored in the game code: "I like cats"

    User input: "I like vats"

    End result: comparison accepts user's typo. Eventually there is a match.

    I would like to make a game with a lot of sentences like this. I hope there is a way to achieve this as easily as possible. Please help, i think this is a tricky one :/

Voytek's avatar

Voytek

Member since 19 Jul, 2016

None one is following Voytek yet!

Trophy Case

  • 8-Year Club
  • RTFM Read the fabulous manual
  • Email Verified

Progress

10/44
How to earn trophies