Java Code Examples for gnu.trove.iterator.TObjectIntIterator#key()

The following examples show how to use gnu.trove.iterator.TObjectIntIterator#key() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Term.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/**
 * PUBLIC: Returns the preferred variant of the term. This is a form
 * of the term which actually occurred in the classified content.
 */
public String getPreferredName() {
  if (variants.isEmpty())
    return getStem();
  Variant maxKey = null;
  int maxValue = -1;
  TObjectIntIterator<Variant> iter = variants.iterator();
  while (iter.hasNext()) {
    iter.advance();
    int thisValue = iter.value();
    Variant thisKey = iter.key();
    // select variant with most occurrences, or lowest lexical value if equal for predictability
    if ((thisValue > maxValue) ||
        ((thisValue == maxValue) && (thisKey.getValue().compareTo(maxKey.getValue()) < 0))) {
      maxValue = thisValue;
      maxKey = thisKey;
    }
  }
  return maxKey.getValue();
}
 
Example 2
Source File: Term.java    From ontopia with Apache License 2.0 6 votes vote down vote up
protected void merge(Term other) {
  if (other == this) return;
  
  this.score = this.score + other.score;    
  this.totalOccurrences = this.totalOccurrences + other.totalOccurrences;

  TObjectIntIterator<Variant> iter = other.variants.iterator();
  while (iter.hasNext()) {
    iter.advance();
    Variant key = iter.key();
    int value = iter.value();
    if (this.variants.containsKey(key))
      this.variants.adjustValue(key, value);
    else
      this.variants.put(key, value);
    key.replaceTerm(this);
  }
}