static void Main(string[] args) { _String str = new _String(new char[] { 'c', 'a', 't' }); Console.WriteLine("Create string:"); printStr(str.Chars); Console.WriteLine("\nUsing text"); _String s = new _String(new char[] { 'd', 'o', 'g' }); _String s2 = new _String(new char[] { 'c', 'o', 'w' }); Text text = new Text(s.Chars); text.Add(str); text.Add(s); text.Add(s2); //Console.WriteLine("Before:"+str.Chars.Length); // text.DeleteFirstAndLastSpace(str); //Console.WriteLine("After:"+str.Chars.Length); //text.DeleteByIndex(2,false); Console.WriteLine(text.ToString()); //str.CalcConsonants(new char[] { 'h', 'e', 'l', 'l', 'o' }); // Console.WriteLine(text.ToString()); // text.FindMinLenOfStr(); // text.DeleteFirstAndLastSpace(str); // printStr(str.Chars); Console.WriteLine("\nPercentage of consonants:" + text.FindPercentageOfConsonants() + "%"); //text.deleteExtraSpaces(str); // printStr(str.Chars); Console.ReadKey(); }
public void Separate(char currentSymbol) { if (PunctuationInSetnenceSetted == false && PunctuationSentenceFinisherSetted == false) { SetWord(); InSentenseSeparator separator = new InSentenseSeparator(currentSymbol); SentenceBuffer.Add(separator); } if (PunctuationInSetnenceSetted == true) { PunctuationMark punctuationMark = new PunctuationMark(CharBuffer); CharBuffer.Clear(); InSentenseSeparator separator = new InSentenseSeparator(currentSymbol); SentenceBuffer.Add(separator); } if (PunctuationSentenceFinisherSetted == true) { PunctuationMark punctuationMark = new PunctuationMark(CharBuffer); CharBuffer.Clear(); PunctuationSentenceFinisherSetted = false; Sentence sentence = new Sentence(SentenceBuffer); ResultTextModel.Add(sentence); SentenceBuffer.Clear(); SentenseSeparator separator = new SentenseSeparator(currentSymbol); ResultTextModel.Add(sentence); } }
public static Text Init( this Text text, Transform parent, string content = "", Vector2 size = default(Vector2), int font_size = 50, string font = "Arial", Color?color = null, TextAnchor alignment = TextAnchor.MiddleCenter, JLib.TextFitMode?fit = null) { text.transform.SetParent(parent, false); text.text = content; text.GetComponent <RectTransform>().sizeDelta = size; text.fontSize = font_size; //text.font = Font(font); text.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); text.alignment = alignment; if (color.HasValue) { text.color = color.Value; } else { text.color = Color.black; } if (fit.HasValue) { var fitter = text.gameObject.AddComponent <ContentSizeFitter>(); if (fit.Value == JLib.TextFitMode.ShrinkX || fit.Value == JLib.TextFitMode.StretchX) { fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; if (fit.Value == JLib.TextFitMode.ShrinkX) { text.Add <RectShrinker>().Init(size.x, JLib.Axes(true, false, false)); } } else if (fit.Value == JLib.TextFitMode.ShrinkY || fit.Value == JLib.TextFitMode.StretchY) { fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; if (fit.Value == JLib.TextFitMode.ShrinkY) { text.Add <RectShrinker>().Init(size.x, JLib.Axes(true, false, false)); } } } else { UnityEngine.Object.Destroy(text.Get <ContentSizeFitter>()); UnityEngine.Object.Destroy(text.Get <RectShrinker>()); } return(text); }
public void AddTextLineTwiceAppendsFirstContent() { var testtext = "wibble"; var text = new Text("dontcare"); var line = new TextLine(testtext); text.Add(line); text.Add(line); var content = Assert.Single(text.Content); Assert.Equal(testtext + testtext, content); }
static void Main(string[] args) { Text one = new Text(2); one.Add(0, 0, '1'); one.Add(0, 1, 'a'); one.Add(1, 0, '2'); one.Add(1, 1, 'b'); Console.WriteLine(one.VowelCount); Console.WriteLine(one[0]); Console.WriteLine(one[1]); }
public void AddVariationAddsSecondOption() { var testtext = "wibble"; var text = new Text("dontcare"); var line = new TextLine(testtext); text.Add(line); text.Add(new Variation()); text.Add(line); text.Add(line); Assert.Equal(2, text.Content.Count); Assert.Equal(testtext, text.Content.First()); Assert.Equal(testtext + testtext, text.Content.Skip(1).First()); }
/// <summary> /// Reads the text and stores it in lists of lines /// </summary> /// <param name="name">File to load</param> protected override void ReadText(string name) { Data = new Parser.BBSCodeResult(); List <string> txt; if (TextHelper.IsUrl(name)) { WebClient webClient = new WebClient(); txt = TextHelper.SplitString(webClient.DownloadString(name)); } else { txt = File.ReadAllLines(GetFile(name)).ToList(); } foreach (string s in txt) { if (s.Length <= client.screenWidth) { Text.Add(s); } else { Text.AddRange(TextHelper.WordWrap(s, client.screenWidth)); } } Footer.Add(string.Empty); }
public void Update() { Color32 col = new Color32(0, 255, 0, 255); Hierarchy.Push(Matrix.T(-0.06f, .05f, 0)); Text.Add("Y Top", Matrix.TR(new Vec3(0, .04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.TopCenter); Lines.Add(new Vec3(-0.05f, .04f, 0), new Vec3(.05f, .04f, 0), col, 0.001f); Text.Add("Y Center", Matrix.TR(new Vec3(0, .0f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.Center); Lines.Add(new Vec3(-0.05f, 0, 0), new Vec3(.05f, 0, 0), col, 0.001f); Text.Add("Y Bottom", Matrix.TR(new Vec3(0, -.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.BottomCenter); Lines.Add(new Vec3(-0.05f, -.04f, 0), new Vec3(.05f, -.04f, 0), col, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0.02f, 0.05f, 0)); Text.Add("2cm Tall", Matrix.R(Quat.LookDir(0, 0, 1)), style, TextAlign.CenterLeft); Lines.Add(new Vec3(0, -.01f, 0), new Vec3(.11f, -.01f, 0), col, 0.001f); Lines.Add(new Vec3(0, .01f, 0), new Vec3(.11f, .01f, 0), col, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0, -0.06f, 0)); Text.Add("X Left", Matrix.TR(new Vec3(0, 0.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.CenterLeft); Text.Add("X Center", Matrix.TR(new Vec3(0, 0, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.Center); Text.Add("X Right", Matrix.TR(new Vec3(0, -0.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.CenterRight); Lines.Add(new Vec3(0, .06f, 0), new Vec3(0, -.06f, 0), col, 0.001f); Hierarchy.Pop(); Tests.Screenshot("Tests/FontSizing.jpg", 600, 600, new Vec3(0, 0, .15f), Vec3.Zero); }
public static Text DeleteWordFromText(Text text, int count) { var tempText = new Text(); foreach (var sentence in text) { var newSentence = new Collection <ISentenceItem>(); foreach (var sentenceItem in sentence) { if (sentenceItem is Word) { var word = (Word)sentenceItem; if (!word.IsConsonantBegining) { newSentence.Add(word); } if (word.IsConsonantBegining) { if (word.Value.Length != count) { newSentence.Add(word); } } } else { newSentence.Add(sentenceItem); } } tempText.Add(new Sentence(newSentence)); } return(tempText); }
/// <summary> /// Fills the messages area list /// </summary> protected override void AddList() { string fmt = "{0,-20} {1,4} {2,4} {3,4} {4}"; using (bbsContext bbs = new bbsContext()) { User user = bbs.GetUserByUsername(client.username); List <MessageArea> list = bbs.GetMessageAllowedAreasByGroup( Params.Length > 1 ? Params[1] : string.Empty, client.username).ToList(); foreach (MessageArea area in list) { Text.Add(TextHelper.Truncate(string.Format(fmt, new object[] { area.Id, area.MessagesCount, area.NewMessagesCount(user.LastLoginDate), area.UnreadMessagesCount(user.Userid), area.Description }), client.screenWidth)); Data.Actions.Add(area.Id, new Parser.BBSCodeResult.Action() { module = "MessagesList", data = string.Format("@MessagesList;{0}", area.Id) }); } } KeyLength = 20; }
/// :End: public void Update() { ShowMicDeviceWindow(); Tests.Screenshot("MicrophoneSelector.jpg", 1, 400, 400, 90, micSelectPose.position + V.XYZ(-0.15f, -0.02f, 0.15f), micSelectPose.position - V.XYZ(0, 0.12f, 0)); if (Microphone.IsRecording) { // Squaring a 0-1 value gives an extra slow initial response, but // squaring the inverse of a 0-1 value and then inverting it back // gives a fast initial response! Try graphing "y = 1-(1-x)^2" // versus "y = x^2" for the x 0-1 range. float intensity = GetMicIntensity(); intensity = 1 - intensity; intensity = 1 - (intensity * intensity); float scale = 0.1f + 0.06f * intensity; Color color = new Color(1, 1, 1, Math.Max(0.1f, intensity)); Default.MeshSphere.Draw(micMaterial, Matrix.TS(0, 0, -0.5f, scale), color); micSprite.Draw(Matrix.TS(-0.03f, 0.03f, -0.5f, 0.06f)); } else { // Draw it in red if we're not recording Default.MeshSphere.Draw(micMaterial, Matrix.TS(0, 0, -0.5f, 0.1f), new Color(1, 0, 0, 0.1f)); micSprite.Draw(Matrix.TS(-0.03f, 0.03f, -0.5f, 0.06f)); } Text.Add(title, titlePose); Text.Add(description, descPose, V.XY(0.4f, 0), TextFit.Wrap, TextAlign.TopCenter, TextAlign.TopLeft); }
private void ReadText(XElement e) { var cnt = setting.AskItems.Count(vv => vv.IsAskText); if (Text == null) { Text = new List <Dictionary <string, string> >(); for (var n = 0; n < cnt; n++) { Text.Add(new Dictionary <string, string>()); } } var txsetattr = e.Attribute("set"); if (txsetattr != null) { txset = txsetattr.Value.ToInt(); } while (Text.Count <= txset) { Text.Add(new Dictionary <string, string>()); } var tx = e.Attribute("question"); if (tx != null) { Text[txset].Add(tx.Value, e.Value); } }
/// <summary> /// Fills the messages area list /// </summary> protected override void AddList() { if (Params.Length < 2) { return; // There is no area filter } string area = Params[1].Trim().ToUpper(); string filter = Params.Length > 2 ? Params[2].Trim().ToUpper() : string.Empty; string fmt = "{0,5} {1,1} {2,1} {3,-30} {4}"; using (bbsContext bbs = new bbsContext()) { User user = bbs.GetUserByUsername(client.username); List <Message> list = bbs.GetAllMessagesInArea(area).ToList(); foreach (Message m in list) { Text.Add(TextHelper.Truncate(string.Format(fmt, new object[] { m.Id, m.IsNew(user.LastLoginDate) ? "N" : "", m.IsRead(client.username) ? "" : "U", TextHelper.Truncate(m.MessageFrom, 30), m.Subject }), client.screenWidth)); Data.Actions.Add(m.Id.ToString(), new Parser.BBSCodeResult.Action() { module = "MessageScreen", data = string.Format("@MessageScreen;{0}", m.Id) }); } } KeyLength = 5; }
private void PopulateTextAnswers(OrganizationMember om, Ask ask) { FetchQuestionsAnswersList(om); if (Text == null) { Text = new List <Dictionary <string, string> >(); } var tx = new Dictionary <string, string>(); Text.Add(tx); foreach (var q in ((AskText)ask).list) { if (setting.TargetExtraValues) { var v = person.GetExtra(q.Question); if (v.HasValue()) { tx[q.Question] = v; } } else if (qlist != null) { var v = qlist.SingleOrDefault(qq => qq.Question == q.Question && qq.Type == "text"); if (v != null) { tx[q.Question] = v.Answer; } } } }
private void CreateSentences(IToken sign, IToken word) { AddWord(word); AddPuncSign(sign); _text.Add(_sentence); _sentence = new Sentence(new List <IToken>()); }
public void Update() { /// :CodeSample: Model Model.AnimCompletion Model.ActiveAnim Model.AnimTime Model.AnimMode Anim.Name /// ### Animation progress bar /// A really simple progress bar visualization for the Model's active /// animation. /// /// ![Model with progress bar]({{site.screen_url}}/AnimProgress.jpg) model.Draw(Matrix.Identity); Hierarchy.Push(Matrix.T(0.5f, 1, -.25f)); // This is a pair of green lines that show the current progress through // the animation. float progress = model.AnimCompletion; Lines.Add(V.XY0(0, 0), V.XY0(-progress, 0), new Color(0, 1, 0, 1.0f), 2 * U.cm); Lines.Add(V.XY0(-progress, 0), V.XY0(-1, 0), new Color(0, 1, 0, 0.2f), 2 * U.cm); // These are some labels for the progress bar that tell us more about // the active animation. Text.Add($"{model.ActiveAnim.Name} : {model.AnimMode}", Matrix.TS(0, -2 * U.cm, 0, 3), TextAlign.TopLeft); Text.Add($"{model.AnimTime:F1}s", Matrix.TS(-progress, 2 * U.cm, 0, 3), TextAlign.BottomCenter); Hierarchy.Pop(); /// :End: Tests.Screenshot("AnimProgress.jpg", 400, 600, V.XYZ(0, .9f, -1.2f), V.XYZ(0, .9f, 0)); }
public void Update() { Hierarchy.Push(Matrix.T(-0.3f, 0.1f, -0.7f)); logo.Draw(Matrix.TRS(V.XYZ(logoHalfWidth, 0.3f, 0), Quat.LookDir(0, 0, 1), V.XYZ(logo.Aspect, 1, 1) * 0.25f)); Text.Add(message, Matrix.TRS(V.XYZ(-logoHalfWidth, 0, 0), Quat.LookDir(0, 0, 1), 1.25f), V.XY(logoHalfWidth / 1.25f, 0), TextFit.Wrap, TextAlign.TopLeft, TextAlign.TopLeft); Hierarchy.Pop(); }
public IText ParseText(StreamReader reader) { IText text = new Text(); StringBuilder sb = new StringBuilder(); using (reader) { while (reader.Peek() >= 0) { StringBuilder line = new StringBuilder(reader.ReadLine()); if (sb.ToString() != "") { line.Insert(0, sb); sb.Clear(); } var sentences = line.ToString().Split(_sentenceSeparators.GetSeparators(), StringSplitOptions.RemoveEmptyEntries); var separators = line.ToString().Split(sentences, StringSplitOptions.RemoveEmptyEntries); if (sentences.Length > separators.Length) { sb.Append(sentences[sentences.Length - 1]); sb.Append(" "); } IEnumerable <Tuple <string, string> > tuples = sentences.Zip(separators, (sentence, separator) => new Tuple <string, string>(sentence, separator)); foreach (var tuple in tuples) { text.Add(ParseSentence(tuple)); } } } return(text); }
/// <summary> /// Reads the message and the page template /// </summary> /// <param name="name">template name</param> protected override void ReadText(string name) { Message msg; using (bbsContext bbs = new bbsContext()) { msg = bbs.GetMessageById(Params[1]); if (bbs.SetMessageRead(msg.Id, client.username)) { msg.TimesRead++; bbs.SaveChanges(); } } base.ReadText(name); Data.Header = Data.Header.Replace("$msgid$", Params[1]) .Replace("$msgdatetime$", msg.DateTime.ToString("G")) .Replace("$msgfrom$", msg.MessageFrom) .Replace("$msgto$", msg.MessageTo) .Replace("$msgorig$", new FidoAddress(msg.OrigZone, msg.OrigNet, msg.OrigNode, msg.OrigPoint).address4D) .Replace("$msgdest$", new FidoAddress(msg.DestZone, msg.DestNet, msg.DestNode, msg.DestPoint).address4D) .Replace("$msgsubj$", msg.Subject); Header = Data.GetHeaderRows(); Text = TextHelper.SplitString(msg.Body); if (!string.IsNullOrWhiteSpace(msg.TearLine)) { Text.Add($"--- {msg.TearLine}"); } if (!string.IsNullOrWhiteSpace(msg.OriginLine)) { Text.Add($" * Origin: {msg.OriginLine}"); } }
/// <summary> /// Initializes a new instance of the <see cref="SubtitleFrame" /> class. /// </summary> /// <param name="frame">The frame.</param> /// <param name="component">The component.</param> internal SubtitleFrame(AVSubtitle *frame, MediaComponent component) : base(frame, component) { m_Pointer = (AVSubtitle *)InternalPointer; // Extract timing information (pts for Subtitles is always in AV_TIME_BASE units) var timeOffset = TimeSpan.FromTicks(frame->pts.ToTimeSpan(ffmpeg.AV_TIME_BASE).Ticks - component.Container.MediaStartTimeOffset.Ticks); StartTime = TimeSpan.FromTicks(timeOffset.Ticks + ((long)frame->start_display_time).ToTimeSpan(StreamTimeBase).Ticks); EndTime = TimeSpan.FromTicks(timeOffset.Ticks + ((long)frame->end_display_time).ToTimeSpan(StreamTimeBase).Ticks); Duration = TimeSpan.FromTicks(EndTime.Ticks - StartTime.Ticks); // Extract text strings for (var i = 0; i < frame->num_rects; i++) { var rect = frame->rects[i]; if (rect->text != null) { Text.Add(Utils.PtrToStringUTF8(rect->text)); } } // Immediately release the frame as the struct was created in managed memory // Accessing it later will eventually caused a memory access error. Release(); }
//todo build in cancellation token public async Task OnNavigate() { Text.Clear(); LoadMessage = new LoadingViewModel("Load message example", "10 Second delay"); Text.Add("Often you need to execute a process that takes some time to complete."); await Task.Delay(1000); Text.Add("For example: Database or Hardware calls."); await Task.Delay(1000); Text.Add("During this period, you want to show some feedback to the user."); await Task.Delay(1000); Text.Add("Thats why we show a loading bar/message on the left."); await Task.Delay(1000); Text.Add("It's important to note, that we don't block the UI."); await Task.Delay(1000); Text.Add("So the user can use, all available functionality."); await Task.Delay(1000); Text.Add("For example our back button is clickable during this period."); await Task.Delay(4000); LoadMessage.IsLoading = false; }
public void AddLineChar(char @char, ConsoleColor color = ConsoleColor.White, params char[] chars) { Text.Add(new ConsoleObjectList(new ConsoleCharObject(@char, color))); for (int i = 0; i < chars.Length; ++i) { Text[Text.Count - 1].ConsoleObjectGroup.Add(new ConsoleCharObject(chars[i], color)); } }
public void Update() { ShowController(Handed.Right); ShowController(Handed.Left); Text.Add(title, titlePose); Text.Add(description, descPose, V.XY(0.4f, 0), TextFit.Wrap, TextAlign.TopCenter, TextAlign.TopLeft); }
public void AddLineText(string text, ConsoleColor color = ConsoleColor.White, params string[] texts) { Text.Add(new ConsoleObjectList(new ConsoleTextObject(text, color))); for (int i = 0; i < texts.Length; ++i) { Text[Text.Count - 1].ConsoleObjectGroup.Add(new ConsoleTextObject(texts[i], color)); } }
public void AddText(string text) { Text.Add(text); if (DynamicallyResize) { Resize(); } }
public Text Parse(string txt) { bool newSentence = false; Text text = new Text(); Sentence sentence = new Sentence(); Word word = new Word(); for (int i = 0; i < txt.Length; i++) { if (!CheckSeparator(punctuationSeparator.MyPunctuationSeparator(), txt[i]) && !CheckSeparator(punctuationSeparator.Separator(), txt[i]) && !CheckSeparator(punctuationSeparator.CodeSymbolSeparator(), txt[i])) { word.symbol.Content += txt[i]; } else if (!CheckSeparator(punctuationSeparator.MyPunctuationSeparator(), txt[i])) { if (word.symbol.Content == null) { word.punctuationMarkBefore = txt[i]; } else { word.punctuationMarkAfter.Add(txt[i]); } if (CheckSeparator(punctuationSeparator.EndSentenceSeparator(), txt[i]) && word.symbol.Content != null) { sentence.GetType(txt[i]); newSentence = true; } } else { if (txt[i] == '\r' && word.symbol.Content != null) { word.presenceOfLineFeed = true; newSentence = true; } } if (((CheckSeparator(punctuationSeparator.Separator(), txt[i]) || i == (txt.Length - 1) || (CheckSeparator(punctuationSeparator.CodeSymbolSeparator(), txt[i])) || txt[i] == '.') && word.symbol.Content != null)) { sentence.Add(word); if (newSentence) { text.Add(sentence); sentence = new Sentence(); } word = new Word(); newSentence = false; } } return(text); }
/// <summary> /// Reads the text from the buffer. /// </summary> private void ReadFromBuffer(int numberOfString) { for (int i = 0; i < numberOfString; ++i) { Text.Add(buffer.ReadData()); } buffer.Clear(); }
public static Text Parse(string fullText) { var numCurrentSymbol = 0; var numFirstSymbol = 0; var sentence = new Collection <ISentenceItem>(); var text = new Text(); int numPunctuation = 0; while (numCurrentSymbol <= fullText.Length - 1) { if (!char.IsLetterOrDigit(fullText[numCurrentSymbol])) { if (char.IsWhiteSpace(fullText[numCurrentSymbol])) { if (numPunctuation < numCurrentSymbol) { sentence.Add(Word.GetWordByStringValue(fullText.Substring(numFirstSymbol, numCurrentSymbol - numFirstSymbol))); } numPunctuation = numCurrentSymbol + 1; numFirstSymbol = numCurrentSymbol; sentence.Add(Punctuation.GetPunctuationByStringValue(" ")); } if (char.IsPunctuation(fullText[numCurrentSymbol])) { if (numPunctuation < numCurrentSymbol) { sentence.Add(Word.GetWordByStringValue(fullText.Substring(numFirstSymbol, numCurrentSymbol - numFirstSymbol))); } numPunctuation = numCurrentSymbol + 1; numFirstSymbol = numCurrentSymbol; while (numPunctuation <= fullText.Length - 1 && char.IsPunctuation(fullText[numPunctuation])) { numPunctuation++; numCurrentSymbol++; } var punctuation = Punctuation.GetPunctuationByStringValue(fullText.Substring(numFirstSymbol, numPunctuation - numFirstSymbol)); if (punctuation != null) { sentence.Add(punctuation); if (punctuation.IsEndSentence) { text.Add(new Sentence(sentence)); sentence = new Collection <ISentenceItem>(); } } numFirstSymbol = numCurrentSymbol + 1; } numFirstSymbol = numCurrentSymbol + 1; numPunctuation = numCurrentSymbol + 1; } numCurrentSymbol++; } return(text); }
public async Task RunAsync() { CanRun = false; Text.Clear(); Text.Add("Beginning test run..."); await InvokeTests(); CanRun = true; }
public void Update() { Text.Add( "Zwölf Boxkämpfer jagen Viktor quer über den großen Sylter Deich.", Matrix.TR(new Vec3(0, 0, 0), Quat.LookDir(0, 0, 1)), new Vec2(40, 100) * U.cm, TextFit.Wrap); Tests.Screenshot(400, 400, "GermanText.jpg", new Vec3(0, 0, .2f), Vec3.Zero); }
public static Text GetActivatedText(Text text) { var activeText = new Text(); foreach(var paragraph in text) { var activeParagraph = new Paragraph(); foreach(var sentence in paragraph) { activeParagraph.Add(GetActivatedSentence(sentence)); } activeText.Add(activeParagraph); } return activeText; }
public Text ParseFile(string filePath) { Text text = new Text(); var result = new List<string>(); string pattern = @"(?<=[\.!\?])\s*(?=[^\.!\?»])"; string line; string remainingLine = null; var file = new StreamReader(filePath); while ((line = file.ReadLine()) != null) { string[] sentences = Regex.Split(line, pattern); if (!string.IsNullOrWhiteSpace(remainingLine)) sentences[0] = remainingLine + " " + sentences[0]; remainingLine = !IsSentence(sentences[sentences.Length - 1]) ? sentences[sentences.Length - 1] : null; foreach (string sentence in sentences) { if (string.IsNullOrWhiteSpace(sentence)) continue; if (IsSentence(sentence)) result.Add(sentence); } } if (!string.IsNullOrWhiteSpace(remainingLine)) result.Add(remainingLine); file.Close(); foreach (var sentence in result) text.Add(ParseSentence(sentence)); return text; }
public virtual Text ParseText(string text, out int endIndex) { text = TrimSpaces(text); Text result = new Text(); var matches = _textParserRegex.Matches(text); foreach (Match match in matches) { string sentence = match.Value.Trim(); if (sentence != String.Empty) result.Add(ParseTextItem(sentence)); } if (matches.Count != 0) { Match lastMatch = matches[matches.Count - 1]; endIndex = lastMatch.Index + lastMatch.Length - 1; } else endIndex = 0; return result; }
private void OnSortByButtonClick(object sender, RoutedEventArgs e) { if (SortByWordsCountRadioButton.IsChecked.Value) { var sortedSentences = _text.GetSentences().OrderBy(sentence => sentence.Count); var text = new Text(); foreach(var sentence in sortedSentences) { var paragraph = new Paragraph(); paragraph.Add(sentence); text.Add(paragraph); } TextContainer.ItemsSource = text; } else if (SortBySentenceCountRadioButton.IsChecked.Value) { var sortedParagraphs = _text.OrderBy(paragraph => paragraph.Count); var text = new Text(); foreach(var paragraph in sortedParagraphs) { text.Add(paragraph); text.Add(new Paragraph()); } TextContainer.ItemsSource = text; } }
public static Text Parse(TextReader reader) { var text = new Text(); var line = reader.ReadLine(); while(!string.IsNullOrEmpty(line)) { var paragraph = new Paragraph(); text.Add(paragraph); while (!string.IsNullOrEmpty(line)) { var sentenceString = line; var terminalPunctuationMark = line.GetFirstOrDefaultPunctuationMark(DefaultPunctuationMarks.TerminalPunctuationMarks); if (terminalPunctuationMark.HasValue) { var index = line.IndexOfPunctuationMark(terminalPunctuationMark); sentenceString = line.Substring(0, index).TrimStart(' '); line = line.Remove(0, index + terminalPunctuationMark.StringValue.Length); if(text.Count > 1) { var lastParagraph = text.Last(p => p.HasValue); if (lastParagraph.Any()) { var lastSentence = lastParagraph.Last(); if (lastSentence.IsNotFinished) { text.Remove(paragraph); paragraph = lastParagraph; lastSentence.Concat(sentenceString); continue; } } } } else { line = string.Empty; } var sentence = ParseSentenceString(sentenceString, terminalPunctuationMark); paragraph.Add(sentence); } line = reader.ReadLine(); } return text; }
public Text ParseText(string text) { Text _text = new Text(); var result = new List<string>(); string pattern = @"(?<=[\.!\?])\s*(?=[^\.!\?»])"; string[] sentences = Regex.Split(text, pattern); foreach (string sentence in sentences) { if (string.IsNullOrWhiteSpace(sentence)) continue; result.Add(sentence); } foreach (var sentence in result) _text.Add(ParseSentence(sentence)); return _text; }