我正在使用maltparser,nltk处理过程文本。好吧,我有maltparser和nltk之间的集成,工作正常。但是因为每次我执行程序nltk调用java VE这需要花费很多时间...所以我认为制作一个web服务谁需要conll .txt并返回由java app解析的conll。
当我从maltparser来源测试示例时,问题就出现了。我从初始化模型中选择一个并解析一个标记数组。我只是将de model改为常规英语(engmalt.linear-1.7.mco)。因此,就像输入一样执行并返回句子。
代码是这个
public static void main(String[] args) {
// Loading the Swedish model swemalt-mini
ConcurrentMaltParserModel model = null;
try {
URL swemaltMiniModelURL = new File("inputs/engmalt.linear-1.7.mco").toURI().toURL();
System.out.println(swemaltMiniModelURL.getFile());
model = ConcurrentMaltParserService.initializeParserModel(swemaltMiniModelURL);
} catch (Exception e) {
e.printStackTrace();
}
// Creates an array of tokens, which contains the Swedish sentence 'Samtidigt får du högsta sparränta plus en skattefri sparpremie.'
// in the CoNLL data format.
String[] tokens = new String[5];
tokens[0] = "1\tThis\t_\tDT\tDT\t_\t0\ta\t_\t_";
System.out.println(tokens[0]);
tokens[1] = "2\tis\t_\tVBZ\tVBZ\t_\t0\ta\t_\t_";
System.out.println(tokens[1]);
tokens[2] = "3\ta\t_\tZ\tZ\t_\t0\ta\t_\t_";
System.out.println(tokens[2]);
tokens[3] = "4\ttest\t_\tNN\tNN\t_\t0\ta\t_\t_";
System.out.println(tokens[3]);
tokens[4] = "5\t.\t_\tFp\tFp\t_\t0\ta\t_\t_";
System.out.println(tokens[4]);
try {
String[] outputTokens = model.parseTokens(tokens);
ConcurrentUtils.printTokens(outputTokens);
} catch (Exception e) {
e.printStackTrace();
}
}
,输出为:
/home/tomas/workspace/PruebaMalt/inputs/engmalt.linear-1.7.mco
1 This _ DT DT _ 0 a _ _
2 is _ VBZ VBZ _ 0 a _ _
3 a _ Z Z _ 0 a _ _
4 test _ NN NN _ 0 a _ _
5 . _ Fp Fp _ 0 a _ _
1 This _ DT DT _ 0 a _ _
2 is _ VBZ VBZ _ 0 a _ _
3 a _ Z Z _ 0 a _ _
4 test _ NN NN _ 0 a _ _
5 . _ Fp Fp _ 0 a _ _
我尝试与其他模特和语言一样......任何建议? TY!
答案 0 :(得分:1)
1 This _ DT DT _ 0 a _ _
并返回:1 This _ DT DT _ 2 SUBJ _ _
但是在java中格式有点不同,最后2 _
必须删除。有了这个,它就会起作用!
输入:1 This _ DT DT _
返回:1 This _ DT DT _ 2 SUBJ _ _
我希望这有助于他人。