gnu.trove.impl.Constants Java Examples
The following examples show how to use
gnu.trove.impl.Constants.
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: DataAccessKeyphraseTokensCacheTarget.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
protected void loadFromDisk() throws IOException { File cacheFile = getCacheFile(); DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(cacheFile)))); int keyphraseCount = in.readInt(); data_ = new TIntObjectHashMap<>((int) (keyphraseCount / Constants.DEFAULT_LOAD_FACTOR)); for (int i = 0; i < keyphraseCount; ++i) { int wordId = in.readInt(); int arrLen = in.readInt(); int[] arrTokens = new int[arrLen]; for (int j = 0; j < arrLen; j++) { arrTokens[j] = in.readInt(); } data_.put(wordId, arrTokens); } in.close(); }
Example #2
Source File: ProcessLinkSearchMap.java From olca-app with Mozilla Public License 2.0 | 5 votes |
/** * Returns all the links where the process with the given ID is either * provider or connected with a provider. */ public List<ProcessLink> getLinks(long processId) { // because this method could be called quite often in graphical // presentations of product systems and there can be a lot of links // in some kind of product systems (e.g. from IO-databases) we do // not just merge the incoming and outgoing links here TIntHashSet intSet = new TIntHashSet(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1); TIntArrayList list = providerIndex.get(processId); if (list != null) intSet.addAll(list); list = connectionIndex.get(processId); if (list != null) intSet.addAll(list); return getLinks(intSet.iterator()); }
Example #3
Source File: DataAccess.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public static TIntIntHashMap getKeywordDocumentFrequencies(TIntSet keywords) throws EntityLinkingDataAccessException { logger.debug("Get keyword-document frequencies."); Integer runId = RunningTimer.recordStartTime("DataAccess:KWDocFreq"); TIntIntHashMap keywordCounts = new TIntIntHashMap((int) (keywords.size() / Constants.DEFAULT_LOAD_FACTOR)); for (TIntIterator itr = keywords.iterator(); itr.hasNext(); ) { int keywordId = itr.next(); int count = DataAccessCache.singleton().getKeywordCount(keywordId); keywordCounts.put(keywordId, count); } RunningTimer.recordEndTime("DataAccess:KWDocFreq", runId); return keywordCounts; }
Example #4
Source File: DataAccess.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public static TIntIntHashMap getUnitDocumentFrequencies(TIntSet keywords, UnitType unitType) throws EntityLinkingDataAccessException { logger.debug("Get Unit-document frequencies."); Integer runId = RunningTimer.recordStartTime("DataAccess:KWDocFreq"); TIntIntHashMap keywordCounts = new TIntIntHashMap((int) (keywords.size() / Constants.DEFAULT_LOAD_FACTOR)); for (TIntIterator itr = keywords.iterator(); itr.hasNext(); ) { int keywordId = itr.next(); int count = DataAccessCache.singleton().getUnitCount(keywordId, unitType); keywordCounts.put(keywordId, count); } RunningTimer.recordEndTime("DataAccess:KWDocFreq", runId); return keywordCounts; }
Example #5
Source File: ProcessLinkSearchMap.java From olca-app with Mozilla Public License 2.0 | 5 votes |
public ProcessLinkSearchMap(Collection<ProcessLink> links) { providerIndex = new TLongObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1L); connectionIndex = new TLongObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1L); data = new ArrayList<>(links); for (int i = 0; i < data.size(); i++) { ProcessLink link = data.get(i); index(link.providerId, i, providerIndex); index(link.processId, i, connectionIndex); } }
Example #6
Source File: DataAccessEntitiesCacheTarget.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
@Override protected void loadFromDisk() throws IOException { File cacheFile = getCacheFile(); DataInputStream in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(cacheFile)))); int size = in.readInt(); data_ = new TIntObjectHashMap<>((int) (size / Constants.DEFAULT_LOAD_FACTOR)); for (int i = 0; i < size; ++i) { int entityId = in.readInt(); int entityClass = in.readInt(); data_.put(entityId, EntityType.getNameforDBId(entityClass)); } in.close(); }
Example #7
Source File: InputTextWrapper.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public InputTextWrapper(Context context, UnitType unitType, boolean removeStopwords) throws EntityLinkingDataAccessException { logger.debug("Wrapping input text."); mentionToIgnore = null; this.unitType = unitType; int unitLength = unitType.getUnitSize(); if (context.getTokenCount() < unitLength) return; List<String> unitStrings = new ArrayList<>(context.getTokenCount()); Queue<String> curTokens = new ArrayDeque<>(unitLength); String[] curTokensArray = new String[unitLength]; for (String token : context.getTokens()) { curTokens.add(token); if (curTokens.size() == unitLength || (!curTokens.isEmpty() && curTokens.size() - 1 == unitLength)) { unitStrings.add(UnitBuilder.buildUnit(curTokens.toArray(curTokensArray))); curTokens.remove(); } } logger.debug("Get ids for words."); TObjectIntHashMap<String> wordIds = DataAccess.getIdsForWords(unitStrings); units = new int[unitStrings.size()]; unitCounts = new TIntIntHashMap((int) (wordIds.size() / Constants.DEFAULT_LOAD_FACTOR), Constants.DEFAULT_LOAD_FACTOR); numOfUnits = 0; for (int i = 0; i < unitStrings.size(); i++) { int unitId = wordIds.get(unitStrings.get(i)); if (unitId == 0) continue; logger.debug("Get contract term for unit id {}.", unitId); int contractedUnitId = DataAccess.contractTerm(unitId); if (contractedUnitId != 0) unitId = contractedUnitId; if (removeStopwords && StopWord.isStopwordOrSymbol(unitId, Language.getLanguageForString("en"))) continue; units[i] = unitId; unitCounts.adjustOrPutValue(unitId, 1, 1); numOfUnits++; } }
Example #8
Source File: ShareableResource.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
/** * Make a new resource. * * @param id the resource identifier * @param defCapacity the nodes default capacity * @param defConsumption the VM default consumption */ public ShareableResource(String id, int defCapacity, int defConsumption) { this.rcId = id; vmsConsumption = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, defConsumption); nodesCapacity = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, defCapacity); if (defCapacity < 0) { throw new IllegalArgumentException(String.format("The %s default capacity must be >= 0", rcId)); } if (defConsumption < 0) { throw new IllegalArgumentException(String.format("The %s default consumption must be >= 0", rcId)); } this.viewId = VIEW_ID_BASE + rcId; }
Example #9
Source File: EncoderDecoderKryoTest.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
@Test public void test() throws IOException { EncoderDecoderKryo<Integer> encoderInteger = new EncoderDecoderKryo(Integer.class); int a = 845739038; byte[] bytes = encoderInteger.encode(a); int resultInt = encoderInteger.decode(bytes); assertEquals(a, resultInt); EncoderDecoderKryo<Double> encoderDouble = new EncoderDecoderKryo(Double.class); double b = 845739038; bytes = encoderDouble.encode(b); double resultDouble = encoderDouble.decode(bytes); assertEquals(b, resultDouble, 0.00001); EncoderDecoderKryo<String> encoderString = new EncoderDecoderKryo(String.class); String str = "hola"; bytes = encoderString.encode(str); String resultString = encoderString.decode(bytes); assertEquals(str, resultString); EncoderDecoderKryo<String[]> encoderStringArray = new EncoderDecoderKryo(String[].class); String[] strArray = new String[] { "hola", "y", "chau" }; bytes = encoderStringArray.encode(strArray); String[] resultStringArray = encoderStringArray.decode(bytes); for (int i = 0; i < strArray.length; i++) { assertEquals(strArray[i], resultStringArray[i]); } EncoderDecoderKryo<KeyValueStoreRow[]> keyvalueStoreRowArray = new EncoderDecoderKryo(KeyValueStoreRow[].class); Object[] elements = new Object[] { a, b, str }; KeyValueStoreRow kvs1 = new KeyValueStoreRow(elements); Object[] elements2 = new Object[] { str, b, a }; KeyValueStoreRow kvs2 = new KeyValueStoreRow(elements2); KeyValueStoreRow[] kvsr = new KeyValueStoreRow[] { kvs1, kvs2 }; bytes = keyvalueStoreRowArray.encode(kvsr); KeyValueStoreRow[] kvsrResultl = keyvalueStoreRowArray.decode(bytes); assertEquals(kvsr[0].getInt(0), kvsrResultl[0].getInt(0)); assertEquals(kvsr[0].getDouble(1), kvsrResultl[0].getDouble(1), 0.00001); assertEquals(kvsr[0].getString(2), kvsr[0].getString(2)); assertEquals(kvsr[1].getInt(2), kvsrResultl[1].getInt(2)); assertEquals(kvsr[1].getDouble(1), kvsrResultl[1].getDouble(1), 0.00001); assertEquals(kvsr[1].getString(0), kvsr[1].getString(0)); EncoderDecoderKryo<TIntDoubleHashMap> tintDoubleHashMap = new EncoderDecoderKryo(TIntDoubleHashMap.class); TIntDoubleHashMap object = new TIntDoubleHashMap(2, Constants.DEFAULT_LOAD_FACTOR); object.put(7, 8.19); object.put(15, 7.9); bytes = tintDoubleHashMap.encode(object); TIntDoubleHashMap result = tintDoubleHashMap.decode(bytes); TIntDoubleIterator it = result.iterator(); int index = 0; while (it.hasNext()) { it.advance(); if (index == 0) { assertEquals(7, it.key()); assertEquals(it.value(), 8.19, 0.00001); } else { assertEquals(15, it.key()); assertEquals(it.value(), 7.9, 0.00001); } index++; } }
Example #10
Source File: MaterialCounter.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public MaterialCounter() { this(new TIntIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1, 0)); }
Example #11
Source File: BlockVectorSet.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public BlockVectorSet() { this(Constants.DEFAULT_CAPACITY); }
Example #12
Source File: BlockVectorSet.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public BlockVectorSet(int capacity) { this(new TLongHashSet(capacity, Constants.DEFAULT_LOAD_FACTOR, BlockUtils.ENCODED_NULL_POS)); }
Example #13
Source File: BlockMaterialMap.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public BlockMaterialMap() { this(Constants.DEFAULT_CAPACITY); }
Example #14
Source File: BlockMaterialMap.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public BlockMaterialMap(int capacity) { this(new TLongIntHashMap(capacity, Constants.DEFAULT_LOAD_FACTOR, NO_KEY, NO_VALUE)); }
Example #15
Source File: BlockVectorSet.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public BlockVectorSet() { this(Constants.DEFAULT_CAPACITY); }
Example #16
Source File: EncoderDecoderKryo.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
public EncoderDecoderKryo(Class<T> objectType) { this.objectType = objectType; if (kryos == null) { kryos = new ThreadLocal<Kryo>(){ //Max capacity is needed, to allow automatically cleaning, if the maximum is reached clean is called to remove unused references protected Kryo initialValue() { Kryo kryo = new Kryo(); kryo.setRegistrationRequired(true); // All primitives, primitive wrappers, and String are registered by default. kryo.register(KeyValueStoreRow.class, new Serializer<KeyValueStoreRow>() { //Problems sertializing Object with Kryo, this is a worl around. In principle it should work out of the box in kryo by adding @FieldSerializer.Bind(DefaultArraySerializers.ObjectArraySerializer.class) on top of the variable @Override public void write(Kryo kryo, Output output, KeyValueStoreRow keyValueStoreRow) { //work around byte[] data = SerializationUtils.serialize(keyValueStoreRow.values); int size = data.length; output.writeInt(size); output.writeBytes(data); } @Override public KeyValueStoreRow read(Kryo kryo, Input input, Class<? extends KeyValueStoreRow> aClass) { int size = input.readInt(); Object[] values = (Object[]) SerializationUtils.deserialize(input.readBytes(size)); return new KeyValueStoreRow(values); } }, 9); kryo.register(KeyValueStoreRow[].class, 10); kryo.register(String[].class, 11); kryo.register(double[].class, 12); kryo.register(TIntDoubleHashMap.class, new Serializer<TIntDoubleHashMap>() { public void write (Kryo kryo, Output output, TIntDoubleHashMap object) { int size = object.size(); output.writeInt(size); int[] keys = new int[size]; double[] values = new double[size]; int in = 0; TIntDoubleIterator it = object.iterator(); while(it.hasNext()) { it.advance(); keys[in] = it.key(); values[in] = it.value(); in++; } final Iterator<AbstractMap.SimpleEntry<Integer, Double>> sorted = IntStream.range(0, keys.length) .mapToObj(i -> new AbstractMap.SimpleEntry<>(keys[i], values[i])) .sorted(Comparator.comparingInt(b -> b.getKey())).iterator(); int index = 0; while(sorted.hasNext()) { Map.Entry<Integer, Double> entry = sorted.next(); keys[index] = entry.getKey(); values[index] = entry.getValue(); index++; } try { CompressionUtils.deltaEncoding(keys); } catch (IOException e) { e.printStackTrace(); } output.writeInts(keys, 0, keys.length); output.writeDoubles(values, 0, values.length); kryo.writeClassAndObject(output, object); } public TIntDoubleHashMap read (Kryo kryo, Input input, Class<? extends TIntDoubleHashMap> type) { int size = input.readInt(); int[] keys = input.readInts(size); double[] values = input.readDoubles(size); CompressionUtils.deltaUncompress(keys); TIntDoubleHashMap object = new TIntDoubleHashMap(size, Constants.DEFAULT_LOAD_FACTOR); for(int i = 0; i < size; i++) { object.put(keys[i], values[i]); } return object; } }, 13); return kryo; } }; } }
Example #17
Source File: MaterialCounter.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public MaterialCounter() { this(new TIntIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1, 0)); }