Exemple #1
0
 private void populateMap() {
   for (Integer row : linePositions) {
     map.put(
         row,
         OCRUtilities.wordsPositions(
             image, row, letterInfo.getLetterSize(), letterInfo.getSpaceGap()));
   }
 }
Exemple #2
0
 public static Letter getLetter(char character) {
   for (Letter letter : Letter.values()) {
     if (letter.name().equalsIgnoreCase(String.valueOf(character))) {
       return letter;
     }
   }
   return null;
 }
Exemple #3
0
  public String convertToString() {
    StringBuilder builder = new StringBuilder();

    for (Letter letter : lettersOfWord) {
      builder.append(letter.getName());
    }

    return builder.toString();
  }
Exemple #4
0
  public int calculateWordPoints() {
    int points = 0;

    for (Letter letter : lettersOfWord) {
      points += letter.getLetterPoints();
    }

    return points;
  }
Exemple #5
0
  public static List<Character> convertFromLetterListToCharacterList(List<Letter> letterList) {
    List<Character> characterList = new ArrayList<Character>();

    for (Letter letter : letterList) {
      characterList.add(letter.getName());
    }

    return characterList;
  }
Exemple #6
0
  private static Letter getLetterByName(Character name, List<Letter> letterList) {

    for (Letter letter : letterList) {
      if (name.equals(letter.getName())) {
        return letter;
      }
    }

    return null;
  }
Exemple #7
0
  public Letter getLetterByName(Character name) {

    for (Letter letter : lettersOfWord) {

      if (letter.getName().equals(name)) {
        return letter;
      }
    }

    return null;
  }
Exemple #8
0
  public Double scoreString(String prefix) {
    Letter thisLetter = root;

    while (prefix.length() > 0) {
      Character thisChar = prefix.charAt(0);
      prefix = prefix.substring(1);

      if (!thisLetter.hasChild(thisChar)) {
        return new Double(0);
      } else {
        thisLetter = thisLetter.getChild(thisChar);
      }
    }
    return thisLetter.score().doubleValue();
  }
Exemple #9
0
  public boolean isWord(String word) {
    Letter thisLetter = root;

    while (word.length() > 0) {
      Character thisChar = word.charAt(0);
      word = word.substring(1);

      if (!thisLetter.hasChild(thisChar)) {
        return false;
      } else {
        thisLetter = thisLetter.getChild(thisChar);
      }
    }
    return thisLetter.isWord();
  }
Exemple #10
0
 public Text(BufferedImage image, Letter letterInformation) {
   this.letterInfo = letterInformation;
   this.image = image;
   linePositions = OCRUtilities.rowPositions(image, letterInformation.getSmallestSizeLetter());
   createMap();
   populateMap();
 }
Exemple #11
0
  /**
   * Create random word from dictionary, and take letters for it from given letter box.
   *
   * @param dictionary loaded dictionary
   * @param letterBox letter box
   * @return List<Letter> random word
   */
  public static Word getRandomWord(Dictionary dictionary, LetterBox letterBox) {
    List<Letter> wordLetters = new ArrayList<Letter>();

    String randomWord = dictionary.getRandomWord();

    for (Character name : randomWord.toCharArray()) {
      Letter letter = letterBox.getLetterByName(name);
      if (letter == null) {
        letter = wordLetters.get(wordLetters.indexOf(letter));
        wordLetters.add(new Letter(letter.getName(), letter.getLetterPoints()));
      } else {
        wordLetters.add(letter);
      }
    }

    return new Word(wordLetters);
  }
Exemple #12
0
  /**
   * Load letters from resource file. Load letter name, points of letter and letter quantity.
   *
   * @return List<Letter> loaded letters
   */
  public static List<Letter> loadLetterListFromResource() {

    List<Letter> letterList = new ArrayList<Letter>();

    Map<Character, Integer> letterPointMap = loadLetterProperties(LETTER_POINTS_FILE);
    Map<Character, Integer> letterQuantityMap = loadLetterProperties(LETTER_QUANTITY_FILE);

    for (Map.Entry<Character, Integer> letterPoint : letterPointMap.entrySet()) {
      Letter letter = new Letter(letterPoint.getKey(), letterPoint.getValue());

      int quantity = letterQuantityMap.get(letter.getName());
      for (int i = 0; i < quantity; i++) {
        letterList.add(letter);
      }
    }

    return letterList;
  }
Exemple #13
0
  private Letter buildTree(String dictionaryFile) {
    System.out.print("Building Dictionary Tree");
    Letter root = new Letter();

    try {
      BufferedReader dictionaryIn = new BufferedReader(new FileReader(dictionaryFile));

      while (dictionaryIn.ready()) {
        String s = dictionaryIn.readLine();
        if (Dictionary.validWord(s)) {
          root.processWord(s);
          stats.processWord(s);
        }
      }
    } catch (IOException e) {
      System.err.println("borked :D  " + e);
    }

    System.out.println("\t\t[OK]");
    return root;
  }
Exemple #14
0
  public void score(LetterGrid letters) {
    ArrayList<Letter> letter = new ArrayList<Letter>(Arrays.asList(letters.getLetters()));
    char[] word = this.word.toCharArray();

    score = 0;

    for (int i = 0; i < word.length; i++) {
      Letter best = null;

      for (Letter l : letter) {
        if (word[i] == l.getLetter()) {
          if (best == null || best.getScore() < l.getScore()) {
            best = l;
          }
        }
      }

      score += best.getScore();
      letter.remove(best);
    }
  }
Exemple #15
0
 /**
  * @param character
  * @return the value of the specified char.
  */
 public static int getLetterValue(char character) {
   final Letter letter = getLetter(character);
   return letter == null ? 1 : letter.getValue();
 }
Exemple #16
0
 public DecoratorLetter(Letter<?> letter, float cost) {
   super(letter.getSender(), letter.getReceiver(), letter, cost);
 }
 public static void main(String[] args) {
   Letter l = new Letter();
   l.c = 'a';
   f(l);
   System.out.println(l.c);
 }
  // This method gets called at 20tps whenever a map is in a players inventory. Bail out as quickly
  // as possible if we
  // shouldn't do anything with it.
  // https://bukkit.atlassian.net/browse/BUKKIT-476
  @Override
  public void render(MapView map, MapCanvas canvas, Player player) {
    if (map.getCenterX() == Courier.MAGIC_NUMBER
        && map.getId() != plugin.getCourierdb().getCourierMapId()) {
      // it's a Courier map in an ItemFrame. We get called when it's in a loaded chunk. Player
      // doesn't
      // even need to be near it. Performance issues galore ...
      Letter letter = plugin.getTracker().getLetter(map.getCenterZ());
      if (letter != null && letter.getDirty()) {
        plugin
            .getCConfig()
            .clog(
                Level.FINE,
                "Rendering a Courier ItemFrame Letter ("
                    + letter.getId()
                    + ") on Map ("
                    + map.getId()
                    + ")");
        for (int j = 0; j < CANVAS_HEIGHT; j++) {
          for (int i = 0; i < CANVAS_WIDTH; i++) {
            canvas.setPixel(i, j, clearImage[j * 128 + i]);
            //                        canvas.setPixel(i, j, MapPalette.TRANSPARENT);
            //                        canvas.setPixel(i, j, MapPalette.LIGHT_BROWN);
          }
        }

        int drawPos = HEADER_POS;

        if (letter.getHeader() != null) {
          canvas.drawText(
              0, MinecraftFont.Font.getHeight() * drawPos, MinecraftFont.Font, letter.getHeader());
          LetterRenderer.drawLine(
              canvas,
              10,
              MinecraftFont.Font.getHeight() * (drawPos + 1)
                  + (int) (MinecraftFont.Font.getHeight() * 0.4),
              CANVAS_WIDTH - 11,
              MapPalette.DARK_BROWN);
          drawPos = BODY_POS;
        }

        canvas.drawText(
            letter.getLeftMarkerPos(),
            MinecraftFont.Font.getHeight(),
            MinecraftFont.Font,
            letter.getLeftMarker());
        canvas.drawText(
            letter.getRightMarkerPos(),
            MinecraftFont.Font.getHeight(),
            MinecraftFont.Font,
            letter.getRightMarker());

        if (letter.getMessage() != null) {
          canvas.drawText(
              0,
              MinecraftFont.Font.getHeight() * drawPos,
              MinecraftFont.Font,
              Letter.MESSAGE_COLOR + letter.getMessage());
        }

        if (letter.getDisplayDate() != null) {
          canvas.drawText(
              letter.getDisplayDatePos(),
              0,
              MinecraftFont.Font,
              Letter.DATE_COLOR + letter.getDisplayDate());
        }
        letter.setDirty(false);
        player.sendMap(map);
      }
    }
  }
Exemple #19
0
  public static void main(String[] args) throws IOException {
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter printWriter = new PrintWriter(System.out);

    // reading dimensions
    StringTokenizer stk = new StringTokenizer(bufferedReader.readLine());
    int N = Integer.parseInt(stk.nextToken()), Q = Integer.parseInt(stk.nextToken());

    // reading given tree
    // and building the index
    char alphabet[] = new char[N];
    Letter letters[] = new Letter[N];
    bufferedReader.read(alphabet, 0, N);
    for (int i = 0; i < N; i++) {
      letters[i] = new Letter(alphabet[i]);
    }
    bufferedReader.readLine();

    for (int i = 0; i < N - 1; i++) {
      stk = new StringTokenizer(bufferedReader.readLine());
      Letter parent = letters[Integer.parseInt(stk.nextToken()) - 1];
      int j = Integer.parseInt(stk.nextToken());
      Letter child = letters[j - 1];

      // uniting duplicate children by the way
      if (parent.children[child.ch - 97] == null) {
        parent.children[child.ch - 97] = child;
      } else {
        letters[j - 1] = parent.children[child.ch - 97];
      }
    }

    // return value for K=1
    index.value = ' ';

    // generate all possible sub-strings
    for (int i = 0; i < N - 1; i++) {
      Letter letter = letters[i];
      if (!letter.visited) {
        letter.visited = true;

        Index subIndex = index.getElementOrCreate(letter.ch);
        long subSize = subIndex.size;

        subStringGenerator(subIndex, letter);

        index.size += subIndex.size - subSize;
      }
    }

    // printing total number of distinct substrings
    printWriter.println(index.size);

    // printing answers string by string
    char[] order = new char[26];
    for (int i = 0; i < Q; i++) {
      bufferedReader.read(order, 0, 26);

      int K = Integer.parseInt(bufferedReader.readLine().substring(1));
      if (K > index.size) {
        printWriter.println("-1");
        continue;
      }

      String stepAnswer = getString(index, order, K);
      printWriter.println(stepAnswer);
    }

    printWriter.flush();
  }
 static void f(Letter y) {
   y.c = 'z';
 }