Skip to content

Commit

Permalink
保证最小距离大于1
Browse files Browse the repository at this point in the history
  • Loading branch information
ysc committed May 21, 2015
1 parent ebfcabb commit 36820fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,10 @@ word分词提供了多种文本相似度计算方式:
运行结果如下:

我爱购物 和 我爱购物 的相似度分值:1.0
我爱购物 和 我爱读书 的相似度分值:0.71
我爱购物 和 他是黑客 的相似度分值:0.41
我爱购物 和 我爱读书 的相似度分值:0.41
我爱购物 和 他是黑客 的相似度分值:0.29
我爱读书 和 我爱读书 的相似度分值:1.0
我爱读书 和 他是黑客 的相似度分值:0.41
我爱读书 和 他是黑客 的相似度分值:0.29
他是黑客 和 他是黑客 的相似度分值:1.0

方式七:曼哈顿距离(Manhattan Distance),通过计算两个点在标准坐标系上的绝对轴距总和来评估他们的相似度
Expand Down Expand Up @@ -735,10 +735,10 @@ word分词提供了多种文本相似度计算方式:
运行结果如下:

我爱购物 和 我爱购物 的相似度分值:1.0
我爱购物 和 我爱读书 的相似度分值:0.5
我爱购物 和 他是黑客 的相似度分值:0.17
我爱购物 和 我爱读书 的相似度分值:0.33
我爱购物 和 他是黑客 的相似度分值:0.14
我爱读书 和 我爱读书 的相似度分值:1.0
我爱读书 和 他是黑客 的相似度分值:0.17
我爱读书 和 他是黑客 的相似度分值:0.14
他是黑客 和 他是黑客 的相似度分值:1.0
###分词算法效果评估:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ protected double scoreImpl(List<Word> words1, List<Word> words2) {
//距离为0,表示完全相同
score = 1;
}else {
score = 1 / euclideanDistance;
score = 1 / (euclideanDistance+1);
}
if(LOGGER.isDebugEnabled()){
LOGGER.debug("文本1和文本2的欧几里得距离:"+euclideanDistance);
LOGGER.debug("文本1和文本2的相似度分值:1 / "+euclideanDistance+"="+score);
LOGGER.debug("文本1和文本2的相似度分值:1 / ("+euclideanDistance+"+1)="+score);
}
return score;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ protected double scoreImpl(List<Word> words1, List<Word> words2) {
//距离为0,表示完全相同
score = 1;
}else {
score = 1 / (double)manhattanDistance.get();
score = 1 / (double)(manhattanDistance.get()+1);
}
if(LOGGER.isDebugEnabled()){
LOGGER.debug("文本1和文本2的曼哈顿距离:"+manhattanDistance.get());
LOGGER.debug("文本1和文本2的相似度分值:1 / (double)"+manhattanDistance.get()+"="+score);
LOGGER.debug("文本1和文本2的相似度分值:1 / (double)("+manhattanDistance.get()+"+1)="+score);
}
return score;
}
Expand Down

0 comments on commit 36820fa

Please sign in to comment.