?? formdemo.cs
字號(hào):
?/***************************************************************************************
* KTDictSeg 簡介: KTDictSeg 是由KaiToo搜索開發(fā)的一款基于字典的簡單中英文分詞算法
* 主要功能: 中英文分詞,未登錄詞識(shí)別,多元歧義自動(dòng)識(shí)別,全角字符識(shí)別能力
* 主要性能指標(biāo):
* 分詞準(zhǔn)確度:90%以上(有待專家的權(quán)威評(píng)測)
* 處理速度: 600KBytes/s
*
* 版本: V1.2.02
* Copyright(c) 2007 http://www.kaitoo.com
* 作者:肖波
* 授權(quán): 開源GPL
* 公司網(wǎng)站: http://www.kaitoo.com
* 個(gè)人博客: http://blog.csdn.net/eaglet; http://www.cnblogs.com/eaglet
* 聯(lián)系方式: blog.eaglet@gmail.com
* ***************************************************************************************/
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using KTDictSeg;
using FTAlgorithm;
namespace Demo
{
public partial class FormDemo : Form
{
public static CSimpleDictSeg m_SimpleDictSeg;
String m_InitSource = "KTDictSeg 簡介: KTDictSeg 是由KaiToo搜索開發(fā)的一款基于字典的簡單中英文分詞算法\r\n"+
"主要功能: 中英文分詞,未登錄詞識(shí)別,多元歧義自動(dòng)識(shí)別,全角字符識(shí)別能力\r\n" +
"主要性能指標(biāo):\r\n" +
"分詞準(zhǔn)確度:90%以上(有待專家的權(quán)威評(píng)測)\r\n" +
"處理速度: 600KBytes/s\r\n" +
"用于測試的句子:\r\n" +
"長春市長春節(jié)致詞\r\n" +
"長春市長春藥店\r\n" +
"IBM的技術(shù)和服務(wù)都不錯(cuò)\r\n" +
"張三在一月份工作會(huì)議上說的確實(shí)在理\r\n" +
"于北京時(shí)間5月10日舉行運(yùn)動(dòng)會(huì)\r\n"+
"我的和服務(wù)必在明天做好" ;
public FormDemo()
{
InitializeComponent();
}
private void DisplaySegmentAndPostion()
{
if (m_SimpleDictSeg == null)
{
try
{
m_SimpleDictSeg = new CSimpleDictSeg();
m_SimpleDictSeg.LoadConfig("KTDictSeg.xml");
checkBoxFreqFirst.Checked = m_SimpleDictSeg.FreqFirst;
checkBoxAutoStudy.Checked = m_SimpleDictSeg.AutoStudy;
checkBoxFilterStopWords.Checked = m_SimpleDictSeg.FilterStopWords;
checkBoxMatchName.Checked = m_SimpleDictSeg.MatchName;
numericUpDownAutoSaveInterval.Value = m_SimpleDictSeg.AutoSaveInterval;
numericUpDownUnknownWordsThreshold.Value = m_SimpleDictSeg.UnknownWordsThreshold;
//m_SimpleDictSeg.DictPath = @"..\..\..\Data\";
m_SimpleDictSeg.LoadDict();
}
catch (Exception e1)
{
m_SimpleDictSeg = null;
MessageBox.Show(String.Format("Load Dict Fail! ErrMsg:{0}", e1.Message),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else
{
m_SimpleDictSeg.FreqFirst = checkBoxFreqFirst.Checked;
m_SimpleDictSeg.AutoStudy = checkBoxAutoStudy.Checked;
m_SimpleDictSeg.FilterStopWords = checkBoxFilterStopWords.Checked;
m_SimpleDictSeg.MatchName = checkBoxMatchName.Checked;
m_SimpleDictSeg.AutoSaveInterval = (int)numericUpDownAutoSaveInterval.Value;
m_SimpleDictSeg.UnknownWordsThreshold = (int)numericUpDownUnknownWordsThreshold.Value;
}
Stopwatch watch = new Stopwatch();
watch.Start();
List<T_WordInfo> words = m_SimpleDictSeg.SegmentToWordInfos(textBoxSource.Text);
watch.Stop();
labelSrcLength.Text = textBoxSource.Text.Length.ToString();
labelSegTime.Text = watch.Elapsed.ToString();
if (watch.ElapsedMilliseconds == 0)
{
labelRegRate.Text = "無窮大";
}
else
{
labelRegRate.Text = ((double)(textBoxSource.Text.Length / watch.ElapsedMilliseconds) * 1000).ToString();
}
StringBuilder wordsString = new StringBuilder();
foreach (T_WordInfo wordInfo in words)
{
wordsString.AppendFormat("{0}({1})/", wordInfo.Word, wordInfo.Position);
}
textBoxSegwords.Text = wordsString.ToString();
}
private void DisplaySegment()
{
if (m_SimpleDictSeg == null)
{
try
{
m_SimpleDictSeg = new CSimpleDictSeg();
m_SimpleDictSeg.LoadConfig("KTDictSeg.xml");
checkBoxFreqFirst.Checked = m_SimpleDictSeg.FreqFirst;
checkBoxAutoStudy.Checked = m_SimpleDictSeg.AutoStudy;
checkBoxFilterStopWords.Checked = m_SimpleDictSeg.FilterStopWords;
checkBoxMatchName.Checked = m_SimpleDictSeg.MatchName;
numericUpDownAutoSaveInterval.Value = m_SimpleDictSeg.AutoSaveInterval;
numericUpDownUnknownWordsThreshold.Value = m_SimpleDictSeg.UnknownWordsThreshold;
//m_SimpleDictSeg.DictPath = @"..\..\..\Data\";
m_SimpleDictSeg.LoadDict();
}
catch (Exception e1)
{
m_SimpleDictSeg = null;
MessageBox.Show(String.Format("Load Dict Fail! ErrMsg:{0}", e1.Message),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else
{
m_SimpleDictSeg.FreqFirst = checkBoxFreqFirst.Checked;
m_SimpleDictSeg.AutoStudy = checkBoxAutoStudy.Checked;
m_SimpleDictSeg.FilterStopWords = checkBoxFilterStopWords.Checked;
m_SimpleDictSeg.MatchName = checkBoxMatchName.Checked;
m_SimpleDictSeg.AutoSaveInterval = (int)numericUpDownAutoSaveInterval.Value;
m_SimpleDictSeg.UnknownWordsThreshold = (int)numericUpDownUnknownWordsThreshold.Value;
}
Stopwatch watch = new Stopwatch();
watch.Start();
List<String> words = m_SimpleDictSeg.Segment(textBoxSource.Text);
watch.Stop();
labelSrcLength.Text = textBoxSource.Text.Length.ToString();
labelSegTime.Text = watch.Elapsed.ToString();
if (watch.ElapsedMilliseconds == 0)
{
labelRegRate.Text = "無窮大";
}
else
{
labelRegRate.Text = ((double)(textBoxSource.Text.Length / watch.ElapsedMilliseconds) * 1000).ToString();
}
StringBuilder wordsString = new StringBuilder();
foreach (String str in words)
{
wordsString.AppendFormat("{0}/", str);
}
textBoxSegwords.Text = wordsString.ToString();
}
private void buttonSegment_Click(object sender, EventArgs e)
{
if (checkBoxDisplayPosition.Checked)
{
DisplaySegmentAndPostion();
}
else
{
DisplaySegment();
}
}
private void FormDemo_Load(object sender, EventArgs e)
{
textBoxSource.Text = m_InitSource;
DisplaySegment();
}
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(((LinkLabel)sender).Text);
}
private void comboBoxMatchDir_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void buttonTrafficPos_Click(object sender, EventArgs e)
{
if (m_SimpleDictSeg == null)
{
return;
}
FormTrafficPos frmTrafficPos = new FormTrafficPos();
frmTrafficPos.Show();
}
private void buttonSaveConfig_Click(object sender, EventArgs e)
{
m_SimpleDictSeg.SaveConfig("KTDictSeg.xml");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -