Java Code Examples for gnu.trove.map.TIntIntMap#get()

The following examples show how to use gnu.trove.map.TIntIntMap#get() . 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: IEJoin.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private static int[] getPermutationArray(int[] l2, int[] l1) {
	final int count = l1.length;
	TIntIntMap map = new TIntIntHashMap(count);
	for (int i = 0; i < count; ++i) {
		map.put(l1[i], i);
	}
	int[] result = new int[count];
	for (int i = 0; i < count; ++i) {
		result[i] = map.get(l2[i]);
	}
	return result;
}
 
Example 2
Source File: MetricTable.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static mt_32bit encode32Bit(TIntIntMap t_32bit, int timestampsSize) {
    LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_32bit));
    int[] values = new int[timestampsSize];
    int values_len = 0;
    for (int i = 0; i < values.length; ++i) {
        if (t_32bit.containsKey(i))
            values[values_len++] = t_32bit.get(i);
    }

    mt_32bit result = new mt_32bit();
    result.presence = createPresenceBitset(t_32bit.keySet(), timestampsSize);
    result.values = Arrays.copyOf(values, values_len);

    return result;
}
 
Example 3
Source File: MetricTable.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static mt_str encodeStr(TIntIntMap t_str, int timestampsSize) {
    LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_str));
    int[] values = new int[timestampsSize];
    int values_len = 0;
    for (int i = 0; i < values.length; ++i) {
        if (t_str.containsKey(i))
            values[values_len++] = t_str.get(i);
    }

    mt_str result = new mt_str();
    result.presence = createPresenceBitset(t_str.keySet(), timestampsSize);
    result.values = Arrays.copyOf(values, values_len);

    return result;
}
 
Example 4
Source File: LanguageModelMentionEntitySimilarityMeasure.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
@Override public double calcSimilarity(Mention mention, Context context, Entity entity, EntitiesContext entitiesContext)
    throws EntityLinkingDataAccessException {
  if (!(entitiesContext instanceof LanguageModelContext)) {
    logger.warn("LanguageModelMentionEntitySimilarityMeasure#calcSimilarity() "
        + "was invoked with an EntitiesContext that's not a LanguageModelContext => " + "returning 0.0 as similarity");
    return 0d;
  }
  LanguageModelContext languageModelContext = (LanguageModelContext) entitiesContext;

  if (originalInputText == null) {
    logger.debug("Calculating similarity, original input text is null.");
    originalInputText = new InputTextWrapper(context, unitType, removeStopwords);
  }
  if (languageModelContext.shouldIgnoreMention(unitType)) originalInputText.mentionToIgnore(mention);

  KLDivergenceCalculator klDivergenceCalculator = new KLDivergenceCalculator(normalized);
  TIntIntMap unitCountsForEntity = languageModelContext.getUnitCountsForEntity(entity, unitType);

  UnitMeasureTracer mt = null;
  if (isTracing) mt = new UnitMeasureTracer(getIdentifier(), 0.0, unitCountsForEntity.size());

  int entityUnitsSum = 0;
  for (int unitCount : unitCountsForEntity.values()) {
    entityUnitsSum += unitCount;
  }

  int unitGlobalCount, unitEntityCount;
  for (int unit : originalInputText.getUnits()) {
    if (unit == 0) continue;
    unitGlobalCount = languageModelContext.getUnitCount(unit, unitType);
    unitEntityCount = unitCountsForEntity.get(unit);
    // this check makes sure that the unit exist for this unitType
    if (unitGlobalCount == 0) continue;
    double summand = -klDivergenceCalculator
        .addSummand(originalInputText.getUnitCount(unit), originalInputText.getSize(), unitEntityCount, entityUnitsSum,
            languageModelContext.getUnitCount(unit, unitType), languageModelContext.getCollectionSize(),
            languageModelContext.getSmoothingParameter(unitType));
    if (mt != null) mt.addUnitTraceInfo(unit, summand, unitEntityCount != 0);
  }

  if (mt != null) {
    mt.setScore(-klDivergenceCalculator.getKLDivergence());
    tracer.addMeasureForMentionEntity(mention, entity.getId(), mt);
  }

  return -klDivergenceCalculator.getKLDivergence();
}
 
Example 5
Source File: Utils.java    From apkfile with Apache License 2.0 4 votes vote down vote up
public static void rollUp(TIntIntMap dest, TIntIntMap src) {
    for (int key : src.keys()) {
        int value = src.get(key);
        dest.adjustOrPutValue(key, value, value);
    }
}
 
Example 6
Source File: AllPairs.java    From JedAIToolkit with Apache License 2.0 4 votes vote down vote up
private List<Comparison> performJoin() {
    final List<Comparison> executedComparisons = new ArrayList<>();
    final TIntObjectMap<ListItemPPJ> index = new TIntObjectHashMap<>();
    for (int k = 0; k < noOfEntities; k++) {
        final TIntList record = records[k];

        int minLength = minPossibleLength(record.size());
        int probeLength = probeLength(record.size());
        int indexLength = indexLength(record.size());

        final int[] requireOverlaps = new int[record.size() + 1];
        for (int l = minLength; l <= record.size(); l++) {
            requireOverlaps[l] = requireOverlap(record.size(), l);
        }

        final TIntIntMap occurances = new TIntIntHashMap();
        for (int t = 0; t < probeLength; t++) {
            int token = record.get(t);

            ListItemPPJ item = index.get(token);
            if (item == null) {
                item = new ListItemPPJ();
                index.put(token, item);
            }

            int pos = item.getPos();
            final List<IntPair> ids = item.getIds();
            int noOfIds = ids.size();
            while (pos < noOfIds && records[ids.get(pos).getKey()].size() < minLength) {
                pos++;
            }

            for (int p = pos; p < noOfIds; p++) {
                int candId = ids.get(p).getKey();
                int oldValue = occurances.get(candId);
                occurances.put(candId, (oldValue + 1));
            }

            if (t < indexLength) {
                ids.add(new IntPair(k, t));
            }
        }

        for (int cand : occurances.keys()) {
            if (k == cand) {
                continue;
            }

            if (isCleanCleanER) {
                if (originalId[k] < datasetDelimiter && originalId[cand] < datasetDelimiter) { // both belong to dataset 1
                    continue;
                }

                if (datasetDelimiter <= originalId[k] && datasetDelimiter <= originalId[cand]) { // both belong to dataset 2
                    continue;
                }
            }

            int noOfCandidates = records[cand].size();
            int newindexLength = indexLength(noOfCandidates);
            if (records[cand].get(newindexLength - 1) < records[k].get(probeLength - 1)) {
                if (occurances.get(cand) + noOfCandidates - newindexLength < requireOverlaps[noOfCandidates]) {
                    continue;
                }
            } else {
                if (occurances.get(cand) + records[k].size() - probeLength < requireOverlaps[noOfCandidates]) {
                    continue;
                }
            }

            int realOverlap = getOverlap(k, cand, requireOverlaps[noOfCandidates]);
            if (realOverlap != -1) {
                float jaccardSim = calcSimilarity(records[k].size(), noOfCandidates, realOverlap);
                if (jaccardSim >= threshold) {
                    final Comparison currentComp = getComparison(originalId[k], originalId[cand]);
                    currentComp.setUtilityMeasure(jaccardSim); // is this correct?
                    executedComparisons.add(currentComp);
                }
            }
        }
    }
    return executedComparisons;
}