--正在做这样的东西,比较英文单词库中相似的单词。 --得到最大相似度,定义:最大相同子串长度/最长字符长度 --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
--正在做这样的东西,比较英文单词库中相似的单词。 --得到最大相似度,定义:最大相同子串长度/最长字符长度 --CSDN超级大笨狼。 --更正BUGcreate 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
--得到最大相似度,定义:最大相同子串长度/最长字符长度
--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
--得到最大相似度,定义:最大相同子串长度/最长字符长度
--CSDN超级大笨狼。
--更正BUGcreate 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
--75
--相似度