在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.7 ICTCLAS_GetParagraphProcessAWordCountGet ProcessAWordCount, API for C# int ICTCLAS_GetParagraphProcessAWordCount(const char *sParagraph);
Return Value Return the paragraph word count. Parameters sParagraph: The source paragraph Remarks The ICTCLAS_GetParagraphProcessAWordCount function works properly only if ICTCLAS_Init succeeds. The output format is customized in ICTCLAS configure. Example
代码
using System;
using System.IO; using System.Runtime.InteropServices; namespace win_csharp { [StructLayout(LayoutKind.Explicit)] public struct result_t { [FieldOffset(0)] public int start; [FieldOffset(4)] public int length; [FieldOffset(8)] public int sPos; [FieldOffset(12)] public int sPosLow; [FieldOffset(16)] public int POS_id; [FieldOffset(20)] public int word_ID; [FieldOffset(24)] public int word_type; [FieldOffset(28)] public int weight; } /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { const string path = @"ICTCLAS30.dll"; [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_Init")] public static extern bool ICTCLAS_Init(String sInitDirPath); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_ParagraphProcess")] public static extern String ICTCLAS_ParagraphProcess(String sParagraph, int bPOStagged); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_Exit")] public static extern bool ICTCLAS_Exit(); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_ImportUserDict")] public static extern int ICTCLAS_ImportUserDict(String sFilename); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_FileProcess")] public static extern bool ICTCLAS_FileProcess(String sSrcFilename, String sDestFilename, int bPOStagged); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_FileProcessEx")] public static extern bool ICTCLAS_FileProcessEx(String sSrcFilename, String sDestFilename); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_GetParagraphProcessAWordCount")] static extern int ICTCLAS_GetParagraphProcessAWordCount(String sParagraph); //ICTCLAS_GetParagraphProcessAWordCount [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_ParagraphProcessAW")] static extern void ICTCLAS_ParagraphProcessAW(int nCount, [Out, MarshalAs(UnmanagedType.LPArray)] result_t[] result); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_AddUserWord")] static extern int ICTCLAS_AddUserWord(String sWord); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_SaveTheUsrDic")] static extern int ICTCLAS_SaveTheUsrDic(); [DllImport(path, CharSet = CharSet.Ansi, EntryPoint = "ICTCLAS_DelUsrWord")] static extern int ICTCLAS_DelUsrWord(String sWord); /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // if (!ICTCLAS_Init(null)) { System.Console.WriteLine("Init ICTCLAS failed!"); return; } String s = "点击下载超女纪敏佳深受观众喜爱。禽流感爆发在非典之后。"; int count = ICTCLAS_GetParagraphProcessAWordCount(s);//先得到结果的词数 result_t[] result = new result_t[count];//在客户端申请资源 ICTCLAS_ParagraphProcessAW(count, result);//获取结果存到客户的内存中 int i = 1; foreach (result_t r in result) { String sWhichDic = ""; switch (r.word_type) { case 0: sWhichDic = "核心词典"; break; case 1: sWhichDic = "用户词典"; break; case 2: sWhichDic = "专业词典"; break; default: break; } Console.WriteLine("No.{0}:start:{1}, length:{2},POS_ID:{3},Word_ID:{4}, UserDefine:{5}, Word:{6}\n", i++, r.start, r.length, r.POS_id, r.word_ID, sWhichDic, s.Substring(r.start / 2, r.length / 2)); } ICTCLAS_Exit(); } } }
Output 1.8 ICTCLAS_ ParagraphProcessAWProcess a paragraph, API for C# void ICTCLAS_ParagraphProcessAW(int nCount,result_t * result);
Return Value Parameters nCount: the paragraph word count. result: Pointer to structure to store results. Remarks The ICTCLAS_ParagraphProcessAW function works properly only if ICTCLAS_Init succeeds. The output format is customized in ICTCLAS configure. Example (见上1.7例子) Output
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论