Java calls ICTCLAS Chinese Word Segmentation package through JNI

Source: Internet
Author: User

2) create a Java project with the class code:
Public class Exec {
Public static void main (String [] args ){
Try {
ICTCLAS. I3S. AC. ICTCLAS50 testICTCLAS50 = new ICTCLAS. I3S. AC. ICTCLAS50 ();
// Path of the library required for word splitting
String argu = ".";
// Initialization
If (testICTCLAS50.ICTCLAS _ Init (argu. getBytes ("GB2312") = false ){
System. out. println ("Init Fail! ");
Return;
} Else {
System. out. println ("Init Succeed! ");
}
String sInput = "Let's try Java's JNI call method today. ";
Byte nativeBytes [] = testICTCLAS50.ICTCLAS _ ParagraphProcess (sInput
. GetBytes ("GB2312"), 0, 1 );
System. out. println (nativeBytes. length );
String nativeStr = new String (nativeBytes, 0, nativeBytes. length,
"GB2312 ");
System. out. println ("The result is:" + nativeStr );
TestICTCLAS50.ICTCLAS _ Exit ();
} Catch (Exception ex ){
}
}
} Www.2cto.com
 

3) Add the source code in the API directory of the compressed package, that is, the ICTCLAS50 in the ictclas \ I3S \ AC package to the project.
 
4) put all the other files in the API directory of the compressed package directly to the root directory of the current project.
 
To run
 
Input:
Init Succeed!
68
The result is: We/rr today/t try/v/m try/v Java/x/ude1 JNI/x call method/n. /Wj

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.