-4

I'm making a chat-bot, which will answer you by nearest value in dataset (treemaps). System is analog of AIML.

I need to make Winkler-table, which will give me array of result numbers. How to do that?

There is an image, which show how this table works: WINKLER TABLE

nesclass
  • 27
  • 4
  • 5
    You forgot to ask a question. – Guy Dec 06 '18 at 09:49
  • Sorry, changed. – nesclass Dec 06 '18 at 09:51
  • It looks obvious. On what stage you have problem? Can you show what you tried? – talex Dec 06 '18 at 09:53
  • *How to do that?* is not much of a question. You need to try doing it yourself and come back with what you have tried and explain what was the problem with it. – Guy Dec 06 '18 at 09:53
  • I just don't know how to do that, and post ask here to get an solution. – nesclass Dec 06 '18 at 09:55
  • Since this is quite a trivial question for any java programmer, it's clear that the OP doesn't know any java at all. I've at least given a few pointers without actually writing the code. – herman Dec 06 '18 at 10:19

2 Answers2

0

You can do it in 3 easy steps.

  1. Create a 2 dimensional array for the result matrix: see question Syntax for creating a two-dimensional array.

    Dimensions will have to match the input and key lengths of course. See https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#length().

  2. Loop over the characters of the input string, and the key as a nested loop. See https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.14.1 and https://docs.oracle.com/javase/10/docs/api/java/lang/String.html#charAt(int). Basically you have 2 indices which give you 2 char values.

  3. Compare both characters using the == operator and store 0 or 1 in the two-dimensional array using the indices.

herman
  • 11,740
  • 5
  • 47
  • 58
0

Okey, i made that table. It looks like next:

String[] ts = new String[s2.length()];

int[][] table = new int[s1.length()][s2.length()];
char[] s1c = s1.toCharArray();
char[] s2c = s2.toCharArray();

for(int s1cl = 0; s1cl <= s1c.length - 1; s1cl++) {
    for(int s2cl = 0; s2cl <= s2c.length - 1; s2cl++) {
        if(s1c[s1cl] == s2c[s2cl]) {
            table[s1cl][s2cl] = 0;
        } else {
            table[s1cl][s2cl] = 1;
        }
    }
}

for(int ts1 = 0; ts1 <= s1c.length - 1; ts1++) {
    String res = "";
    for(int ts2 = 0; ts2 <= s2c.length - 1; ts2++) {
        res += ts2;
        if(ts2 == s2c.length - 1) {
            ts[ts1] = res;
            res = "";
        }
    }
}

Thanks "herman" for your answer!

nesclass
  • 27
  • 4