如何过滤掉词性标签?

时间:2015-04-19 14:46:35

标签: c# regex vb.net

var sentence =" "/`` Do/VBP n't/RB cut/VB off/RP its/PRP$ power/NN ,/, "/'' he/PRP said/VBD ./. ";
var pattern = new Regex(@"/(?:[.,]|\p{Lu}+\b)");
var outcome = pattern.Replace(sentence, string.Empty);

//Output : "/`` Do n't cut off its$ power , "/'' he said .

我应该如何修改模式以产生预期的输出:

“不要切断它的力量,”他说。

1 个答案:

答案 0 :(得分:0)

试图回答,但这个问题需要一些修改,因为它不能编译:

var sentence = "\"Do/VBP n't/RB cut/VB off/RP its/PRP$ power/NN ,/, \" he/PRP said/VBD ./. ";
var pattern = new Regex(@"/.+?\s+");
var outcome = pattern.Replace(sentence, " ");

var expected = "\"Don't cut off its power,\" he said.";

var success = (outcome == expected);
Console.WriteLine(success);
Console.WriteLine(expected);
Console.WriteLine(outcome);