SST*_*SST 6 java nlp stanford-nlp opennlp
我需要使用NLP来解决以下问题,您能否指出如何使用OpenNLP API实现这一点
一个.如何判断一个句子是否暗示过去,现在或将来的某种行为.
(e.g.) I was very sad last week - past
I feel like hitting my neighbor - present
I am planning to go to New York next week - future
Run Code Online (Sandbox Code Playgroud)
湾 如何找到与个人,公司或国家相对应的单词
(e.g.) John is planning to specialize in Electrical Engineering in UC Berkley and pursue a career with IBM).
Run Code Online (Sandbox Code Playgroud)
人=约翰
公司= IBM
位置=伯克利
谢谢
我可以提供解决方案
解决方案b.
这是代码:
public class tikaOpenIntro {
public String Tokens[];
public static void main(String[] args) throws IOException, SAXException,
TikaException {
tikaOpenIntro toi = new tikaOpenIntro();
String cnt;
cnt="John is planning to specialize in Electrical Engineering in UC Berkley and pursue a career with IBM.";
toi.tokenization(cnt);
String names = toi.namefind(toi.Tokens);
String org = toi.orgfind(toi.Tokens);
System.out.println("person name is : "+names);
System.out.println("organization name is: "+org);
}
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 String orgfind(String cnt[]) {
InputStream is;
TokenNameFinderModel tnf;
NameFinderME nf;
String sd = "";
try {
is = new FileInputStream(
"/home/rahul/opennlp/model/en-ner-organization.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 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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且你想要位置也导入位置模型也可以在openNLP源Forge上获得.你可以下载,你可以使用它们.
我不确定名称,位置和组织提取的可能性,但几乎可以识别所有名称,位置和组织.
而如果没有找到足够openNLP然后使用斯坦福解析器名称实体认识.