|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
把原附件中用到的分词引擎的相关代码提取出来,简单应用一下:
- Dim tempstr
- Public attr As String
- Public topnum As Integer
- Sub SplitCN(Target, attr, topnum) '参数1:Target 为待统计的Unicode字符串;参数2:为要求统计的词语类型代码,其中,名词为n;参数3:要求列出统计结果最高的topnum项
- Dim StrHTML$, lStart&, lEnd&, dua$, Ign$
- sendstr = "mydata=" & Target & "&stats=yes&limit=" & topnum & "&xattr=" & attr
- With CreateObject("Msxml2.XMLHTTP")
- .Open "POST", "http://www.xunsearch.com/scws/demo/v48.php", False '由"http://www.xunsearch.com/scws 提供的分词引擎
- .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
- .send sendstr
- StrHTML = .responseText
- End With
- lStart = InStrRev(StrHTML, "<textarea")
- lEnd = InStrRev(StrHTML, "</textarea>")
- StrHTML = Mid(StrHTML, lStart, lEnd - lStart - 2)
- StrHTML = Right(StrHTML, Len(StrHTML) - InStr(StrHTML, ">") - 1)
- StrHTML = Right(StrHTML, Len(StrHTML) - InStr(StrHTML, "-" & Chr(10) & "01.") - 1)
- ' tempstr = Split(Trim(StrHTML), Chr(10))
- tempstr = Trim(StrHTML)
- End Sub
- Sub cs()
- Const attr = "n" '仅分析名词
- Const topnum = 100 '列出词频最高的前100项
- r = Cells(65536, 1).End(xlUp).Row
- arr = Range("A1").Resize(r, 1)
- For i = 2 To r
- If Len(arr(i, 1)) Then Call SplitCN(arr(i, 1), attr, topnum) 'StrConv(InputB$(LOF(1), 1), vbUnicode)
- arr(i, 1) = tempstr
- Next
- arr(1, 1) = "关键词统计结果"
- Range("A1").CurrentRegion.Resize(, 1).Offset(, 1) = arr
- End Sub
复制代码 |
|