开发者

Find the language of a string in c# [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Return the language of a given string

In my program I have to find the language of an input string. For example, if an user enters

 "hello world" 

the language detecte开发者_如何学Pythond is English and if an user enters

"RUE"

it should be French.

Currently, in my project an user can input French or English.

I tried using CultureInfo class but I didn't get anything fruitful.


I think you need to include the language dictionary and then match the words enter to predict the accurate language in which the input is provided.

TextCat is very good for language identification. And it has a lot of implementations in different languages.

Ivan Akcheurov has produced a version with no ports, which can be found HERE.

It is pure .Net Framework dll + command line interface to it. It is fully compatible with 74 language models from TextCat, so it is capable of detecting language out of the box.


There's no build in functionality, and it's not a trivial task but take a look at this question and answer. If you have a large enough learning base then it can be used to determine the language a text is written in. It's always going to be a best guess, since some text such as medical english uses a lot of words that you'd find in French text (or at least where the words are more similar to Franch than English even if the text is written in English)

An very good example on how difficult it can be to determine the language, especially when the text is short is actually "rue". It's French for street but is also a city in at least 4 different countries, so there's five possible languages. One being French and One being English. (There's a town in Virginia calle Rue)


There is no such built-in functionality in .NET, so you need to implement it by yourself (which is very expensive resource-wise) or to try to take advantage of public services such as google translate which might be (or might be not) useful for this task.


The Google Translate API supports detecting the language of a string. This is a paid service, but probably worth the money.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜