コード例 #1
0
  public double getPossibility(int key, int prev, int cur) {
    double result = 0;

    int curIndex = Utility.binarySearch(cur, symbolTable);
    int prevIndex = Utility.binarySearch(prev, symbolTable);

    TagContext tc = getItem(key);

    // return a lower value, not 0 to prevent data sparse
    if (tc == null
        || curIndex == -1
        || prevIndex == -1
        || tc.getContextArray()[prevIndex][curIndex] == 0
        || tc.getTagFreq()[prevIndex] == 0) return 0.000001;

    int prevCurConFreq = tc.getContextArray()[prevIndex][curIndex];
    int prevFreq = tc.getTagFreq()[prevIndex];

    // 0.9 and 0.1 is a value based experience
    result = 0.9 * prevCurConFreq;
    result /= prevFreq;
    result += 0.1 * prevFreq / tc.getTotalFreq();

    return result;
  }
コード例 #2
0
  public int getFreq(int key, int symbol) {
    TagContext tc = getItem(key);
    if (tc == null) return 0;

    int index = Utility.binarySearch(symbol, symbolTable);
    if (index == -1) // error finding the symbol
    return 0;

    // Add the frequency
    int frequency = 0;
    if (tc.getTagFreq() != null) frequency = tc.getTagFreq()[index];
    return frequency;
  }