Java Code Examples for gnu.trove.set.hash.TIntHashSet#toArray()

The following examples show how to use gnu.trove.set.hash.TIntHashSet#toArray() . 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: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntIntHashMap getKeywordDocumentFrequencies(TIntHashSet keywords) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    String[] tokens = kpF[0].split(" ");
    int freq = Integer.parseInt(kpF[1]);
    for (String token : tokens) {
      freqs.put(DataAccess.getIdForWord(token), freq);
    }
  }

  for (int kw : keywords.toArray()) {
    if (!freqs.containsKey(kw)) {
      System.err.println("allKeyphraseFrequencies do not contain token '" + DataAccess.getWordForId(kw) + "'");
    }
  }

  return freqs;
}
 
Example 2
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntIntHashMap getKeyphraseDocumentFrequencies(TIntHashSet keyphrases) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    int keyphrase = DataAccess.getIdForWord(kpF[0]);
    int freq = Integer.parseInt(kpF[1]);
    freqs.put(keyphrase, freq);
  }

  for (int kp : keyphrases.toArray()) {
    if (!freqs.containsKey(kp)) {
      System.err.println("allKeyphraseFrequencies does not contain '" + DataAccess.getWordForId(kp) + "'");
    }
  }

  return freqs;
}
 
Example 3
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 4
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a sorted unique array of integers
 *
 * @param nums an unsorted array of integers with possible duplicates.
 * @return
 */
public static int[] unique(int[] nums) {
    TIntHashSet set = new TIntHashSet(nums);
    int[] result = set.toArray();
    Arrays.sort(result);
    return result;
}
 
Example 5
Source File: DataAccessSQL.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
@Override
public Entities getEntitiesForMentionByFuzzyMatching(String mention, double minSimilarity, boolean isNamedEntity) throws EntityLinkingDataAccessException {
  Integer id = RunningTimer.recordStartTime("FuzzyEntitiesForMention");
  String conflatedMention = EntityLinkingManager.conflateToken(mention, isNamedEntity);
  TIntHashSet entitiesIds = new TIntHashSet();
  EntityType entityType;
  if (isNamedEntity) {
    entityType = EntityType.NAMED_ENTITY;
  } else {
    entityType = EntityType.CONCEPT;
  }
  Connection mentionEntityCon = null;
  Statement statement = null;
  try {
    mentionEntityCon = EntityLinkingManager.getConnectionForDatabase(EntityLinkingManager.DB_AIDA);
    statement = mentionEntityCon.createStatement();
    String sql = null;
    String query = PostgresUtil.getPostgresEscapedString(conflatedMention);
      sql = "SELECT mention, entity  FROM " + DICTIONARY + ", " +
            " WHERE mention % '" + query + "'" +
            " AND similarity(mention, '" +  query + "') >= " + minSimilarity +
            " AND " + DataAccessSQL.DICTIONARY + ".entitytype=" + entityType.getDBId();
    System.out.println(sql);
    ResultSet r = statement.executeQuery(sql);
    while (r.next()) {
      int entity = r.getInt(2);
      entitiesIds.add(entity);
    }
    r.close();
    statement.close();
    EntityLinkingManager.releaseConnection(mentionEntityCon);
  } catch (Exception e) {
    logger.error(e.getLocalizedMessage());
    throw new EntityLinkingDataAccessException(e);
  }
  int[] ids = entitiesIds.toArray();
  TIntObjectHashMap<KBIdentifiedEntity> yagoEntityIds = getKnowlegebaseEntitiesForInternalIds(ids);

  Entities entities = new Entities();
  for (int i = 0; i < ids.length; ++i) {
    entities.add(new Entity(yagoEntityIds.get(ids[i]), ids[i]));
  }
  RunningTimer.recordEndTime("FuzzyEntitiesForMention", id);
  return entities;
}
 
Example 6
Source File: PostgresUtil.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
public static String getIdQuery(TIntHashSet ids) {
  int[] conv = ids.toArray();
  return getIdQuery(conv);
}