首先,我正在使用 OpenNLP,但是不需要有关它的知识,但可能会有用。
一个字符串被输入到方法FindName
String input = "Billy Smith the chicken crossed the road to visit Fred Jones";
它由标记器处理以提供名称查找器的输入:
String[] tokenized = "Billy","Smith","the","chicken","crossed","the","road","to","visit","Fred","Jones";
搜索名称,结果以“for”循环中生成的两个字符串的形式给出
"[0..2) person","[9..11) person"
现在如何将原始名称(“Billy Smith”和“Fred Jones”)放入数组列表或类似的字符串数组中?
到目前为止,我已经尝试过:
for(Span s: nameSpans){
numbers = s.toString().replace("[", "");
//is "[0..2) person" and "[9..11) person"
sect = numbers.split("\\) ");
}
int x;
for(x=0;x<sect.length;x++){
if(x%2 == 0){
String[] numb = sect[x].split("..");
int n;
int first, second;
first = Integer.parseInt(numb[0]);
second = Integer.parseInt(numb[1]);
for(n=first;n<second;n++){
if(sentence.hashCode() == n){
name.add(sentence[n]);
}
但没有运气。