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

TheICTCLAS_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 POS_id;

        [FieldOffset(
12)]
        
public int word_ID;

    }

    
/// <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_GetParagraphProcessAWordCount")]

        
static extern int ICTCLAS_GetParagraphProcessAWordCount(String sParagraph);

        [DllImport(path, CharSet 
= CharSet.Ansi, EntryPoint = "ICTCLAS_ParagraphProcessAW")]

        
static extern void ICTCLAS_ParagraphProcessAW(int nCount, [Out, MarshalAs(UnmanagedType.LPArray)] result_t[] result);

        
/// <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)
            {

                Console.WriteLine(
"No.{0}:start:{1}, length:{2},POS_ID:{3},Word_ID:{4}\n", i++, r.start, r.length, r.POS_id, r.word_ID);

            }



            String pResult;

            
//音乐会上还演奏了小提琴协奏曲《梁山伯与祝英台》、

            pResult 
= ICTCLAS_ParagraphProcess("点击下载超女纪敏佳深受观众喜爱。禽流感爆发在非典之后。"1);

            System.Console.WriteLine(
"Before Userdict imported:");

            System.Console.WriteLine(pResult);





            
int nCount = ICTCLAS_ImportUserDict("userdict.txt");//Import Userdict

            System.Console.WriteLine(nCount);



            pResult 
= ICTCLAS_ParagraphProcess("点击下载超女纪敏佳深受观众喜爱。禽流感爆发在非典之后。"0);

            System.Console.WriteLine(
"After Userdict imported:");

            System.Console.WriteLine(pResult);







            System.Console.WriteLine(
"Input Sentence Now!(q to quit)\n");

            String sInput 
= System.Console.ReadLine();

            
while (sInput.CompareTo("q"!= 0)
            {

                pResult 
= ICTCLAS_ParagraphProcess(sInput, 1);

                System.Console.WriteLine(
"Resut:");

                System.Console.WriteLine(pResult);

                System.Console.WriteLine(
"\nInput Sentence Now!(q to quit)\n");

                sInput 
= System.Console.ReadLine();

            }

            ICTCLAS_FileProcess(
"Input.txt""Input_result.txt"1);

            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

TheICTCLAS_ParagraphProcessAW function works properly only if ICTCLAS_Init succeeds.

The output format is customized in ICTCLAS configure.

Example

(见上1.7例子)

Output

 

 

from:http://ictclas.org/hottopic_003.html