How to determine language of text in your application

The easiest way to determine the language of text specified is like this:

// Don't forget to deploy a language profile (e.g. Core14.profile.xml) with your application.
// You can do it with referencing a language profile as content that should be copied to output
// in your application project (.exe, website, etc.).
// Language profiles are located either in <NTextCatRelease>\LanguageModels\
// or <YOURSOLUTION>\packages\IvanAkcheurov.NTextCat.Lib.0.2.1.1\ (if you get NTextCat from NuGet)
var factory = new RankedLanguageIdentifierFactory();
var identifier = factory.Load("Core14.profile.xml");
var languages = identifier.Identify("your text to get its language identified");
var mostCertainLanguage = languages.FirstOrDefault();
if (mostCertainLanguage != null)  
    Console.WriteLine("The language of the text is '{0}' (ISO639-3 code)", mostCertainLanguage.Item1.Iso639_3);  
else 
    Console.WriteLine("The language couldn’t be identified with an acceptable degree of certainty");

Last edited Dec 26, 2013 at 10:36 PM by IvanAkcheurov, version 2

Comments

No comments yet.