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

The following examples show how to use gnu.trove.map.hash.TIntObjectHashMap#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: 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: DataAccess.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/**
 * Computes all entity occurrence probabilities based on their incoming links.
 *
 * @return Map of Entity->Probability.
 * @throws EntityLinkingDataAccessException
 */
public static TIntDoubleHashMap getAllEntityProbabilities() throws EntityLinkingDataAccessException {
  TIntObjectHashMap<int[]> entityInlinks = getAllInlinks();

  TIntDoubleHashMap entityProbabilities = new TIntDoubleHashMap(entityInlinks.size(), 0.5f);

  // Get the total number of links.
  long totalLinkCount = 0;

  TIntObjectIterator<int[]> itr = entityInlinks.iterator();

  while (itr.hasNext()) {
    itr.advance();
    totalLinkCount += itr.value().length;
  }

  // Derive probabilities from counts.
  itr = entityInlinks.iterator();

  while (itr.hasNext()) {
    itr.advance();
    double probability = (double) itr.value().length / (double) totalLinkCount;
    entityProbabilities.put(itr.key(), probability);
  }

  return entityProbabilities;
}
 
Example 3
Source File: GraphTracer.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private String buildEntityUriAnchor(int entityId, TIntObjectHashMap<EntityMetaData> entitiesMetaData) {
  String uriString = "NO_METADATA";
  String displayString = new Integer(entityId).toString();
  if (entitiesMetaData != null && entitiesMetaData.size() > 0) {
    EntityMetaData md = entitiesMetaData.get(entityId);
    if (md != null) {
      uriString = entitiesMetaData.get(entityId).getUrl();
      displayString = Char.toHTML(entitiesMetaData.get(entityId).getHumanReadableRepresentation());
    }
  }
  String entityAnchor = "<a class='entityAnchor' target='_blank' href='" + uriString + "'>" + displayString + "</a>";
  return entityAnchor;
}