Java Code Examples for gnu.trove.impl.Constants#DEFAULT_LOAD_FACTOR

The following examples show how to use gnu.trove.impl.Constants#DEFAULT_LOAD_FACTOR . 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 vote down vote up
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: DataAccess.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
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 3
Source File: DataAccess.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
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 4
Source File: DataAccessEntitiesCacheTarget.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: InputTextWrapper.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
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 6
Source File: ShareableResource.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 7
Source File: ProcessLinkSearchMap.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
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 8
Source File: ProcessLinkSearchMap.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: MaterialCounter.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public MaterialCounter() {
  this(new TIntIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1, 0));
}
 
Example 10
Source File: EncoderDecoderKryoTest.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: BlockMaterialMap.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockMaterialMap(int capacity) {
    this(new TLongIntHashMap(capacity, Constants.DEFAULT_LOAD_FACTOR, NO_KEY, NO_VALUE));
}
 
Example 12
Source File: BlockVectorSet.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockVectorSet(int capacity) {
    this(new TLongHashSet(capacity, Constants.DEFAULT_LOAD_FACTOR, BlockUtils.ENCODED_NULL_POS));
}
 
Example 13
Source File: MaterialCounter.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public MaterialCounter() {
    this(new TIntIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1, 0));
}