gpt4 book ai didi

java - 从字符串中删除 POS 标签

转载 作者:行者123 更新时间:2023-11-30 07:56:37 26 4
gpt4 key购买 nike

我有一个看起来像这样的字符串:

The/at Fulton/np-tl County/nn-tl Grand/jj-tl Jury/nn-tl said/vbd Friday/nr an/at investigation/nn of/in Atlanta's/np$ recent/jj primary/nn election/nn produced/vbd / no/at evidence/nn ''/'' that/cs any/dti irregularities/nns took/vbd place/nn ./.

我只想提取原始文本并丢弃 POS 标签。我可以使用什么正则表达式来做到这一点。我知道我可以拆分/但我也需要删除标签并获取。我应该使用正则表达式来识别标签吗?

The Fulton County Grand Jury said Friday an investigation of Atlanta's recent primary election produced "no evidence" that any irregularities took place .

最佳答案

您可以使用 String#replaceAll()使用模式 /.*?(\s|$) 删除 POS 标签。我认为以下代码应该可以让您非常接近您想要的位置。

String input = "The/at Fulton/np-tl County/nn-tl Grand/jj-tl Jury/nn-tl said/vbd Friday/nr an/at investigation/nn of/in Atlanta's/np$ recent/jj primary/nn election/nn produced/vbd / no/at evidence/nn ''/'' that/cs any/dti irregularities/nns took/vbd place/nn ./.";
input = input.replaceAll("/.*?(?:\\s|$)", " ");
System.out.println(input);

输出:

The Fulton County Grand Jury said Friday an investigation of Atlanta's recent primary
election produced no evidence " that any irregularities took place . "

关于java - 从字符串中删除 POS 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41974758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com