我有一个问题,对专家来说应该很简单,但对我来说却是令人痛苦的神秘:)我想把文本(预处理后,除了常规标点符号之外没有特殊字符)解析成句子,并执行两项类似的任务:
我想知道是否有办法做到这一点,最好是在C#或VB中。任何帮助都将不胜感激。
======================
示例段落:
This is an example of a paragraph! It contains three sentences? And the average sentence has many words. 示例模式:
"three"输出:
number of sentences-3.
Average sentence length-6.
Number of matches-1.发布于 2011-06-02 19:24:44
您可以使用以下方法获得一个句子(取决于您对句子的定义):
(\a|[\.!\?:])[^\.!\?:]+还有一个词使用:
[a-zA-Z]+其余的都很简单--只需查看MSDN上正则表达式的文档即可。
发布于 2011-06-02 19:44:29
这应该是可行的:
string example =
"This is an example of a paragraph! It contains three sentences? And the average sentence has many words.";
var splitExample = example.Split(new[] {'.', '!', '?'}, StringSplitOptions.RemoveEmptyEntries);
var matchExpression = new Regex("three");
double avgLength = splitExample.Average(x => x.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries).Length);
int sentences = splitExample.Length;
int matches = splitExample.Where(x => matchExpression.IsMatch(x)).Count();发布于 2011-06-02 19:23:30
您可以根据句点(.)执行Split。这会给你一系列的句子。
string sentences[] = document.Split('.');然后,根据“空格”对每个“句子数组”执行一个Split,以获得单词数。
是的,然后使用正则表达式进行匹配。由于您没有指定要匹配的内容,所以我可以添加的其他内容不多。
https://stackoverflow.com/questions/6219317
复制相似问题