判断两段内容的相似度问题?结果返回相似度!
给你2段内容,怎么精确判断他们得相似度?
给你2段内容,怎么精确判断他们得相似度?
解决方案 »
- 我用Sakmail发邮件后,邮件居然收不到?
- 請幫忙把VB代碼轉換為Delphi
- IdFTP1 如何自动取得服务器上的文件名?
- delphi中如何定义结构?
- 如何传递web的图片信息到ocx控件上显示出来
- format函数怎么用
- delphi与oracle怎么连在一起运行?
- 简单问题:关于一个控件,50个大洋。
- 我怎么实现表的复制?
- win2000中能否安装delphi4呀
- 怎样用程序在SQL Server上新建数据库(.MDF文件,不是表),并能使用,因为我想做成象一些程序一样的有‘新建帐套’的工能?3Q
- 比较难得问题!数据t1,与下表中字段t_doll中的值比较,如果t1介于a(i)与a(i+1)之间,就取t2=b(i);在线ing,给粉ing!
内容一:
版权声明:CSDN是本Blog托管服务提供商。如本文牵涉版权问题,CSDN不承担相关责任,请版权拥有者直接与文章作者联系解决。
内容二:
版权声明:CSDN是托管服务提供商。CSDN不承担相关责任,请版权拥有者直接与文章作者联系解决。内容一和内容二很相似,用一种方法来判断两个内容是否相似
http://student.zjzk.cn/course_ware/data_structure/web/chuan/chuan4.2.3.1.htm
里面只有很简单的介绍,还要忙别的事,只能帮你这么多了。
1、相似度要怎么量化?
2、这个涉及到AI的呀正好体现的这个问题大在什么地方。如果要求非常高的话,所谓的串匹配、数据结构、线程处理,相对于问题本身的复杂度来说,都象小儿科一样了。最高的要求,乃是做出一个人的脑袋来:
1、我是男孩阿Q的老爸
2、阿Q是我的儿子,我是男的
3、阿Q是我和他妈生的,阿Q是一个男孩
这三句话毫无疑问是有着非常大的相似度的,但用电脑来识别,头大呀!降低要求(可能就是楼主的要求):
根据文字本身的相似度来判别,很快想到的是用第二句的部分内容去和第一句的内容匹配,也就是串匹配(如果从一般做程序的知识结构来说,就应该做的是精确匹配,而非涉及自然语言语义的智能模糊匹配)。匹配的问题数据结构的知识可以解决了,那么,剩下的问题就是:你用什么样的策略从第二句当中选取部分内容,按字?按词?按词组?按句子?还有拿去匹配了,占多少的比例也就是阀值,就可以判断是相似?语言学,模糊理论,唉,头大呀。
'John' and 'John' = 100%
'John' and 'Jon' = 75%
'Jim' and 'James' = 40%
"Luke Skywalker" and 'Darth Vader' = 0% function StrSimilar (s1, s2: string): Integer;
var hit: Integer; // Number of identical chars
p1, p2: Integer; // Position count
l1, l2: Integer; // Length of strings
pt: Integer; // for counter
diff: Integer; // unsharp factor
hstr: string; // help var for swapping strings
// Array shows is position is already tested
test: array [1..255] of Boolean;
begin
// Test Length and swap, if s1 is smaller
// we alway search along the longer string
if Length(s1) < Length(s2) then begin
hstr:= s2; s2:= s1; s1:= hstr;
end;
// store length of strings to speed up the function
l1:= Length (s1);
l2:= Length (s2);
p1:= 1; p2:= 1; hit:= 0;
// calc the unsharp factor depending on the length
// of the strings. Its about a third of the length
diff:= Max (l1, l2) div 3 + ABS (l1 - l2);
// init the test array
for pt:= 1 to l1 do test[pt]:= False;
// loop through the string
repeat
// position tested?
if not test[p1] then begin
// found a matching character?
if (s1[p1] = s2[p2]) and (ABS(p1-p2) <= diff) then begin
test[p1]:= True;
Inc (hit); // increment the hit count
// next positions
Inc (p1); Inc (p2);
if p1 > l1 then p1:= 1;
end else begin
// Set test array
test[p1]:= False;
Inc (p1);
// Loop back to next test position if end of the string
if p1 > l1 then begin
while (p1 > 1) and not (test[p1]) do Dec (p1);
Inc (p2)
end;
end;
end else begin
Inc (p1);
// Loop back to next test position if end of string
if p1 > l1 then begin
repeat Dec (p1); until (p1 = 1) or test[p1];
Inc (p2);
end;
end;
until p2 > Length(s2);
// calc procentual value
Result:= 100 * hit DIV l1;
end;