[Feiqiu] C # Call

Source: Internet
Author: User

Although sharpictclas is open-source, no one has maintained it since, and there are many problems with the corpus used to run sogou. Even the author of C # admitted that there are many problems.

Instant Messaging Software
To get more accurate word splitting results, we should study sharpictclas3.0, or ICTCLAS 2009. DLL files are not developed by C #. Therefore, you must use the dllimport

First, I wrote a class myself.

Code

Using system;

Using system. Collections. Generic;

Using system. text;

Using system. runtime. interopservices;

Namespace Test

{

[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;

}

Class ictclas30

{

Const string Path = @ "ictclas30.dll ";

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_init")]

Public static extern bool Init (string sinitdirpath );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_paragraphprocess")]

Public static extern string paragraphprocess (string sparagraph, int bpostagged );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_exit")]

Public static extern bool exit ();

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_importuserdict")]

Public static extern int importuserdict (string sfilename );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_fileprocess")]

Public static extern bool fileprocess (string ssrcfilename, string sdestfilename, int bpostagged );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_fileprocessex")]

Public static extern bool fileprocessex (string ssrcfilename, string sdestfilename );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_getparagraphprocessawordcount")]

Public static extern int getparagraphprocessawordcount (string sparagraph );

// Ictclas_getparagraphprocessawordcount

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_paragraphprocessaw")]

Public static extern void paragraphprocessaw (INT ncount, [out, financialas (unmanagedtype. lparray)] result_t [] result );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_adduserword")]

Public static extern int adduserword (string sword );

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_savetheusrdic")]

Public static extern int savetheusrdic ();

[Dllimport (path, charset = charset. ANSI, entrypoint = "ictclas_delusrword")]

Static extern int delusrword (string sword );

Public ictclas30 ()

{

}

}

}

Call:

Code

If (! Ictclas30.init (null ))

{

System. Console. writeline ("init ICTCLAS failed! ");

Return;

}

System. Console. writeline ("init ICTCLAS success! ");

String presult;

Presult = ictclas30.paragraphprocess ("click to download Super Girl Ji minjia is very popular among viewers. Bird flu outbreaks after SARS. ", 1 );

System. Console. writeline (presult );

Ictclas30.exit ();

Note:

Copy the ictclas30.dll, configure. XML, and data folders to the path where the program EXE runs. Otherwise, you need to specify their location.

How to Make presult into the wordresult format in yesterday's blog is still a problem. You also need to study www.qichepeijian.com ....

Attached: C # Call example on the official website

Code

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>

/// Summary of 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 ();

/// <Summary>

/// Main entry point of the application.

/// </Summary>

[Stathread]

Static void main (string [] ARGs)

{

//

// Todo: Add code here to start the application

//

If (! Ictclas_init (null ))

{

System. Console. writeline ("init ICTCLAS failed! ");

Return;

}

System. Console. writeline ("init ICTCLAS success! ");

String presult;

Presult = ictclas_paragraphprocess ("click to download the Super Girl Ji minjia, which is favored by the audience. Bird flu outbreaks after SARS. ", 1 );

System. Console. writeline (presult );

Ictclas_exit ();

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.