Example #1
1
  public static Hashtable findConfidence(Hashtable table) {
    Hashtable confidences = new Hashtable();
    Iterator key_iter = table.keySet().iterator();
    while (key_iter.hasNext()) {
      // System.out.println("here");
      ArrayList<Integer> combo = (ArrayList<Integer>) key_iter.next();
      // System.out.println("current combo"+combo);
      if (combo.size() >= 2) {
        ArrayList<Integer> current_combo =
            new ArrayList<Integer>(combo.subList(0, combo.size() - 1));
        ArrayList<Integer> last_combo =
            new ArrayList<Integer>(combo.subList(combo.size() - 1, combo.size()));
        /*System.out.println(combo);
        System.out.println(current_combo);
        System.out.println(last_combo);
        System.out.println(table.get(current_combo));*/

        if (table.get(current_combo) != null) {
          // System.out.println("it contains!");
          int first = (Integer) table.get(current_combo);
          int second = (Integer) table.get(combo);
          double dub_first = (double) first;
          double dub_second = (double) second;
          double combo_conf = dub_second / dub_first;
          confidences.put(combo, combo_conf);
          // System.out.println("combo:"+combo+" has the confience: "+combo_conf);
        }
      }
    }
    // System.out.println(confidences+"O");

    return confidences;
  }
Example #2
0
  /**
   * Creates new JShell instance and runs the Shell.
   *
   * @param args not used.
   */
  public static void main(String[] args) {
    String filename = "JShell.ser";
    JShell newShell = loadJShell(filename);

    if (newShell == null) {
      newShell = new JShell();
    }
    newShell.printPrompt();
    ArrayList<String> input = newShell.readInput();
    while (input.isEmpty() || !"exit".equals(input.get(0))) {
      if (!input.isEmpty()) {
        List<String> params = newShell.handleRedirection(input.subList(1, input.size()));
        newShell.executeCommand(input.get(0).toString(), params);
      }
      newShell.printPrompt();
      input = newShell.readInput();
    }
    filename = "JShell.ser";
    newShell.saveJShell(filename);
  }
Example #3
0
  public void initialiseWithLines(ArrayList<StringBuilder> lines, ProcessingOptions options)
      throws UnsupportedEncodingException {

    // remove blank rows at the bottom
    boolean done = false;
    int i;
    for (i = lines.size() - 1; i >= 0 && !done; i--) {
      StringBuilder row = lines.get(i);
      if (!StringUtils.isBlank(row.toString())) done = true;
    }
    rows = new ArrayList<StringBuilder>(lines.subList(0, i + 2));

    if (options != null) fixTabs(options.getTabSize());
    else fixTabs(ProcessingOptions.DEFAULT_TAB_SIZE);

    // make all lines of equal length
    // add blank outline around the buffer to prevent fill glitch
    // convert tabs to spaces (or remove them if setting is 0)

    int blankBorderSize = 2;

    int maxLength = 0;
    int index = 0;

    String encoding = null;
    if (options != null) encoding = options.getCharacterEncoding();

    Iterator<StringBuilder> it = rows.iterator();
    while (it.hasNext()) {
      String row = it.next().toString();
      if (encoding != null) {
        byte[] bytes = row.getBytes();
        row = new String(bytes, encoding);
      }
      if (row.length() > maxLength) maxLength = row.length();
      rows.set(index, new StringBuilder(row));
      index++;
    }

    it = rows.iterator();
    ArrayList<StringBuilder> newRows = new ArrayList<StringBuilder>();
    // TODO: make the following depend on blankBorderSize

    StringBuilder topBottomRow =
        new StringBuilder(StringUtils.repeatString(" ", maxLength + blankBorderSize * 2));

    newRows.add(topBottomRow);
    newRows.add(topBottomRow);
    while (it.hasNext()) {
      StringBuilder row = it.next();

      if (row.length() < maxLength) {
        String borderString = StringUtils.repeatString(" ", blankBorderSize);
        StringBuilder newRow = new StringBuilder();

        newRow.append(borderString);
        newRow.append(row);
        newRow.append(StringUtils.repeatString(" ", maxLength - row.length()));
        newRow.append(borderString);

        newRows.add(newRow);
      } else { // TODO: why is the following line like that?
        newRows.add(new StringBuilder("  ").append(row).append("  "));
      }
    }
    // TODO: make the following depend on blankBorderSize
    newRows.add(topBottomRow);
    newRows.add(topBottomRow);
    rows = newRows;

    replaceBullets();
    replaceHumanColorCodes();
  }