• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ICTCLAS2009接口文档C#

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.7 ICTCLAS_GetParagraphProcessAWordCount

Get ProcessAWordCount, API for C#

int ICTCLAS_GetParagraphProcessAWordCount(const char *sParagraph);

 

Routine

Required Header

ICTCLAS_FileProcess

<ICTCLAS30.h>

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_ ParagraphProcessAW

Process a paragraph, API for C#

void ICTCLAS_ParagraphProcessAW(int nCount,result_t * result);

 

Routine

Required Header

ICTCLAS_FileProcess

<ICTCLAS30.h>

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

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#连接sqlserver数据库发布时间:2022-07-10
下一篇:
C#程序性能提升篇-1、装箱和拆箱,枚举的ToString浅析发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap