Java Code Examples for gnu.trove.map.hash.TObjectIntHashMap#adjustOrPutValue()

The following examples show how to use gnu.trove.map.hash.TObjectIntHashMap#adjustOrPutValue() . 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: MFCCShingle.java    From cineast with MIT License 6 votes vote down vote up
/**
 * This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by
 * the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of
 * ScoreElements is returned by the feature module during retrieval.
 *
 * @param partialResults List of partial results returned by the lookup stage.
 * @param qc             A ReadableQueryConfig object that contains query-related configuration parameters.
 * @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
 */
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
     /* Prepare helper data-structures. */
    final List<ScoreElement> results = new ArrayList<>();
    final TObjectIntHashMap<String> scoreMap = new TObjectIntHashMap<>();

     /* Set QueryConfig and extract correspondence function. */
    qc = this.setQueryConfig(qc);
    final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.correspondence);
    for (DistanceElement hit : partialResults) {
        if (hit.getDistance() < this.distanceThreshold) {
            scoreMap.adjustOrPutValue(hit.getId(), 1, scoreMap.get(hit.getId())/2);
        }
    }

    /* Prepare final result-set. */
    scoreMap.forEachEntry((key, value) -> results.add(new SegmentScoreElement(key, 1.0 - 1.0/value)));
    ScoreElement.filterMaximumScores(results.stream());
    return results;
}
 
Example 2
Source File: DictionaryBuilder.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private void addDictionaryEntry(Map<String, TObjectIntHashMap<DictionaryEntity>> dictionaryEntries,
    String mentionString, DictionaryEntity candidateEntity) {
  TObjectIntHashMap<DictionaryEntity> mentionCandidates = dictionaryEntries.get(mentionString);
  if (mentionCandidates == null) {
    mentionCandidates = new TObjectIntHashMap<>();
    dictionaryEntries.put(mentionString, mentionCandidates);
  }
  mentionCandidates.adjustOrPutValue(candidateEntity, 0, 0);
}