本文整理汇总了C#中Text.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Text.Add方法的具体用法?C# Text.Add怎么用?C# Text.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActivatedText
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;
}
示例2: ParseFile
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;
}
示例3: Parse
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;
}
示例4: ParseText
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;
}
示例5: OnSortByButtonClick
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;
}
}
示例6: ParseText
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;
}