// here codes represents codes for word1
 private int calculateSimilarity(WordComposer composer, CharSequence word2) {
   int score = 0;
   CharSequence word1 = composer.getTypedWord();
   int length = word1.length() < word2.length() ? word1.length() : word2.length();
   for (int i = 0; i < length; i++) {
     char c1 = word1.charAt(i);
     char c2 = word2.charAt(i);
     if (c1 == c2) {
       score++;
     } else {
       // check code similarity?
       int[] codes = composer.getCodesAt(i);
       for (int code : codes) {
         if ((char) code == c2) {
           score++;
         }
       }
     }
   }
   if (word1.charAt(word1.length() - 1) == word2.charAt(word2.length() - 1)) {
     score += 3;
   }
   score -= Math.abs(word2.length() - word1.length()) / 2;
   return score;
 }