/// <summary> /// Example code to call Rosette API to detect possible languages for a piece of text. /// Requires Nuget Package: /// rosette_api /// </summary> static void Main(string[] args) { //To use the C# API, you must provide an API key string apikey = "Your API key"; string alturl = string.Empty; //You may set the API key via command line argument: //language yourapikeyhere if (args.Length != 0) { apikey = args[0]; alturl = args.Length > 1 ? args[1] : string.Empty; } try { CAPI LanguageCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl); string language_data = @"Por favor Señorita, says the man."; //The results of the API call will come back in the form of a Dictionary LanguageCAPI.SetCustomHeaders("X-RosetteAPI-App", "csharp-app"); LanguageIdentificationResponse response = LanguageCAPI.Language(language_data); foreach (KeyValuePair <string, string> h in response.Headers) { Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value)); } Console.WriteLine(response.ToString()); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
/// <summary> /// Example code to call Rosette API to detect possible languages for a piece of text. /// Requires Nuget Package: /// rosette_api /// </summary> static void Main(string[] args) { //To use the C# API, you must provide an API key string apikey = "Your API key"; string alturl = string.Empty; //You may set the API key via command line argument: //language yourapikeyhere if (args.Length != 0) { apikey = args[0]; alturl = args.Length > 1 ? args[1] : string.Empty; } try { CAPI LanguageCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl); string language_multilingual_data = @"On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة ""د هـ ك ب ج"" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."; LanguageCAPI.SetCustomHeaders("X-RosetteAPI-App", "csharp-app"); LanguageCAPI.SetOption("multilingual", "true"); //The results of the API call will come back in the form of a Dictionary LanguageIdentificationResponse response = LanguageCAPI.Language(language_multilingual_data); foreach (KeyValuePair <string, string> h in response.Headers) { Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value)); } Console.WriteLine(response.ToString()); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public Dictionary <string, string> DetectedLanguage(string word, string idUser) { Database.UserTable.IncreaseCountRequest(word, idUser); Dictionary <string, string> languages = new Dictionary <string, string> { { "rus", "Russian" }, { "eng", "English" }, { "spa", "Spanish" }, { "bul", "Bulgarian" }, { "por", "Portuguese" } }; Dictionary <string, string> dictionaryResult; Dictionary <string, decimal?> matchLanguages = new Dictionary <string, decimal?>(); dictionaryResult = Database.UserTable.GetSavedRequest(word); if (dictionaryResult.Count == 0) { string apikey = ConfigurationManager.AppSettings["apikey"]; CAPI LanguageCAPI = new CAPI(apikey); LanguageCAPI.SetCustomHeaders("X-RosetteAPI-App", "csharp-app"); LanguageIdentificationResponse response = LanguageCAPI.Language(word); decimal?allLanguageValue = 0; foreach (var language in response.LanguageDetections) { if (languages.ContainsKey(language.Language)) { allLanguageValue += language.Confidence; matchLanguages.Add(language.Language, language.Confidence); } } foreach (var language in languages) { if (matchLanguages.Keys.Contains(language.Key)) { dictionaryResult.Add(language.Value, String.Format("{0:0.##}%", matchLanguages[language.Key].Value * 100 / allLanguageValue)); } else { dictionaryResult.Add(language.Value, "0%"); } } Database.UserTable.SaveRequest(dictionaryResult, word); } return(dictionaryResult); }