Java 使用整数获取字符串数组节
首先,我正在与OpenNLP合作,但是不需要关于它的知识,但可能有用 一个字符串被输入到方法FindNameJava 使用整数获取字符串数组节,java,stringtokenizer,opennlp,Java,Stringtokenizer,Opennlp,首先,我正在与OpenNLP合作,但是不需要关于它的知识,但可能有用 一个字符串被输入到方法FindName String input = "Billy Smith the chicken crossed the road to visit Fred Jones"; 它由标记器处理,为namefinder提供输入: String[] tokenized = "Billy","Smith","the","chicken","crossed","the","road","to","visit","
String input = "Billy Smith the chicken crossed the road to visit Fred Jones";
它由标记器处理,为namefinder提供输入:
String[] tokenized = "Billy","Smith","the","chicken","crossed","the","road","to","visit","Fred","Jones";
搜索名称时,结果以两个字符串的形式给出,这两个字符串在“for”循环中生成
现在,我如何将原始名称(“Billy Smith”和“Fred Jones”)放入arraylist或类似的字符串数组中
到目前为止,我已经尝试:
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]);
}
for(Span s:nameSpans){
numbers=s.toString().replace(“[”,”);
//是“[0..2)个人”和“[9..11)个人”
sect=编号。拆分(“\\”);
}
int x;
对于(x=0;x,Span对象有一个内置的静态方法,可以实现您想要的功能。请参见此答案。
可以通过将输出字符串解析为整数,然后使用原始输入字符串创建字符串数组来创建单词,然后我可以使用正确的数字调用这些单词,从而给出全名和中间名
工作守则:
for(Span s: nameSpans){
String a = s.toString().replace("[", "").replace(")", "");
String[] b = a.split("\\s");
String[] c = b[0].split("\\..");
int first = Integer.parseInt(c[0]);
int second = Integer.parseInt(c[1]);
String[] word = input.split("\\s");
int n;
for(n=first;n<second;n++){
names.add(word[n]);
System.out.println(word[n]);
}
}
for(Span s:nameSpans){
字符串a=s.toString().replace(“[”,”).replace(“),”);
字符串[]b=a.split(\\s”);
字符串[]c=b[0]。拆分(\\..);
int first=Integer.parseInt(c[0]);
int second=Integer.parseInt(c[1]);
字符串[]word=input.split(\\s”);
int n;
对于(n=first;如果这是一个问题:如何将原始名称(“Billy Smith”和“Fred Jones”)放入arraylist或类似的字符串数组中?那么这就是如何使用设计的方法将名称放入数组中://“tokens”这是句子Span[]find=nf.find(tokens)中的字符串[];//使用Span的静态方法获取name String[]namedEntities=Span.spansToStrings的字符串[](find,tokens);在我贴的链接中是我的道歉,很有趣的是误读一部作品会产生如此大的影响。谢谢你的回答,不幸的是,因为有人问我,我已经开始使用斯坦福NLP,我发现它更容易操作。
for(Span s: nameSpans){
String a = s.toString().replace("[", "").replace(")", "");
String[] b = a.split("\\s");
String[] c = b[0].split("\\..");
int first = Integer.parseInt(c[0]);
int second = Integer.parseInt(c[1]);
String[] word = input.split("\\s");
int n;
for(n=first;n<second;n++){
names.add(word[n]);
System.out.println(word[n]);
}
}