我标记了一个简单的句子,这是我的代码:
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)
然后删除 arch
和 trainFile
属性。
关于java - 在 stanford pos tagger 中编辑配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29429137/