java - 在 stanford pos tagger 中编辑配置文件

标签 java nlp stanford-nlp maxent

我标记了一个简单的句子,这是我的代码:

package tagger;

import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class myTag {

public static void main(String[] args) {

    MaxentTagger tagger = new MaxentTagger("D:/tagger/english-bidirectional-distsim.tagger");


    String sample = "i go to school by bus";

    String tagged = tagger.tagString(sample);

    System.out.println(tagged);
}

}

这是输出:

    Reading POS tagger model from D:/tagger/english-bidirectional-distsim.tagger    ... done [3.0 sec].
i_LS go_VB to_TO school_NN by_IN bus_NN 

编辑属性文件后,它根本没有任何效果。 例如,我已将标签分隔符更改为 ( * ),但在输出中它仍然打印 ( _ )。

如何在 eclipse 中使用模型配置文件?

最佳答案

您可以加载属性文件并将其传递给 MaxEnt 的构造函数,如下所示:

Properties props = new Properties();
props.load(new FileReader("path/to/properties"));
MaxentTagger tagger = new MaxentTagger("D:/tagger/english-bidirectional-distsim.tagger", props);

你也可以直接在props对象中设置属性:

props.setProperty("tagSeparator", "*");

注意:如果您使用原始属性文件并且失败并出现类似

的异常
java.io.FileNotFoundException: /u/nl
p/data/pos_tags_are_useless/egw4-reut.512.clusters (No such file or directory)

然后删除 archtrainFile 属性。

关于java - 在 stanford pos tagger 中编辑配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29429137/

相关文章:

java - Jackson 序列化 View : nested object

search - 有没有可以直接给出答案的搜索引擎?

python - 导入 sutime 模块时出现以下导入错误 - 这是什么意思?

java - 在 stanford-nlp 中训练 NER 模型

Java 16 位对齐

java - 如何使用不在 "Query-Collection"中的值对 Firestore RecyclerView 项目进行排序? (社交排行榜)

java - JShell <Shift+tab i> 在 jdk 9 中无法正常工作

python - 如何在 spaCy 中获取句子编号?

python - 属性错误: 'tuple' attribute has no attribute 'endswith' Python NLTK Lemmatizer

python - 无法使 Stanford POS 标记器在 nltk 中工作