public void DetectLanguage(string text) { int count = Text.GetCountOfWords(text); string lanCode = ld.Detect(text); string languageNaturalName; if (lanCode == null) { languageNaturalName = "Not detected"; } else { languageNaturalName = ld.GetLanguageNameByCode(lanCode); } lock (locker) { if (m_wordCount.ContainsKey(languageNaturalName)) { m_wordCount[languageNaturalName] += count; } else { m_wordCount.Add(languageNaturalName, count); } } }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { _roomsDictionary = new Dictionary <string, string>(); var rooms = _roomService.GetRooms(); foreach (var room in rooms) { _roomsDictionary.Add(room.Address, room.Name); } var message = await item; var detector = new LanguageDetector(); var defaultLanguage = ConfigurationManager.AppSettings["BotDefaultLanguage"]; var localLanguage = ConfigurationManager.AppSettings["BotLocalLanguage"]; detector.AddLanguages(defaultLanguage, localLanguage); // issue; when message.Text is in Japanese.Detect(message.Text)) will give null _detectedCulture = Equals(defaultLanguage, detector.Detect(message.Text)) ? ConfigurationManager.AppSettings["BotDefaultCulture"] : ConfigurationManager.AppSettings["BotLocalCulture"]; SetCulture(_detectedCulture); accessToken = await GetAccessToken("graph"); accessToken_office = await GetAccessToken("office"); PromptDialog.Text(context, SubjectMessageReceivedAsync, Properties.Resources.Text_PleaseEnterSubject); }
private void Test(string lang, string[] texts, string[][] pairs = null) { LanguageDetector detector; detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddAllLanguages(); foreach (string text in texts) { Assert.AreEqual(lang, detector.Detect(text)); } if (pairs != null) { foreach (string[] pair in pairs) { detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddLanguages(pair); detector.AddLanguages(lang); foreach (string text in texts) { Assert.AreEqual(lang, detector.Detect(text)); } } } }
public static Language MainProgram(string stringInput) { Stopwatch stopwatch = new Stopwatch(); Language lang = new Language(); stopwatch.Start(); var learner = new LanguageLearner(); var knownLanguages = learner.Remember(knownLanguagesFile); var detector = new LanguageDetector(knownLanguages); int score; var languageCode = detector.Detect(stringInput, out score); lang.inputString = stringInput; lang.languageType = languageCode; lang.probability = score; lang.nGramProbability = score; switch (languageCode) { case "en": lang = fastBrainProcessEnglish(lang, stopwatch); break; case "es": lang = fastBrainProcessSpanish(lang, stopwatch); break; case "ru": lang = fastBrainProcessRussian(lang, stopwatch); break; default: // Launch Error Window? Loc: I handle this by outputing result = "Undefined" when probability = 0% break; } if (lang.probability < 50) { Stopwatch stopwatch2 = new Stopwatch(); stopwatch2.Start(); //Thread.Sleep(2999);//This line right here should be eliminated. I'm just including a 2999s delay to simulte the Slow BP. Diego // Slow Brain processes lang = SlowBrainProcess.SlowBrainProcessing(lang); stopwatch2.Stop(); TimeSpan ts = stopwatch2.Elapsed; double second = ts.Seconds; double milisecond = ts.Milliseconds; double TIME = second * 1000 + milisecond; lang.slowBrainRuntime = TIME; } return(lang); }
static void Test() { const string testFilesPath = @"C:\Users\kevin\Desktop\data"; var learner = new LanguageLearner(); var english = learner.Learn("en", Path.Combine(testFilesPath, "en-source.txt")); var dutch = learner.Learn("nl", Path.Combine(testFilesPath, "nl-source.txt")); var spanish = learner.Learn("es", Path.Combine(testFilesPath, "es-source.txt")); var bulgarian = learner.Learn("bg", Path.Combine(testFilesPath, "bg-source.txt")); var russian = learner.Learn("ru", Path.Combine(testFilesPath, "ru-source.txt")); var german = learner.Learn("de", Path.Combine(testFilesPath, "de-source.txt")); var languages = new Dictionary <string, Dictionary <string, int> > { { "en", english }, { "nl", dutch }, { "es", spanish }, { "bg", bulgarian }, { "ru", russian }, { "de", german }, }; var detector = new LanguageDetector(languages); int scoreEnglish; var testEnglish = detector.Detect(Path.Combine(testFilesPath, "en-sample.txt"), out scoreEnglish); int scoreDutch; var testDutch = detector.Detect(Path.Combine(testFilesPath, "nl-sample.txt"), out scoreDutch); int scoreSpanish; var testSpanish = detector.Detect(Path.Combine(testFilesPath, "es-sample.txt"), out scoreSpanish); int scoreBulgarian; var testBulgarian = detector.Detect(Path.Combine(testFilesPath, "bg-sample.txt"), out scoreBulgarian); int scoreRussian; var testRussian = detector.Detect(Path.Combine(testFilesPath, "ru-sample.txt"), out scoreRussian); int scoreGerman; var testGerman = detector.Detect(Path.Combine(testFilesPath, "de-sample.txt"), out scoreGerman); Console.WriteLine("Test 1: {0} ({1}%)", testEnglish, scoreEnglish); Console.WriteLine("Test 2: {0} ({1}%)", testDutch, scoreDutch); Console.WriteLine("Test 3: {0} ({1}%)", testSpanish, scoreSpanish); Console.WriteLine("Test 4: {0} ({1}%)", testBulgarian, scoreBulgarian); Console.WriteLine("Test 5: {0} ({1}%)", testRussian, scoreRussian); Console.WriteLine("Test 6: {0} ({1}%)", testGerman, scoreGerman); }
static void Detect(string file, string knownLanguagesFile) { var learner = new LanguageLearner(); var knownLanguages = learner.Remember(knownLanguagesFile); var detector = new LanguageDetector(knownLanguages); int score; var languageCode = detector.Detect(file, out score); Console.WriteLine("The language code of the detected language is: {0} ({1}%)", languageCode, score); }
public static void Main(string[] args) { Console.WriteLine("Starting app..."); ILanguageDetector languageDetector = new LanguageDetector(); languageDetector.LoadProfile(@"~/../../../../languagedetector.net/profiles/profiles/"); var language = languageDetector.Detect("This is a test to test the language."); Console.WriteLine("Language picked up: {0}", language.LanguageCode); Console.WriteLine("Done...Press any key to quit"); Console.ReadKey(); }
public AnswerModel <string> Execute(string text) { AnswerModel <string> answer = new AnswerModel <string>(); LanguageDetector detector = new LanguageDetector(); detector.AddAllLanguages(); Assert.AreEqual("lv", detector.Detect("Привет")); answer.Property = "Определен язык: "; answer.Value = "Определен язык: "; return(answer); }
private static bool IsValidWord(string word, LanguageDetector languageDetector, string languageName) { if (languageDetector != null) { var detectedLanguage = languageDetector.Detect(word); return(detectedLanguage != null && detectedLanguage.Equals(languageName)); } else { var nonCharEntries = word.Where(c => !Char.IsLetter(c)); return(!nonCharEntries.Any()); } }
private void DetectLanguageIfRequired() { string newSourceCode = sourceCodeTextBox.Text; if (!fileOpened && (!string.IsNullOrEmpty(newSourceCode) && string.IsNullOrEmpty(oldSourceCode))) { Task.Factory.StartNew(() => { var detectedLanguage = (Language)languageDetector.Detect(newSourceCode); Dispatcher.UIThread.InvokeAsync(() => SelectedLanguage = detectedLanguage); }); Dispatcher.UIThread.InvokeAsync(() => OpenedFileName = ""); } fileOpened = false; }
public void UpdateIndexedWords(bool detectLanguage) { var words = new List <string>(); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.AssignedTo.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.State.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.Title.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.WorkItemType.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).Add(this.Id.ToString()); words = words.Distinct().ToList(); if (detectLanguage) { StopWords.FilterStopWords(words, LanguageDetector.Detect(Title) ?? "en"); } _indexedWords = string.Join(" ", words); }
private void TranslateBtn_Clicked(object sender, EventArgs e) { AzureAuthToken azureAuthToken = new AzureAuthToken("731cf5d466e543409989ce06c9499979"); var authToken = azureAuthToken.GetAccessToken(); LanguageDetector languageDetector = new LanguageDetector(authToken); var lang = languageDetector.Detect(toTranslate.Text); Translator translator = new Translator(authToken); var result = translator.Translate(toTranslate.Text, lang, languagePicker.SelectedItem.ToString()); translated.Text = result; App.Database.SaveItem(new Models.Translation { FromLang = languagePicker.SelectedItem.ToString(), ToLang = lang, FromText = toTranslate.Text, ToText = result }); }
public void Issue_2() { string text = "Výsledky kola švýcarské hokejové ligy"; LanguageDetector detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddAllLanguages(); Assert.AreEqual("slk", detector.Detect(text)); Assert.AreEqual(1, detector.DetectAll(text).Count()); detector = new LanguageDetector(); detector.RandomSeed = 1; detector.ConvergenceThreshold = 0.9; detector.MaxIterations = 50; detector.AddAllLanguages(); Assert.AreEqual("slk", detector.Detect(text)); Assert.AreEqual(2, detector.DetectAll(text).Count()); }
public void UpdateIndexedWords(bool detectLanguage) { var words = new List <string>(); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.Comment.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.Committer.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.CommitterDisplayName.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.Owner.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).AddRange(_whitespaceRegex.Replace(this.OwnerDisplayName.ToLowerInvariant(), " ").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); ((List <string>)words).Add(this.ChangeSetId.ToString()); words = words.Distinct().ToList(); if (detectLanguage) { StopWords.FilterStopWords(words, LanguageDetector.Detect(Comment) ?? "en"); } _indexedWords = string.Join(" ", words); foreach (WorkItem workItem in this.CachedWorkItems) { _indexedWords += workItem.IndexedWords; } }
public string EnglishOnlyDetect() => EnglishDetector.Detect("Schneller brauner Fuchs springt über den faulen Hund");
private void Test(string lang, string[] texts, string[][] pairs = null) { LanguageDetector detector; detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddAllLanguages(); foreach (string text in texts) Assert.AreEqual(lang, detector.Detect(text)); if (pairs != null) { foreach (string[] pair in pairs) { detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddLanguages(pair); detector.AddLanguages(lang); foreach (string text in texts) Assert.AreEqual(lang, detector.Detect(text)); } } }
public string AllDetect() => AllDetector.Detect("Schneller brauner Fuchs springt über den faulen Hund");
public static async Task <List <Words> > Search(string searchTerm) { LanguageDetector detector = new LanguageDetector(); detector.AddAllLanguages(); HttpClient client = new HttpClient(); var loginPage = await client.GetStringAsync("https://www.altmetric.com/explorer/login"); Match matchObject = Regex.Match(loginPage, @"name=""authenticity_token"" value=""(?<key>.+)"""); string token = string.Empty; if (matchObject.Success) { token = matchObject.Groups["key"].Value; } Dictionary <string, string> formFields = new Dictionary <string, string>() { { "email", "*****@*****.**" }, { "password", "bigdatachallenge" }, { "authenticity_token", token }, { "commit", "Sign in" } }; FormUrlEncodedContent content = new FormUrlEncodedContent(formFields); var response = await client.PostAsync("https://www.altmetric.com/explorer/login", content); var searchResults = await client.GetStringAsync("https://www.altmetric.com/explorer/json_data/research_outputs?q=" + searchTerm + "&scope=all"); Console.WriteLine("A"); var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; dynamic papersDict = serializer.DeserializeObject(searchResults); List <Words> newsList = new List <Words>(); List <Task <string> > taskList = new List <Task <string> >(); List <int> scoreList = new List <int>(); if (papersDict["outputs"].Length == 0) { return(newsList); } Console.WriteLine("B"); for (int i = 0; i < Math.Min(10, papersDict["outputs"].Length); i++) { string altId = papersDict["outputs"][i]["id"].ToString(); int score = papersDict["outputs"][i]["score"]; scoreList.Add(score); taskList.Add(client.GetStringAsync("https://api.altmetric.com/v1/fetch/id/" + altId + "?key=ef2e9b9961415ba4b6510ec82c3e9cba")); } int counter = 0; while (taskList.Count > 0) { Console.WriteLine(counter); Task <string> firstFinishedTask = await Task.WhenAny(taskList); taskList.Remove(firstFinishedTask); string detailsText = await firstFinishedTask; dynamic details = serializer.DeserializeObject(detailsText); if (details["posts"].ContainsKey("news") && details["posts"]["news"].Length > 0) { for (int j = 0; j < Math.Min(3, details["posts"]["news"].Length); j++) { if (details["posts"]["news"][j].ContainsKey("title") && details["posts"]["news"][j].ContainsKey("url")) { string title = details["posts"]["news"][j]["title"]; if (detector.Detect(title) == "en" && details["posts"]["news"][j]["url"] != null) { var request = new HttpRequestMessage(HttpMethod.Head, details["posts"]["news"][j]["url"]); try { var validityResponse = await client.SendAsync(request); if (validityResponse.IsSuccessStatusCode) { Words newsArticle = new Words(title, details["posts"]["news"][j]["url"], scoreList[counter], WordType.Article); newsList.Add(newsArticle); } } catch (HttpRequestException e) { } } } } } if (details["posts"].ContainsKey("blogs") && details["posts"]["blogs"].Length > 0) { string title = details["posts"]["blogs"][0]["title"]; if (detector.Detect(title) == "en" && details["posts"]["blogs"][0]["url"] != null) { var request = new HttpRequestMessage(HttpMethod.Head, details["posts"]["blogs"][0]["url"]); try { var validityResponse = await client.SendAsync(request); if (validityResponse.IsSuccessStatusCode) { Words blogPost = new Words(title, details["posts"]["blogs"][0]["url"], scoreList[counter], WordType.Blog); newsList.Add(blogPost); } } catch (HttpRequestException e) { } } } if (details["posts"].ContainsKey("video") && details["posts"]["video"].Length > 0) { string title = details["posts"]["video"][0]["title"]; if (detector.Detect(title) == "en" && details["posts"]["video"][0]["url"] != null) { var request = new HttpRequestMessage(HttpMethod.Head, details["posts"]["video"][0]["url"]); try { var validityResponse = await client.SendAsync(request); if (validityResponse.IsSuccessStatusCode) { Words video = new Words(title, details["posts"]["video"][0]["url"], scoreList[counter], WordType.Video); newsList.Add(video); } } catch (HttpRequestException e) { } } } counter++; } client.Dispose(); return(newsList); }
public static string Detect(string[] lines) { LanguageDetector languageDetector = new LanguageDetector(); return(languageDetector.Detect(string.Join(string.Empty, lines))); }
public static void ProcessParameters(this SerializedNotification.Parameter o, GridClient Client, Configuration corradeConfiguration, string type, List <object> args, Dictionary <string, string> store, object sync, LanguageDetector languageDetector, BayesSimpleTextClassifier bayesSimpleClassifier) { object value; switch (o.Value != null) { case false: var arg = o.Type != null ? args.AsParallel() .FirstOrDefault( a => string.Equals(a.GetType().FullName, o.Type) || a.GetType() .GetBaseTypes() .AsParallel() .Any(t => string.Equals(t.FullName, o.Type))) : args.AsParallel() .FirstOrDefault( a => string.Equals(a.GetType().FullName, type) || a.GetType() .GetBaseTypes() .AsParallel() .Any(t => string.Equals(t.FullName, o.Type))); if (arg == null) { return; } // Process all conditions and return if they all fail. if (o.Condition != null) { if ( o.Condition.AsParallel() .Select(condition => new { condition, conditional = arg.GetFP(condition.Path) }) .Where(t => t.conditional != null && !t.conditional.Equals(t.condition.Value)) .Select(t => t.condition).Any()) { return; } } value = arg.GetFP(o.Path); if (o.Processing != null) { foreach (var process in o.Processing) { if (process.ToLower != null) { value = process.ToLower.Culture != null ? value.ToString().ToLower() : value.ToString().ToLowerInvariant(); continue; } if (process.GetValue != null) { IDictionary iDict = null; var dict = arg.GetFP(process.GetValue.Path); var internalDictionaryInfo = dict.GetType() .GetField("Dictionary", BindingFlags.Default | BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic); if (dict is IDictionary) { iDict = dict as IDictionary; goto PROCESS; } if (internalDictionaryInfo != null) { iDict = internalDictionaryInfo.GetValue(dict) as IDictionary; } PROCESS: if (iDict != null) { var look = arg.GetFP(process.GetValue.Value); if (!iDict.Contains(look)) { continue; } value = process.GetValue.Get != null ? iDict[look].GetFP(process.GetValue.Get) : iDict[look]; } continue; } if (process.ConditionalSubstitution != null) { dynamic l = null; dynamic r = null; if (process.ConditionalSubstitution.Type != null) { arg = args.AsParallel() .FirstOrDefault( a => string.Equals(a.GetType().FullName, process.ConditionalSubstitution.Type)); if (arg != null) { l = arg.GetFP(process.ConditionalSubstitution.Path); r = process.ConditionalSubstitution.Check; } } if (l == null || r == null) { continue; } if (l == r) { value = process.ConditionalSubstitution.Value; break; } continue; } if (process.TernarySubstitution != null) { dynamic l = null; dynamic r = null; if (process.TernarySubstitution.Type != null) { arg = args.AsParallel() .FirstOrDefault( a => string.Equals(a.GetType().FullName, process.TernarySubstitution.Type)); if (arg != null) { l = arg.GetFP(process.TernarySubstitution.Path); r = process.TernarySubstitution.Value; } } if (l == null || r == null) { continue; } value = l == r ? process.TernarySubstitution.Left : process.TernarySubstitution.Right; continue; } if (process.Resolve != null) { switch (process.Resolve.ResolveType) { case SerializedNotification.ResolveType.AGENT: switch (process.Resolve.ResolveDestination) { case SerializedNotification.ResolveDestination.UUID: var fullName = new List <string>(wasOpenMetaverse.Helpers.GetAvatarNames(value as string)); var agentUUID = UUID.Zero; if (!fullName.Any() || !Resolvers.AgentNameToUUID(Client, fullName.First(), fullName.Last(), corradeConfiguration.ServicesTimeout, corradeConfiguration.DataTimeout, new DecayingAlarm(corradeConfiguration.DataDecayType), ref agentUUID)) { break; } value = agentUUID; break; } break; } continue; } if (process.ToEnumMemberName != null && process.ToEnumMemberName.Type != null && process.ToEnumMemberName.Assembly != null) { value = Enum.GetName( Assembly.Load(process.ToEnumMemberName.Assembly) .GetType(process.ToEnumMemberName.Type), value); continue; } if (process.NameSplit != null) { if (process.NameSplit.Condition != null) { var nameSplitCondition = arg.GetFP(process.NameSplit.Condition.Path); if (!nameSplitCondition.Equals(process.NameSplit.Condition.Value)) { continue; } } var fullName = new List <string>(wasOpenMetaverse.Helpers.GetAvatarNames(value as string)); if (fullName.Any()) { lock (sync) { store.Add(process.NameSplit.First, fullName.First()); store.Add(process.NameSplit.Last, fullName.Last()); } } return; } if (process.IdentifyLanguage != null) { var detectedLanguage = languageDetector.Detect(value as string); if (detectedLanguage != null) { lock (sync) { store.Add(process.IdentifyLanguage.Name, detectedLanguage); } } continue; } if (process.BayesClassify != null) { var bayesClassification = bayesSimpleClassifier.Classify(value as string).FirstOrDefault(); if (!bayesClassification.Equals(default(KeyValuePair <string, double>))) { lock (sync) { store.Add(process.BayesClassify.Name, CSV.FromKeyValue(bayesClassification)); } } continue; } if (process.Method != null) { Type methodType; switch (process.Method.Assembly != null) { case true: methodType = Assembly.Load(process.Method.Assembly).GetType(process.Method.Type); break; default: methodType = Type.GetType(process.Method.Type); break; } object instance; try { instance = Activator.CreateInstance(methodType); } catch (Exception) { instance = null; } switch (process.Method.Parameters != null) { case true: value = methodType.GetMethod(process.Method.Name, process.Method.Parameters.Values.Select(Type.GetType).ToArray()) .Invoke(instance, process.Method.Parameters.Keys.Select(arg.GetFP).ToArray()); break; default: value = methodType.GetMethod(process.Method.Name) .Invoke( Activator.CreateInstance(methodType).GetFP(process.Method.Path), null); break; } break; } } } break; default: if (!args.AsParallel().Any(a => string.Equals(a.GetType().FullName, type))) { return; } value = o.Value; break; } var data = new HashSet <string>(wasOpenMetaverse.Reflection.wasSerializeObject(value)); if (!data.Any()) { return; } var output = CSV.FromEnumerable(data); if (data.Count.Equals(1)) { output = data.First().Trim('"'); } lock (sync) { store.Add(o.Name, output); } }
private static void mergeMovies() { string statusText = "All Done"; try { using (FolderBrowserDialog Folder_Browser_Dialog = main.get_folderbrowserdialog()) { if (Folder_Browser_Dialog == null) { return; } List <string> Merging_Movies = new List <string>(); List <string> commands = new List <string>(); List <string> commands_report = new List <string>(); if (new choice_box().ShowDialog() == DialogResult.OK) { main.change_button_text("Stop Merging", main.get_control_by_name("Merge_Button"), msgType.error); if (choice.series) { //needs more tinkering foreach (FileInfo fInfo in new DirectoryInfo(Folder_Browser_Dialog.SelectedPath).GetFiles("*.*", SearchOption.AllDirectories).Where(f => extension.videoEXT.Contains(f.Extension.ToLower())).ToArray()) { commands.Add(@"""" + Application.StartupPath + @"\MKVToolNix\/k mkvmerge.exe --ui-language en --output ^""" + Properties.Settings.Default.merge_destination + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + @".mkv^"" --language 0:und --language 1:und ^""^(^"" ^""" + fInfo.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + "" + fInfo.Extension + @"^"" ^""^)^"" --language 0:en --track-name ^""0:English Subtitle ^"" --default-track 0:yes --forced-track 0:yes ^""^(^"" ^""" + fInfo.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + @".srt ^"" ^""^)^"" --track-order 0:0,0:1,1:0"); if (new DirectoryInfo(Folder_Browser_Dialog.SelectedPath).GetFiles(Path.GetFileNameWithoutExtension(fInfo.Name) + ".*", SearchOption.AllDirectories).Where(f => extension.subtitleEXT.Contains(f.Extension.ToLower())).ToArray().Count() > 0) { commands_report.Add("Done."); } else { commands_report.Add("Subtitle File Not Found."); } Merging_Movies.Add(Path.GetFileNameWithoutExtension(fInfo.Name)); main.log(@"""" + Application.StartupPath + @"\MKVToolNix\/k mkvmerge.exe --ui-language en --output ^""" + Properties.Settings.Default.merge_destination + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + @".mkv^"" --language 0:und --language 1:und ^""^(^"" ^""" + fInfo.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + "" + fInfo.Extension + @"^"" ^""^)^"" --language 0:en --track-name ^""0:English Subtitle ^"" --default-track 0:yes --forced-track 0:yes ^""^(^"" ^""" + fInfo.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(fInfo.Name) + @".srt ^"" ^""^)^"" --track-order 0:0,0:1,1:0", msgType.message); } } else { List <DirectoryInfo> allDirectory = new List <DirectoryInfo>() { new DirectoryInfo(Folder_Browser_Dialog.SelectedPath) }; if (choice.container) { allDirectory = new DirectoryInfo(Folder_Browser_Dialog.SelectedPath).GetDirectories().ToList(); } foreach (DirectoryInfo dInfo in allDirectory) { FileInfo[] allFileInfo = new DirectoryInfo(dInfo.FullName).GetFiles("*.*", SearchOption.AllDirectories); FileInfo[] vidInfo = allFileInfo.Where(f => extension.videoEXT.Contains(f.Extension.ToLower())).ToArray(); FileInfo[] srtInfo = allFileInfo.Where(f => extension.subtitleEXT.Contains(f.Extension.ToLower())).ToArray(); string vidName = Path.GetFileNameWithoutExtension(vidInfo[0].Name); string commandStr = @"""" + Application.StartupPath + @"\MKVToolNix\/c mkvmerge.exe --ui-language en --output ^""" + Properties.Settings.Default.merge_destination + @"\" + Path.GetFileNameWithoutExtension(dInfo.Name) + @".mkv^"" --language 0:und --language 1:und ^""^(^"" ^""" + dInfo.FullName + @"\" + vidName + vidInfo[0].Extension + @"^"" ^""^)^"" "; string trackOrder = "--track-order 0:0,0:1,"; foreach (FileInfo srt in srtInfo) { string dLanguage = string.Empty; using (StreamReader sReader = new StreamReader(srt.FullName)) { LanguageDetector detector = new LanguageDetector(); detector.AddAllLanguages(); dLanguage = detector.Detect(sReader.ReadToEnd()); } int objIndex = Array.IndexOf(srtInfo, srt); commandStr += @"--language " + objIndex + @":" + dLanguage + @" "; if (dLanguage == "en") { commandStr += @"--default-track " + objIndex + @":yes --forced-track " + objIndex + @":yes "; } commandStr += @"^""^(^"" ^""" + dInfo.FullName + @"\" + Path.GetFileNameWithoutExtension(srt.Name) + srt.Extension + @" ^"" ^""^)^"" "; trackOrder += (objIndex + 1) + ":0,"; } commandStr += trackOrder.Substring(0, trackOrder.LastIndexOf(",")); if (srtInfo.Length > 0) { commands_report.Add("Done."); } else { commands_report.Add("Muxed without subtitle."); } commands.Add(commandStr); Merging_Movies.Add(Path.GetFileNameWithoutExtension(dInfo.Name) + ".mkv"); } } main.max_progressbar(commands.Count * 100, main.ProgressBar); main.max_progressbar(100, main.Mini_ProgressBar); mergeInProgress = true; foreach (string merge_command in commands) { main.log("Multiplexing Movie --> " + Merging_Movies[commands.IndexOf(merge_command)] + "... ", msgType.message); main.change_status("Merging " + (currentIndex + 1) + " of " + commands.Count, msgType.message); Process p = Process.Start(new ProcessStartInfo() { FileName = "cmd.exe", Arguments = merge_command, RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }); p.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived); p.BeginOutputReadLine(); do { try { if (cancellationPending) { p.CancelOutputRead(); foreach (Process mkvmerge in Process.GetProcessesByName("mkvmerge")) { mkvmerge.Kill(); } p.Kill(); p.Close(); statusText = "Canceled by user."; main.log("Canceled", msgType.error, true); goto Finish; } } catch (Exception) { } } while (!p.HasExited); p.WaitForExit(); currentIndex += 1; if (commands_report[commands.IndexOf(merge_command)] == "Done.") { main.log(commands_report[commands.IndexOf(merge_command)], msgType.success, true); } else { main.log(commands_report[commands.IndexOf(merge_command)], msgType.error, true); } } } } Finish :; } catch (Exception ex) { main.log(ex.ToString(), msgType.error); statusText = "Error"; } finally { main.update_progressbar(0, main.ProgressBar); main.update_progressbar(0, main.Mini_ProgressBar); if (statusText == "Error") { main.change_status(statusText, msgType.error); } else { main.change_status(statusText, msgType.success); } mergeInProgress = false; main.change_button_text("Merge Movies", main.get_control_by_name("Merge_Button"), msgType.baseColor); } }
public Tweet GetTweetFromStatus(TwitterStatus status) { Tweet t = new Tweet(); if (status.Place != null) { t.placeName = status.Place.Name; t.placeFullName = status.Place.FullName; t.placeType = status.Place.PlaceType; } t.createdAt = status.CreatedDate; t.tweetId = status.Id; t.inReplyToScreenName = status.InReplyToScreenName; t.inReplyToStatusId = status.InReplyToStatusId; t.inReplyToUserId = status.InReplyToUserId; if (status.RetweetedStatus != null && ((status.Text != null && status.Text.StartsWith("RT")) || (status.FullText != null && status.FullText.StartsWith("RT")))) { if (!string.IsNullOrWhiteSpace(status.RetweetedStatus.FullText)) { Console.WriteLine("Full text stored: " + status.RetweetedStatus.FullText); } string tmpString = RemoveTwitterTags(string.IsNullOrWhiteSpace(status.RetweetedStatus.FullText) ? status.Text : status.RetweetedStatus.FullText); if (!string.IsNullOrWhiteSpace(tmpString)) { t.language = detector.Detect(tmpString); } else { t.language = "en"; } t.message = string.IsNullOrWhiteSpace(status.RetweetedStatus.FullText) ? "RT " + status.RetweetedStatus.Text : "RT " + status.RetweetedStatus.FullText; t.retweetedId = status.RetweetedStatus.Id; if (status.User != null) { t.userId = status.User.Id; t.userName = status.User.Name; t.userScreenName = status.User.ScreenName; } else { return(null); } } else { if (!string.IsNullOrWhiteSpace(status.FullText)) { Console.WriteLine("Full text stored: " + status.FullText); } string tmpString = RemoveTwitterTags(string.IsNullOrWhiteSpace(status.FullText) ? status.Text : status.FullText); if (!string.IsNullOrWhiteSpace(tmpString)) { t.language = detector.Detect(tmpString); } else { t.language = "en"; } t.message = string.IsNullOrWhiteSpace(status.FullText) ? status.Text : status.FullText; t.retweetedId = null; if (status.User != null) { t.userId = status.User.Id; t.userName = status.User.Name; t.userScreenName = status.User.ScreenName; } else { return(null); } } return(t); }
public string GetLanguage(string word) { detectedWord = detector.Detect(word); if (detectedWord == "en") { return("english"); } if (detectedWord == "ru") { return("russian"); } if (detectedWord == "fr") { return("french"); } if (detectedWord == "pt") { return("portuguese"); } if (detectedWord == "es") { return("spanish"); } if (detectedWord == "af") { return("afrikaans"); } if (detectedWord == "ar") { return("arabic"); } if (detectedWord == "bg") { return("bulgarian"); } if (detectedWord == "bn") { return("bengali"); } if (detectedWord == "cs") { return("czech"); } if (detectedWord == "da") { return("danish"); } if (detectedWord == "de") { return("german"); } if (detectedWord == "el") { return("modern greek"); } if (detectedWord == "et") { return("estonian"); } if (detectedWord == "fa") { return("persian"); } if (detectedWord == "fi") { return("finnish"); } if (detectedWord == "gu") { return("gujarati"); } if (detectedWord == "he") { return("hebrew"); } if (detectedWord == "hi") { return("hindi"); } if (detectedWord == "hr") { return("croatian"); } if (detectedWord == "hu") { return("hungarian"); } if (detectedWord == "id") { return("indonesian"); } if (detectedWord == "it") { return("italian"); } if (detectedWord == "ja") { return("japanese"); } if (detectedWord == "kn") { return("kannada"); } if (detectedWord == "ko") { return("korean"); } if (detectedWord == "lt") { return("lithuanian"); } if (detectedWord == "lv") { return("latvian"); } if (detectedWord == "mk") { return("macedonian"); } if (detectedWord == "mr") { return("marathi"); } if (detectedWord == "ne") { return("nepali"); } if (detectedWord == "nl") { return("dutch"); } if (detectedWord == "no") { return("norwegian"); } if (detectedWord == "pa") { return("punjabi"); } if (detectedWord == "pl") { return("polish"); } if (detectedWord == "ro") { return("romanian"); } if (detectedWord == "sk") { return("slovak"); } if (detectedWord == "sl") { return("slovene"); } if (detectedWord == "so") { return("somali"); } if (detectedWord == "sq") { return("albanian"); } if (detectedWord == "sv") { return("swedish"); } if (detectedWord == "sw") { return("swahili"); } if (detectedWord == "ta") { return("tamil"); } if (detectedWord == "te") { return("telugu"); } if (detectedWord == "th") { return("thai"); } if (detectedWord == "tl") { return("tagalog"); } if (detectedWord == "tr") { return("turkish"); } if (detectedWord == "uk") { return("ukrainian"); } if (detectedWord == "ur") { return("urdu"); } if (detectedWord == "vi") { return("vietnamese"); } if (detectedWord == "zh-cn") { return("simplified chinise"); } if (detectedWord == "zh-tw") { return("taiwanese chinise"); } else { throw new Exception("Oops, looks like you use language which out of list pf supported ones."); } }
public void Issue_2() { string text = "Výsledky kola švýcarské hokejové ligy"; LanguageDetector detector = new LanguageDetector(); detector.RandomSeed = 1; detector.AddAllLanguages(); Assert.AreEqual("sk", detector.Detect(text)); Assert.AreEqual(1, detector.DetectAll(text).Count()); detector = new LanguageDetector(); detector.RandomSeed = 1; detector.ConvergenceThreshold = 0.9; detector.MaxIterations = 50; detector.AddAllLanguages(); Assert.AreEqual("sk", detector.Detect(text)); Assert.AreEqual(2, detector.DetectAll(text).Count()); }