<%
'词库文件存于config/zwck.txt,该词库目前存放213663条词目,你也可自行扩充
'说明:此版本过滤英文处理.
Class Wordsegment_Cls
	Private KeyList
	Private CacheCK
	Private Sub Class_Initialize() 
	  CacheCK=true                 '是否缓存词库,true 是 false否.当内存较小时建议设置为false,但可能会影响关键词的检索速度
	End Sub
	
	Private Sub Class_Terminate()
	End Sub

    '词库载入
	Sub LoadKey()
		Dim KS:Set KS=new publiccls
		If Application(KS.SiteSN & "ZWCK")="" Or CacheCK=False Then
		 KeyList=KS.ReadFromFile(KS.Setting(3) & "config/zwck.txt")
		 KeyList="|" & Replace(KeyList,vbcrlf,"|") & "|"
		 Application(KS.SiteSN & "ZWCK")=KeyList
		Else
		 KeyList=Application(KS.SiteSN & "ZWCK")
		End If
	End Sub
	
	'参数:str 待检索的字符串 x 取长度 maxlen 最多返回长度
	Function SplitKey(str, x,maxlen)
	    LoadKey
		Dim a, b 'As String
		Dim i, j, flag, max, temp_str
	
		a = str
	
		'分词
		For i = 1 To Len(a)
			For j = 1 To x
				a = a & Mid(a, i, j) & " "
			Next
		Next
	
		a = Split(a, " ")
		max = UBound(a)
	
		'过滤重复字符串
		For i = 0 To max - 1
			flag = a(i)
			If iscn(flag) Then
				For j = i + 1 To max - 1
					If a(j) = flag And flag <> "" Then
						a(j) = ""   
					End If
				Next
				If a(i) <> "" Then
					temp_str = temp_str & a(i) & " "
				End If
		   End If
		Next
		 
		 a = Split(temp_str, " ")
		 temp_str = ""
		 For i=0 to Ubound(a)
		  If Instr(KeyList,"|" & a(i) & "|")<>0 Then
		   temp_str =temp_str  & a(i) &  " "
		   If len(temp_str)>maxlen and maxlen<>0 then exit for
		  end if
		 Next
	   
		SplitKey=replace(trim(temp_str)," ",",")
	End Function
	
	'判断中文
	function iscn(str) 
		Dim i 
		i = Len(str) 
		If i = 0 Then 
		   iscn = False 
		   Exit Function 
		End If 
		
		Do While i > 0 
		  If Asc(Mid(str, i, 1)) < 10000 And Asc(Mid(str, i, 1)) > -10000 Then 
		    iscn = False 
		    Exit Function 
		  End If 
		  i = i - 1 
		Loop 
		iscn = True 
	end function 

End Class

%>