Java Code Examples for gnu.trove.list.TIntList#size()
The following examples show how to use
gnu.trove.list.TIntList#size() .
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: GraphConfidenceEstimator.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
/** * Will return numElements integers from the input elements. If numElements * is larger than elements.size(), everything will be returned. * * @param elements Elements to choose from. * @param numElements Number of elements to choose. * @return numElement random integers from elements. */ private TIntSet getRandomElements(TIntSet elements, int numElements) { TIntList source = new TIntArrayList(elements.toArray()); TIntSet randomElements = new TIntHashSet(); for (int i = 0; i < numElements; ++i) { if (source.size() == 0) { break; } // TODO: this is not efficient, as deleting from the ArrayList // will copy ... make this more efficient when necessary. int elementPosition = random_.nextInt(source.size()); int element = source.get(elementPosition); source.remove(element); randomElements.add(element); } return randomElements; }
Example 2
Source File: PartEnumJoin.java From JedAIToolkit with Apache License 2.0 | 6 votes |
private int check_overlap(TIntList a, TIntList b, int overlap) { int posa = 0, posb = 0, count = 0; while (posa < (int) a.size() && posb < (int) b.size()) { if (count + Math.min((int) a.size() - posa, (int) b.size() - posb) < overlap) { return -1; } if (a.get(posa) == b.get(posb)) { count++; posa++; posb++; } else if (a.get(posa) < b.get(posb)) { posa++; } else { posb++; } } return count; }
Example 3
Source File: UnitBuilder.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public static String buildUnit(TIntList unitTokens, TIntObjectHashMap<String> id2word) { String[] tokenStrings = new String[unitTokens.size()]; for (int i = 0; i < unitTokens.size(); i++) { tokenStrings[i] = id2word.get(unitTokens.get(i)); } return buildUnit(tokenStrings); }
Example 4
Source File: PartEnumJoin.java From JedAIToolkit with Apache License 2.0 | 5 votes |
private float verify(TIntList a, TIntList b) { float factor = categoryTHRESHOLD / (1 + categoryTHRESHOLD); int require_overlap = (int) Math.ceil(factor * (a.size() + b.size()) - 1e-6); int real_overlap = check_overlap(a, b, require_overlap); if (real_overlap == -1) { return -1; } return (real_overlap / (float) (a.size() + b.size() - real_overlap)); }
Example 5
Source File: FastSS.java From JedAIToolkit with Apache License 2.0 | 5 votes |
private int checkEditDistance(TIntList p1, TIntList p2) { int i = 0, j = 0, updates = 0; while (i < p1.size() && j < p2.size()) { if (p1.get(i) == p2.get(j)) { updates++; j++; i++; } else if (p1.get(i) < p2.get(j)) { i++; } else { j++; } } return p1.size() + p2.size() - updates; }
Example 6
Source File: ByteBufUtils.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public static void writeIntList(PacketBuffer buf, TIntList intList) { buf.writeVarInt(intList.size()); for (int i = 0; i < intList.size(); i++) { buf.writeVarInt(intList.get(i)); } }
Example 7
Source File: UnitUtil.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
public static int getUnitId(TIntList unitTokens, TIntObjectHashMap<String> id2word, TObjectIntHashMap<String> word2id) { if (unitTokens == null || unitTokens.size() == 0) return 0; if (unitTokens.size() == 1) return unitTokens.get(0); return word2id.get(UnitBuilder.buildUnit(unitTokens, id2word)); }
Example 8
Source File: AllPairs.java From JedAIToolkit with Apache License 2.0 | 4 votes |
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; }
Example 9
Source File: Topk.java From JedAIToolkit with Apache License 2.0 | 4 votes |
private List<Comparison> performJoin() { final SetSimJoin ssj = new SetSimJoin(); LinkedHashMap<String, ArrayList<Integer>> recordsForTopk = new LinkedHashMap<>(); int cnter = 0; for (TIntList rec : records) { ArrayList<Integer> tokens = new ArrayList<>(); String id = ("" + originalId[cnter++]); for (int inrec = 0; inrec < rec.size(); inrec++) { tokens.add(rec.get(inrec)); } recordsForTopk.put(id, tokens); } ssj.setCleanCleanER(isCleanCleanER); ssj.setNoOfEntities(noOfEntities); ssj.setDatasetDelimiter(datasetDelimiter); ssj.setRecords(recordsForTopk); ssj.topkGlobal(comparisonsBudget); ArrayList<Comparison> results = ssj.getResults(); final List<Comparison> executedComparisons = new ArrayList<>(); for (Comparison res : results) { int id1 = res.getEntityId1(); int id2 = res.getEntityId2(); if (id1 == id2) { continue; } if (isCleanCleanER) { if (((id1 < datasetDelimiter) && (id2 < datasetDelimiter)) || ((id1 >= datasetDelimiter) && (id2 >= datasetDelimiter))) { continue; } } if (res.getUtilityMeasure() >= threshold) { final Comparison currentComp = getComparison(id1, id2); currentComp.setUtilityMeasure(res.getUtilityMeasure()); executedComparisons.add(currentComp); } } return executedComparisons; }