Java Code Examples for gnu.trove.map.hash.TIntObjectHashMap#keys()

The following examples show how to use gnu.trove.map.hash.TIntObjectHashMap#keys() . 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: SuperdocEntityKeyphraseCountCollector.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private void writeToFile(TIntObjectHashMap<TIntIntHashMap> superdocKeyphraseCounts) throws IOException, SQLException {
  int eCount = 0;

  logger.info("Writing entity-keyphrase pairs for " + superdocKeyphraseCounts.size() + " entities");

  for (int eid : superdocKeyphraseCounts.keys()) {

    if ((++eCount % 100000) == 0) {
      double percent = (double) eCount / (double) superdocKeyphraseCounts.size();

      logger.info("Wrote " + eCount + " entities (" + new DecimalFormat("#.##").format(percent) + ")");
    }

    TIntIntHashMap keyphraseCounts = superdocKeyphraseCounts.get(eid);

    for (int kid : keyphraseCounts.keys()) {
      int count = keyphraseCounts.get(kid);

      writer.write(eid + "\t" + kid + "\t" + String.valueOf(count));
      writer.newLine();
    }
  }
}
 
Example 2
Source File: BmeowTypeAnnotator.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private static BmeowTypeDictionary getDicitionaryForEntities(Entities entities) throws EntityLinkingDataAccessException {
	logger.trace("Entities retrieved from DB: " + entities.getEntities().stream()
			.map(Entity::getNMEnormalizedName).collect(Collectors.joining(", ")));

	TIntObjectHashMap<List<MentionObject>> mentions = DataAccess.getMentionsForEntities(entities);
	int[] entityIds = mentions.keys();

	TIntObjectHashMap<int[]> typeIds = DataAccess.getTypesIdsForEntitiesIds(entityIds);

	BmeowTypeDictionary dict = new BmeowTypeDictionary();

	for (int i = 0; i < entityIds.length; i++) {
		int[] typeId = typeIds.get(entityIds[i]); //for each entity its own set of type ids
		Set<NerType.Label> types = NerType.getNerTypesForTypeIds(typeId);
		for(MentionObject mention : mentions.get(entityIds[i])){
			for (NerType.Label nerType : types) {
				dict.put(mention.getMention(), nerType);
				logger.trace("Dict entry added: " + mention + ", " + nerType);
			}
		}
	}
	return dict;
}
 
Example 3
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * check resource profile on each host
 *
 * @param changes  the resource profiles
 * @param initFree the initial amount of free resources
 * @return the satisfaction status
 */
private ESat checkProfiles(TIntIntHashMap[][] changes, int[][] initFree) {
    boolean ok = true;
    for (int h = 0; h < nbHosts; h++) {
        TIntObjectHashMap<int[]> myChanges = myChanges(changes[h]);
        int[] moments = myChanges.keys(new int[myChanges.size()]);
        Arrays.sort(moments);
        for (int t : moments) {
            boolean bad = false;
            for (int d = 0; d < nbDims; d++) {
                initFree[h][d] += myChanges.get(t)[d];
                if (initFree[h][d] < 0) {
                    bad = true;
                }
            }
            if (bad) {
                ok = false;
                break;
            }
        }
    }
    return ESat.eval(ok);
}
 
Example 4
Source File: UnitsStatCollector.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public void startCollectingStatsInMemory(UnitType unitType) throws SQLException, EntityLinkingDataAccessException {
  TIntObjectHashMap<TIntHashSet> entityUnits = UnitUtil.loadEntityUnits(unitType.getUnitSize());

  // Count the occurrences of units with respect to entities
  TIntIntHashMap unitCounts = new TIntIntHashMap();
  for (int entity : entityUnits.keys()) {
    TIntHashSet units = entityUnits.get(entity);
    for (int unit : units.toArray()) {
      unitCounts.adjustOrPutValue(unit, 1, 1);
    }
  }

  logger.info("Storing data ...");
  storeUnitsIntoDB(unitCounts, unitType);
}
 
Example 5
Source File: DataAccessKeyValueStore.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override public TIntDoubleHashMap getEntityPriors(String mention, boolean isNamedentity) throws EntityLinkingDataAccessException {
  TIntDoubleHashMap entityPriors = new TIntDoubleHashMap();
  try {
    DatabaseKeyValueStore db = DatabaseKeyValueStore.DICTIONARY_MENTION;
    if(db.getPartitions() != 1) {
      throw new IllegalArgumentException("Multiple partitions not supported for this key-value store");
    }
    Codec codec = DataAccessKeyValueStoreHandler.singleton().getCodec(db);
    mention = EntityLinkingManager.conflateToken(mention, isNamedentity);
    KeyValueStore<byte[],byte[]> keyValueStore = DataAccessKeyValueStoreHandler.singleton().getKeyValueStore(db);
    byte[] resultBytes = keyValueStore.get(codec.encodeKey(mention));
    if (resultBytes != null) {
      TIntDoubleHashMap tempResults = (TIntDoubleHashMap) codec.decodeValue(resultBytes);
      TIntObjectHashMap<EntityType> entityClasses = DataAccessCache.singleton().getEntityClasses(tempResults.keys());

      for(int entityId: entityClasses.keys()) {
        if (isNamedentity) {
          if (!(entityClasses.get(entityId) == EntityType.CONCEPT)) {
            entityPriors.put(entityId, tempResults.get(entityId));
          }
        }
        else {
          if (!(entityClasses.get(entityId) == EntityType.NAMED_ENTITY)) {
            entityPriors.put(entityId, tempResults.get(entityId));
          }
        }
      }
    }
  } catch (Exception e) {
    throw new EntityLinkingDataAccessException(e);
  }
  return entityPriors;
}
 
Example 6
Source File: TaskScheduler.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String prettyChanges(TIntObjectHashMap<int[]> changes) {
    int[] moments = changes.keys(new int[changes.size()]);
    Arrays.sort(moments);
    StringBuilder b = new StringBuilder();
    for (int t : moments) {
        b.append(t).append('=').append(Arrays.toString(changes.get(t))).append(' ');
    }
    return b.toString();
}