我正在尝试使用OpenNLP Java API从文档中提取名称,技能之类的实体.但它没有提取专有名称.我正在使用opennlp sourceforge link可用的模型
这是一段Java代码-
public class tikaOpenIntro {
public static void main(String[] args) throws IOException, SAXException,
TikaException {
tikaOpenIntro toi = new tikaOpenIntro();
toi.filest("");
String cnt = toi.contentEx();
toi.sentenceD(cnt);
toi.tokenization(cnt);
String names = toi.namefind(toi.Tokens);
toi.files(names);
}
public String Tokens[];
public String contentEx() throws IOException, SAXException, TikaException {
InputStream is = new BufferedInputStream(new FileInputStream(new File(
"/home/rahul/Downloads/rahul.pdf")));
// URL url=new URL("http://in.linkedin.com/in/rahulkulhari");
// InputStream is=url.openStream();
Parser ps = new AutoDetectParser(); // for detect parser related to
BodyContentHandler bch = new BodyContentHandler();
ps.parse(is, bch, new Metadata(), new ParseContext());
return bch.toString();
}
public void files(String st) throws IOException {
FileWriter fw = new FileWriter("/home/rahul/Documents/extrdata.txt",
true);
BufferedWriter bufferWritter = new BufferedWriter(fw);
bufferWritter.write(st + "\n");
bufferWritter.close();
}
public void filest(String st) throws IOException {
FileWriter fw = new FileWriter("/home/rahul/Documents/extrdata.txt",
false);
BufferedWriter bufferWritter = new BufferedWriter(fw);
bufferWritter.write(st);
bufferWritter.close();
}
public String namefind(String cnt[]) {
InputStream is;
TokenNameFinderModel tnf;
NameFinderME nf;
String sd = "";
try {
is = new FileInputStream(
"/home/rahul/opennlp/model/en-ner-person.bin");
tnf = new TokenNameFinderModel(is);
nf = new NameFinderME(tnf);
Span sp[] = nf.find(cnt);
String a[] = Span.spansToStrings(sp, cnt);
StringBuilder fd = new StringBuilder();
int l = a.length;
for (int j = 0; j < l; j++) {
fd = fd.append(a[j] + "\n");
}
sd = fd.toString();
} catch (FileNotFoundException e) {
e.printstacktrace();
} catch (InvalidFormatException e) {
e.printstacktrace();
} catch (IOException e) {
e.printstacktrace();
}
return sd;
}
public void sentenceD(String content) {
String cnt[] = null;
InputStream om;
SentenceModel sm;
SentenceDetectorME sdm;
try {
om = new FileInputStream("/home/rahul/opennlp/model/en-sent.bin");
sm = new SentenceModel(om);
sdm = new SentenceDetectorME(sm);
cnt = sdm.sentDetect(content);
} catch (IOException e) {
e.printstacktrace();
}
}
public void tokenization(String tokens) {
InputStream is;
TokenizerModel tm;
try {
is = new FileInputStream("/home/rahul/opennlp/model/en-token.bin");
tm = new TokenizerModel(is);
Tokenizer tz = new TokenizerME(tm);
Tokens = tz.tokenize(tokens);
// System.out.println(Tokens[1]);
} catch (IOException e) {
e.printstacktrace();
}
}
}
我想做的是:
>我正在使用Apache Tika将PDF文档转换为纯文本文档.
>我正在通过纯文本文档以进行句子边界检测.
>在此标记化之后
>在此名称实体提取之后
但是它正在提取名称和其他单词.它不是提取专有名称.以及如何创建自定义模型以从“游泳”,“编程”等文档中提取技能?
给我一些想法!
任何帮助将不胜感激!?
解决方法:
听起来您对OpenNLP的预构建名称模型的性能不满意.但是(a)模型永远都不是完美的,即使是最好的模型也会错过一些本应捕捉到的东西,并捕捉一些本应错过的东西; (b)如果经过训练的模型的文档与您要标记的文档的类型和文本样式相匹配,则模型的效果最佳(因此,针对混合大小写文本进行训练的模型在所有情况下都无法很好地发挥作用,大写文字,并且经过新闻报道训练的模型不能很好地在推文上使用).您可以尝试使用其他公开可用的工具,例如Stanford NE工具包或LingPipe.他们可能有性能更好的模型.但是它们都不是完美的.
要创建自定义模型,您需要生成一些训练数据.对于OpenNLP,它看起来像
I have a Ph.D. in <START:skill> operations research <END>
对于如此具体的事情,您可能需要自己拿出这些数据.而且您将需要很多; OpenNLP文档建议使用大约15,000个例句.有关更多详细信息,请查阅OpenNLP文档.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。