static void Main(string[] args) { var stopwatch = new Stopwatch(); stopwatch.Start(); List <string> wordstream = new List <string>(); wordstream.AddRange(WordTools.SampleWordStream); for (int i = 0; i < 1000000 - wordstream.Count; i++) { wordstream.Add(WordTools.GetRandomWord()); } IEnumerable <string> ranking = _wordFinder.Find(wordstream); stopwatch.Stop(); var elapsedTicks = stopwatch.ElapsedTicks; var elapsedMilliseconds = stopwatch.ElapsedMilliseconds; System.Console.WriteLine(); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine("SEEDED WORDS:"); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine(); foreach (string word in WordTools.SampleWordStream) { System.Console.WriteLine(word); } System.Console.WriteLine(); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine("MATRIX:"); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine(); MatrixTools.PrintMatrix(MatrixTools.GetIEnumerableMatrix(_matrixSize, _matrix)); System.Console.WriteLine(); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine("RANKING:"); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine(); foreach (string word in ranking) { System.Console.WriteLine(word); } System.Console.WriteLine(); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine("STATS:"); System.Console.WriteLine("----------------------------------------------------"); System.Console.WriteLine(); System.Console.WriteLine($"Elapsed Milliseconds: {elapsedMilliseconds}"); System.Console.WriteLine($"Elapsed Ticks: {elapsedTicks}"); System.Console.WriteLine(); }
private string CaseSwitch() { StringBuilder str = new StringBuilder(txtEnter.Text); WordTools.ConvertOpposite(str); return(txtCaseSwitch.Text = str.ToString()); }
public override void Use(CommandArgs command) { var messages = StatsDatabase.GetMessages(); var usage = messages.SelectMany(m => WordTools.GetWords(m.Message)).GroupBy(w => w).ToDictionary(g => g.Key, g => g.Count()); StatsDatabase.IncrementWords(usage); command.Reply("done."); }
public override void HandleMessage(MessageEvent ev) { if (!Client.IncludeChannel(ev.Message.Channel)) { Logger.Log(null, "Dropping message because its channel should be excluded."); return; } var message = ev.Message; // Can't save statistics if we don't have a DB connection! if (StatsDatabase.ConnectionState == ConnectionState.Closed) { return; } // Add the message to the chat log StatsDatabase.AddMessage(message); var userId = message.Sender.DbUser.Id; // Increment actions/lines for the user if (message.Action) { StatsDatabase.IncrementActions(userId); } else { StatsDatabase.IncrementLineCount(userId); } // Increment words for the user var words = WordTools.GetWords(message.Body); StatsDatabase.IncrementWordCount(userId, words.Count); // Increment global line/word count StatsDatabase.IncrementVar("global_line_count"); StatsDatabase.IncrementVar("global_word_count", words.Count); // Update emoticon usage foreach (var word in words.Where(word => Emoticons.List.Contains(word))) { StatsDatabase.IncrementEmoticon(word, userId); } // Process individual words foreach (var word in words) { ProcessWord(message, word, userId); } // Quote grabbing GenerateRandomQuote(ev, words); ProcessRandomEvents(ev); }
public void 한단어_줄바꿈하기_2() { string inputText = "helloworld"; string expectedText = "helloworld"; string actualText = ""; WordTools wordTools = new WordTools(); actualText = wordTools.wrap(inputText, 7); Assert.AreEqual(expectedText, actualText); }
private string PigLatin() { string str = WordTools.PigLatinConverter(txtEnter.Text); if (str == "-1") { return(txtPigLatin.Text = "Error no vowels"); } else { return(txtPigLatin.Text = str.ToString()); } }
public void HandleInputChinese() { //处理从IME得到的字符 List <Character> getChars = Platform.Current.GetChars(); // WindowInputCapturer.myCharacters; foreach (var getChar in getChars) { if (getChar.IsUsed == false) { if (getChar.CharaterType == characterType.Char) { //sfx.AddText(getChar.Chars.ToString()); if (CanAdd) { Text += getChar.Chars.ToString(); } Platform.Current.PlayEffect(@"Content\Sound\Move"); } //回车等功能键触发事件也可以由KeyboardState来截取处理 else if (getChar.CharaterType == characterType.Enter) { //Text += "\r"; if (OnKeyEnterPress != null) { OnKeyEnterPress.Invoke(null, null); } Platform.Current.ClearChars(); //WindowInputCapturer.myCharacters.Clear(); break; } else if (getChar.CharaterType == characterType.Tab) { //Text += " "; if (OnKeyTabPress != null) { OnKeyTabPress.Invoke(null, null); } Platform.Current.ClearChars(); //WindowInputCapturer.myCharacters.Clear(); break; } else if (getChar.CharaterType == characterType.BackSpace) { Text = WordTools.BackSpaceString(Text); } getChar.IsUsed = true; } } if (getChars != null && getChars.Count > 0) { } }
static void Main() { const string s1 = "Bill Gates is the richest man on Earth"; const string s2 = "Srinivasa Ramanujan was a brilliant mathematician"; // In the Main() method, the rev1/rev2 string variables will // call the WordTools class and its .ReverseWords() method // and applied to both s1 and s2 strings that were declared // and assigned the beginning of the method. 'rev1' and 'rev2' // are introduced as new variables because the original s1 // and s2 were declared as constant strings. string rev1 = WordTools.ReverseWords(s1); Console.WriteLine(rev1); string rev2 = WordTools.ReverseWords(s2); Console.WriteLine(rev2); }
public void Find_Should_Return_Results_In_Less_Than_One_Second_For_One_Million_Words() { List <string> wordstream = new List <string>(); wordstream.AddRange(WordTools.SampleWordStream); for (int i = 0; i < 1000000 - wordstream.Count; i++) { wordstream.Add(WordTools.GetRandomWord()); } var stopWatch = new Stopwatch(); stopWatch.Start(); IEnumerable <string> results = _wordFinder.Find(wordstream); stopWatch.Stop(); Assert.True(stopWatch.ElapsedMilliseconds < 1000); }
private void ProcessWord(ChatMessage message, string word, int sender) { // In order to count word occurrence correctly, all words are transformed to // lowercase, and all non-latin characters are removed. This is done because // people commonly say "its" when they mean "it's", and it is very difficult // to determine which one they meant, so instead, they are considered equal. var lword = word.ToLower(); var cword = textOnly.Replace(lword, string.Empty); if (word.StartsWith("http://") || word.StartsWith("https://")) { StatsDatabase.IncrementUrl(word, sender, message.Body); } else { StatsDatabase.IncrementWord(cword); } if (WordTools.IsProfanity(lword)) { StatsDatabase.IncrementProfanities(sender); } }
public void WordWrapper_인스턴스만들기() { WordTools wordTools = new WordTools(); }
private IEnumerable <PartsSelectionTreeElement> CreatePartsSelectionTreeElements(OpenXmlElement element, int id, Predicate <OpenXmlElement> supportedType, int indent) { List <PartsSelectionTreeElement> result = new List <PartsSelectionTreeElement>(); if (supportedType(element)) { PartsSelectionTreeElement elementToAdd; if (element is Paragraph) { Paragraph paragraph = element as Paragraph; NumberingProperties numberingProperties = null; if (paragraph.ParagraphProperties != null) { numberingProperties = paragraph.ParagraphProperties.NumberingProperties; } string elementId = paragraph.ParagraphId ?? WordDocumentPartAttributes.GetParagraphNoIdFormatter(_paragraphCounter); if (numberingProperties != null) { indent += numberingProperties.NumberingLevelReference.Val.Value; if (WordDocumentPartAttributes.BulletListIds.Any(b => b == numberingProperties.NumberingId.Val.Value)) { elementToAdd = new PartsSelectionTreeElement(id.ToString(), elementId, WordTools.GetElementName(element, WordDocumentPartAttributes.MaxNameLength), indent, Helpers.ElementType.BulletList); } else if (WordDocumentPartAttributes.NumberedListIds.Any(b => b == numberingProperties.NumberingId.Val.Value)) { elementToAdd = new PartsSelectionTreeElement(id.ToString(), elementId, WordTools.GetElementName(element, WordDocumentPartAttributes.MaxNameLength), indent, Helpers.ElementType.NumberedList); } else { elementToAdd = new PartsSelectionTreeElement(id.ToString(), elementId, WordTools.GetElementName(element, WordDocumentPartAttributes.MaxNameLength), indent, Helpers.ElementType.BulletList); } } else { elementToAdd = new PartsSelectionTreeElement(id.ToString(), elementId, WordTools.GetElementName(element, WordDocumentPartAttributes.MaxNameLength), indent, Helpers.ElementType.Paragraph); } _paragraphCounter++; } else if (element is Picture || element is Drawing) { elementToAdd = new PartsSelectionTreeElement(id.ToString(), element.LocalName, indent, Helpers.ElementType.Picture); } else if (element is Table) { elementToAdd = new PartsSelectionTreeElement(id.ToString(), (element as Table).LocalName, indent, Helpers.ElementType.Table); } else { elementToAdd = new PartsSelectionTreeElement(id.ToString(), WordTools.GetElementName(element, WordDocumentPartAttributes.MaxNameLength), indent); } result.Add(elementToAdd); if (element.HasChildren) { foreach (var elmentChild in element.ChildElements) { _index++; CreatePartsSelectionTreeElements(elmentChild, _index, supportedType, ++indent); } } } return(result); }
private string DollarSign() { string str = WordTools.DollarSignConverter(txtEnter.Text); return(txtDollarSigns.Text = str.ToString()); }
private string Reverse() { string str = txtEnter.Text; return(txtReverse.Text = WordTools.ReverseWords(str.ToString())); }