我想使用opennlp Java库将自然语言问题转换为SQL查询,即
谁在索契获得女子花样滑冰?
应转换为
select name from winners where event='skating_woman'
Run Code Online (Sandbox Code Playgroud)
有谁知道哪些类有用以及如何实现这一目标?
还粘贴我试过的代码.
我已将问题转换为语句,后来转换为标记.
/////////1st part
String paragraph = "Did Matt win the men slalom?";
InputStream is1 = new FileInputStream("bins/en-sent.bin");
SentenceModel model1 = new SentenceModel(is1);
SentenceDetectorME sdetector = new SentenceDetectorME(model1);
String sentences[] = sdetector.sentDetect(paragraph);
System.out.println(sentences[0]);
is1.close();
////////2nd part
InputStream is2 = new FileInputStream("bins/en-token.bin");
TokenizerModel model2 = new TokenizerModel(is2);
Tokenizer tokenizer = new TokenizerME(model2);
String tokens[] = tokenizer.tokenize(sentences[0]);
for (String a : tokens)
System.out.println(a);
is2.close();
Run Code Online (Sandbox Code Playgroud)