您需要通过注释一些 opennlp 格式的句子来训练自己的模型。对于您发布的例句,格式如下所示:
what is the risk value on <START:product> icm2500 <END>.
Delivery of <START:product> prd_234 <END> will be arrived late.
Watson is handling <START:product> router_34 <END>.
确保每个句子都以换行符结尾,以及句子中是否有换行符以某种方式转义。
一旦你从你的数据中创建了一个这样的文件,那么你就可以使用 Java API 来训练这样的模型
public static void main(String[] args){
Charset charset = Charset.forName("UTF-8");
ObjectStream<String> lineStream =
new PlainTextByLineStream(new FileInputStream("your file in the above format"), charset);
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream);
TokenNameFinderModel model;
try {
model = NameFinderME.train("en", "person", sampleStream, TrainingParameters.defaultParams(),
null, Collections.<String, Object>emptyMap());
}
finally {
sampleStream.close();
}
try {
modelOut = new BufferedOutputStream(new FileOutputStream(modelFile));
model.serialize(modelOut);
} finally {
if (modelOut != null)
modelOut.close();
}
}
现在您可以将模型与名称查找器一起使用。
因为您可能有一个明确的并且可能很短的产品名称列表,您可以考虑使用简单的正则表达式方法。
这里有一些涉及 NameFinder 的 opennlp 文档:
http://opennlp.apache.org/documentation/1.5.3/manual/opennlp.html#tools.namefind.training.tool