在 stanford pos tagger 中编辑配置文件

edit config file in stanford pos tagger

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

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 代码,您可以使用下载的 ZIP 文件中的 bash 文件。 提取 postagger 的 ZIP 文件后,编辑以下 bash 文件:

stanford-postagger.sh

它应该有下面一行:

java -mx300m -cp 'stanford-postagger.jar:lib/*' edu.stanford.nlp.tagger.maxent.MaxentTagger -model  -textFile 

"-model $1"之后添加名为"-tagSeparator [YourTag]"的参数:

java -mx300m -cp 'stanford-postagger.jar:lib/*' edu.stanford.nlp.tagger.maxent.MaxentTagger -model  -tagSeparator * -textFile 

给运行它(确保已授予必要的权限):

./stanford-postagger.sh models/model_name.tagger in_filename > out_filename

瞧!