コード例 #1
0
  @Override
  public double calcSimilarity(
      Mention mention, Context context, Entity entity, EntitiesContext entitiesContext) {
    // create two Maps representing the word count vectors
    TIntIntHashMap contextVec = createWordCountVector(context.getTokenIds());
    TIntIntHashMap entityVec = createWordCountVector(entitiesContext.getContext(entity));

    // calc dot product between them
    double similarity = calcDotProduct(entityVec, contextVec);
    return similarity;
  }
コード例 #2
0
  @Override
  public double calcSimilarity(
      Mention mention, Context context, Entity entity, EntitiesContext entitiesContext) {
    TIntHashSet contextA = new TIntHashSet(context.getTokenIds());
    TIntHashSet contextB = new TIntHashSet(entitiesContext.getContext(entity));

    TIntHashSet union = getUnion(contextA, contextB);
    TIntHashSet intersection = getIntersection(contextA, contextB);

    double jaccardSim = (double) intersection.size() / (double) union.size();
    return jaccardSim;
  }