日期:2014-05-18  浏览次数:20366 次

谁有语法分析的算法,能给我一份吗?就像百度知道那样,把句子中的名词罗列出来就行
谁有语法分析的算法,能给我一份吗?就像百度知道那样,把句子中的名词罗列出来就行

------解决方案--------------------
您是说 "分词算法 "吧,这可不是什么简单的活,需要分词库+倒叙匹配算法+优化算法等,您还是先了解一下 "分词算法 "吧,用baidu或者google搜吧
------解决方案--------------------
declare @w varchar(8000)
set @w= '常用的分词算法有正向最大匹配、逆向最大匹配、双向最大匹配、最佳匹配法、最少分词法、词网格算法等等。
最大匹配法(Forward Maximum Matching method, FMM法):选取包含6-8个汉字的符号串作为最大符号串,把最大符号串与词典中的单词条目相匹配,如果不能匹配,就削掉一个汉字继续匹配,直到在词典中找到相应的单词为止。匹配的方向是从右向左。
逆向最大匹配法(Backward Maximum Matching method, BMM法):匹配方向与MM法相反,是从左向右。实验表明:对于汉语来说,逆向最大匹配法比最大匹配法更有效。
双向匹配法(Bi-direction Matching method, BM法):比较MM法与RMM法的切分结果,从而决定正确的切分。
最佳匹配法(Optimum Matching method, OM法):将词典中的单词按它们在文本中的出现频度的大小排列,高频度的单词排在前,频度低的单词排在后,从而提高匹配的速度。 '

declare @tb table(w varchar(10),f int)
declare @i int
declare @l int
declare @theWord varchar(10)
set @l=2
while @l <5
begin
set @i=1
while @i <len(@w)
begin
set @theWord=substring(@w,@i,@l)
if charindex( ' ',@theWord)=0 begin
if exists(select w from @tb where w=@theWord)
begin
update @tb set f=f+1 where w=@theWord
end
else
begin
insert @tb(w,f) select @theWord,1
end end
set @i=@i+1
end
set @l=@l+1
end

select * from @tb where f> len(@w)/70 order by f desc