我添加数据到数据库的时候,能不能判断一下相似度,很相似数据的就不要重复添加进去

rockplayer 2006-07-07 11:12:06
我有个问题,我添加数据到数据库的时候
如果两条记录的题目是:"我是谁" "我是谁啊",因为两条记录的题目都差不多.
这样我能不能判断一下,不让第二条记录添进去.就是很相似的就不添加进去.

Thanks/
...全文
120 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2006-12-05
  • 打赏
  • 举报
回复
select dbo.get_semblance_By_2words('我是谁','我是谁啊')
--75
--相似度
超级大笨狼 2006-12-05
  • 打赏
  • 举报
回复
--正在做这样的东西,比较英文单词库中相似的单词。
--得到最大相似度,定义:最大相同子串长度/最长字符长度
--CSDN超级大笨狼。
--更正BUG

create function get_semblance_By_2words
(
@word1 varchar(50),
@word2 varchar(50)
)
returns nvarchar(4000)
as
begin
declare @re int
declare @maxLenth int
declare @i int,@l int
declare @tb1 table(child varchar(50))
declare @tb2 table(child varchar(50))
set @i=1
set @l=2
set @maxLenth=len(@word1)
if len(@word1)<len(@word2)
begin
set @maxLenth=len(@word2)
end
while @l<=len(@word1)
begin
while @i<len(@word1)-1
begin
insert @tb1 (child) values( SUBSTRING(@word1,@i,@l) )
set @i=@i+1
end
set @i=1
set @l=@l+1
end


set @i=1
set @l=2


while @l<=len(@word2)
begin
while @i<len(@word2)-1
begin
insert @tb2 (child) values( SUBSTRING(@word2,@i,@l) )
set @i=@i+1
end
set @i=1
set @l=@l+1
end

select @re=isnull(max( len(a.child)*100/ @maxLenth ) ,0) from @tb1 a, @tb2 b where a.child=b.child
return @re
end








GO
超级大笨狼 2006-12-05
  • 打赏
  • 举报
回复
--正在做这样的东西,比较英文单词库中相似的单词。
--得到最大相似度,定义:最大相同子串长度/最长字符长度
--CSDN超级大笨狼。
create function get_semblance_By_2words
(
@word1 varchar(50),
@word2 varchar(50)
)
returns nvarchar(4000)
as
begin
declare @re int
declare @maxLenth int
declare @i int,@l int
declare @tb1 table(child varchar(50))
declare @tb2 table(child varchar(50))
set @i=1
set @l=2
set @maxLenth=len(@word1)
if len(@word1)<len(@word2)
begin
set @maxLenth=len(@word2)
end
while @l<=len(@word1)
begin
while @i<len(@word1)-1
begin
insert @tb1 (child) values( SUBSTRING(@word1,@i,@l) )
set @i=@i+1
end
set @i=1
set @l=@l+1
end


set @i=1
set @l=2


while @l<=len(@word2)
begin
while @i<len(@word2)-1
begin
insert @tb2 (child) values( SUBSTRING(@word2,@i,@l) )
set @i=@i+1
end
set @i=1
set @l=@l+1
end

select @re=max( len(a.child)*100/len(@maxLenth)) from @tb1 a, @tb2 b where a.child=b.child
return @re
end





go

fcuandy 2006-07-07
  • 打赏
  • 举报
回复
有条记录'他问我是谁'
这个怎么算?

两个语意根本不一样。
xyxfly 2006-07-07
  • 打赏
  • 举报
回复
很相似是个模糊的概念 要有个标准吧。
playwarcraft 2006-07-07
  • 打赏
  • 举报
回复
如果判断的准则有一定规律,就可以

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧