程序代码:
using System;
using System.Drawing;
using System.Text;
using System.Collections;
using using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ChineseParse
{
public struct SHLSegWord
{
public string s_szWord; //字符串
public int s_dwPOS; //词性标志
public float s_fWeight ;//关键词权重,如果不是关键词,权重为0
//System.UInt32
}
/// <summary>
/// HLParse 的摘要说明。
/// </summary>
public class frmHLParse : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox txtOutput;
private System.Windows.Forms.RichTextBox txtInput;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnParse;
private string m_strKey;
private string m_strWords;
private string m_strFinger;
/************************************************************/
// 常量定义部分 //
/************************************************************/
const int HL_CAL_OPT_KEYWORD = 0x1; //计算关键词附加标识
const int HL_CAL_OPT_FINGER = 0x2; //计算文章语义指纹标识
const int HL_CAL_OPT_POS = 0x4;//计算词性标识
const int HL_CAL_OPT_SEARCH = 0x8;//输出面向检索的分词结果
/************************************************************/
// 词性定义部分 //
/************************************************************/
public const int NATURE_D_A=0x40000000; // 形容词 形语素
public const int NATURE_D_B=0x20000000; // 区别词 区别语素
public const int NATURE_D_C=0x10000000; // 连词 连语素
public const int NATURE_D_D=0x08000000; // 副词 副语素
public const int NATURE_D_E=0x04000000; // 叹词 叹语素
public const int NATURE_D_F=0x02000000; // 方位词 方位语素
public const int NATURE_D_I=0x01000000; // 成语
public const int NATURE_D_L=0x00800000; // 习语
public const int NATURE_A_M=0x00400000; // 数词 数语素
public const int NATURE_D_MQ=0x00200000; // 数量词
public const int NATURE_D_N=0x00100000; // 名词 名语素
public const int NATURE_D_O=0x00080000; // 拟声词
public const int NATURE_D_P=0x00040000; // 介词
public const int NATURE_A_Q=0x00020000; // 量词 量语素
public const int NATURE_D_R=0x00010000; // 代词 代语素
public const int NATURE_D_S=0x00008000; // 处所词
public const int NATURE_D_T=0x00004000; // 时间词
public const int NATURE_D_U=0x00002000; // 助词 助语素
public const int NATURE_D_V=0x00001000; // 动词 动语素
public const int NATURE_D_W=0x00000800; // 标点符号
public const int NATURE_D_X=0x00000400; // 非语素字
public const int NATURE_D_Y=0x00000200; // 语气词 语气语素
public const int NATURE_D_Z=0x00000100; // 状态词
public const int NATURE_A_NR=0x00000080; // 人名
public const int NATURE_A_NS=0x00000040; // 地名
public const int NATURE_A_NT=0x00000020; // 机构团体
public const int NATURE_A_NX=0x00000010; // 外文字符
public const int NATURE_A_NZ=0x00000008; // 其他专名
public const int NATURE_D_H=0x00000004;
private System.Windows.Forms.RichTextBox txtKey;
private System.Windows.Forms.CheckBox chkPos;
private System.Windows.Forms.CheckBox chkSeach;
private System.Windows.Forms.Label txtMsg;
private System.Windows.Forms.CheckBox chkKeyword;
private System.Windows.Forms.CheckBox chkFinger;
private System.Windows.Forms.Label lblFinger;
private System.Windows.Forms.Button btn; // 前接成分
public const int NATURE_D_K=0x00000002; // 后接成分
//初始化分词词典
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLSplitInit ")]
private static extern bool HLSplitInit(string path);
//创建分词句柄
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLOpenSplit ")]
private static extern IntPtr HLOpenSplit();
//对一段字符串分词
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLSplitWord ")]
private static extern bool HLSplitWord(IntPtr pHandle,string text,int flag);
//取得分词个数
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLGetWordCnt ")]
private static extern int HLGetWordCnt(IntPtr pHandle);
//获取指定的分词结果
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLGetWordAt ")]
private static extern IntPtr HLGetWordAt(IntPtr pHandle,int pos);
//获取关键词个数
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLGetFileKeyCnt ")]
private static extern int HLGetFileKeyCnt(IntPtr pHandle);
//获取指定下标的关键词
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLGetFileKeyAt ")]
private static extern IntPtr HLGetFileKeyAt(IntPtr pHandle,int pos);
//装载用户自定义词典
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLOpenUsrDict ")]
private static extern bool HLOpenUsrDict(string lpUserDictName);
//卸载用户自定义词典
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLFreeUsrDict ")]
private static extern bool HLFreeUsrDict();
//获得语义指纹
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLGetFingerM ")]
private static extern bool HLGetFingerM(IntPtr hHandle,ref IntPtr rpData, ref Int32 rdwLen);
//关闭分词句柄
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLCloseSplit ")]
private static extern void HLCloseSplit(IntPtr pHandle);
//海量分词系统卸载
[DllImport( "HLSSplit.dll ",SetLastError=true,EntryPoint= "HLFreeSplit ")]
private static extern void HLFreeSplit();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private null;
public frmHLParse()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}