我要处理的文章长短差别很大,StringBuilder(int size)中的size定义很大,会影响性能吗? size大一点不会会影响性能,只是耗一点资源。『『我定义的size小于文本大小时,就出现错误』』应该不会,把你的代码贴出来看一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有大碍,先给分了关键代码如下:原因还是不清楚,定义为StringBuilder(),分词根本就无效只有定义size的长度超过最大文本长度,才没有错误发生麻烦triout(笨牛)看看了public Hashtable statWordInfreq(System.Text.StringBuilder strBefore){System.Text.StringBuilder result = new System.Text.StringBuilder(80480);//调用分词的dll,得到包含分词信息的0、1子串resulttry{//Application.StartupPath="C:\\Documents and Settings\\zjzhou\\My Documents\\Visual Studio Projects\\WinApp1\\WinApp1\\bin\\Debug\\"Form1.DivideSentence(Application.StartupPath+"\\",strBefore.ToString(),result); }catch{ }//处理result字串,获得以空格分割的词串strBefore,进而获得词数组split int j=0; while(j<result.ToString().Length-1) { if(result.ToString().Substring(j,1)=="2" || result.ToString().Substring(j,1)=="4") { result[j]=" ".ToString()[0]; strBefore[j]=" ".ToString()[0]; } if((result.ToString().Substring(j,1)=="0" && result.ToString().Substring(j+1,1)=="1") || (result.ToString().Substring(j,1)=="1" && result.ToString().Substring(j+1,1)=="0")) { result.Insert(j+1," ".ToString()[0]); strBefore.Insert(j+1," ".ToString()[0]); j=j+1; } j=j+1; } //将文本串strBefore分解成的词语并放入数组split中,其中包括了部分空字符,而且包括了所有的字词,并且有重复出现 string[] split=strBefore.ToString().Split(" ".ToString()[0]); //在包含文本中所有词语的数组中统计词频(方法二),方法一在参考代码中保存 //利用hashtable可以更好地改善性能,无需象ArrayList一样boxing和unboxing Hashtable ht = new Hashtable (); for (int i=0;i<split.Length;i++) { if(split[i].Length>1) { StruWord sw; string sWord = split[i].ToLower(); if (ht.Contains(sWord)) { sw = (StruWord)ht[sWord]; sw.inFreq++; ht[sWord] = sw; } else { sw = new StruWord(); sw.word=sWord; sw.inFreq=1; sw.weight=0; sw.outFreq=0; sw.totalFreq=0; ht[sWord] = sw; } } } return ht; } gridview中的删除事件RowDeleting执行一次后,刷新页面出现异常 谁能给我解释一道笔试题 remoting 的问题,急,在线等 水晶报表加载报表失败。初学水晶报表。谢谢大家! 为什么不能得到中文输入? 关于dataGrid获取某列数据问题 怎样更改输出时的乱码??(在线等待) 求教存储过程的问题,在线等! 如何实现在DataGrid控件上使用下拉列表框。 如何修改系统的时间? 水晶报表基础问题 请教两个C#问题,中英文系统下的差异 及 在窗体上播放媒体。
关键代码如下:
原因还是不清楚,定义为StringBuilder(),分词根本就无效
只有定义size的长度超过最大文本长度,才没有错误发生
麻烦triout(笨牛)看看了public Hashtable statWordInfreq(System.Text.StringBuilder strBefore)
{
System.Text.StringBuilder result = new System.Text.StringBuilder(80480);
//调用分词的dll,得到包含分词信息的0、1子串result
try
{
//Application.StartupPath="C:\\Documents and Settings\\zjzhou\\My Documents\\Visual Studio Projects\\WinApp1\\WinApp1\\bin\\Debug\\"
Form1.DivideSentence(Application.StartupPath+"\\",strBefore.ToString(),result);
}
catch
{
}
//处理result字串,获得以空格分割的词串strBefore,进而获得词数组split
int j=0;
while(j<result.ToString().Length-1)
{
if(result.ToString().Substring(j,1)=="2" || result.ToString().Substring(j,1)=="4")
{
result[j]=" ".ToString()[0];
strBefore[j]=" ".ToString()[0];
}
if((result.ToString().Substring(j,1)=="0" && result.ToString().Substring(j+1,1)=="1")
|| (result.ToString().Substring(j,1)=="1" && result.ToString().Substring(j+1,1)=="0"))
{
result.Insert(j+1," ".ToString()[0]);
strBefore.Insert(j+1," ".ToString()[0]);
j=j+1;
}
j=j+1; }
//将文本串strBefore分解成的词语并放入数组split中,其中包括了部分空字符,而且包括了所有的字词,并且有重复出现
string[] split=strBefore.ToString().Split(" ".ToString()[0]);
//在包含文本中所有词语的数组中统计词频(方法二),方法一在参考代码中保存
//利用hashtable可以更好地改善性能,无需象ArrayList一样boxing和unboxing
Hashtable ht = new Hashtable ();
for (int i=0;i<split.Length;i++)
{
if(split[i].Length>1)
{
StruWord sw;
string sWord = split[i].ToLower();
if (ht.Contains(sWord))
{
sw = (StruWord)ht[sWord];
sw.inFreq++;
ht[sWord] = sw;
}
else
{
sw = new StruWord();
sw.word=sWord;
sw.inFreq=1;
sw.weight=0;
sw.outFreq=0;
sw.totalFreq=0;
ht[sWord] = sw;
}
}
}
return ht;
}