gpt4 book ai didi

java - 斯坦福 POS 标记器 : How to preserve newlines in the output?

转载 作者:行者123 更新时间:2023-12-01 15:12:31 25 4
gpt4 key购买 nike

我的 input.txt 文件包含以下示例文本:

你必须让我们
来见我吧。

现在,如果我使用默认命令调用斯坦福 POS 标记器:

java -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/wsj-0-18-bidirectional-distsim.tagger -textFile input.txt > output.txt

我在我的output.txt 文件中得到以下内容:

you_PRP have_VBP to_TO let_VB 's_POS come_VB and_CC see_VB me_PRP ._.

上述输出的问题是我丢失了输入文件中使用的原始换行符。

现在,如果我使用以下命令在输出文件中保留换行符分隔符,我必须将 -tokenize 选项设置为 false:

java -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/wsj-0-18-bidirectional-distsim.tagger -sentenceDelimiter newline -tokenize false -textFile input.txt > output.txt 

这段代码的问题在于它完全搞乱了输出:

you_PRP have_VBP to_TO let's_NNS  
come_VB and_CC see_VB me._NN

让我们和我来吧。被不当标记。

我的问题是如何在输出文件中保留换行符而不扰乱标记化?

最佳答案

答案应该是使用命令:

java -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/wsj-0-18-bidirectional-distsim.tagger -sentenceDelimiter newline -textFile input.txt > output.txt 

但是有一个错误,它在 3.1.3 版本(也许还有所有早期版本)中不起作用(忽略换行符)。它将在 3.1.4+ 版本中运行。

同时,如果文本量较小,您可以尝试使用斯坦福解析器(其中相应的标志命名不同,因此为 -sentences newline)。

关于java - 斯坦福 POS 标记器 : How to preserve newlines in the output?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12140683/

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