Language detection tool

Source: Internet
Author: User

I will give you a piece of text to check the language? Two open-source projects are available. One is Apache Tika and the other is language-detection. Language-detection is an open-source software package for language detection on Google Code. It is ready for use on a daily basis. Its Project LINK is http://code.google.com/p/?age-detection. Basically, you just need to reference langdetect. jar and its dependent jsonic-1.3.0.jar (also Japanese). Below is a simple example.

 

Create a Java project, introduce the above two jar packages into the project, and create a test class, as shown below:

Import Java.net. urisyntaxexception;

ImportCom. cybozu. Labs. langdetect .*;

/**
*@ AuthorXxx
*
 */
Public ClassLangtest
{

/**
* @ Param ARGs
*/
Public Static Void Main (string [] ARGs)
{
Try
{
Detectorfactory. loadprofile (thread. currentthread (). getcontextclassloader (). getresource ("Lang"). getpath ());
} Catch (Langdetectexception E)
{
E. printstacktrace ();
}

Detector detect;
Try
{
Detect = detectorfactory. Create ();
Detect. append ("A depends on ");
System. Out. println (detect. Detect ());
} Catch (Langdetectexception E)
{
E. printstacktrace ();
}

}

}

The result of this text is ZH-CN, which is very simple.

 

The basic initialization of language-detection is completed by detectorfactory. Before testing, you need to load the Language Pack (in fact, it is a sample of each language, you can add it yourself ). The Language Pack was initially added using the addprofile method. Its prototype is addprofile (langprofile profile, int index, int langsize). You can build your own vocabulary and then add it using the addprofile method. You can also use the loadprofile method to load all the language files in a directory (according to the required format, the downloaded jar package has a sample) at one time. The next step is simple. Create a detector through detectorfactory and append the text to be detected. After detect, the system returns the language category and closes the job.

 

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.