【发布时间】:2016-05-11 07:00:30
【问题描述】:
我有这个方法返回一个 arrayList 标记:
public static String[] Tokenize(String input) throws InvalidFormatException, IOException {
InputStream is = new FileInputStream("en-token.bin");
TokenizerModel model = new TokenizerModel(is);
Tokenizer tokenizer = new TokenizerME(model);
String tokens[] = tokenizer.tokenize(input);
for (String a : tokens)
System.out.println(a);
is.close();
return tokens;
}
我希望这些令牌用于另一种方法:
public static void findName(String[] input) throws IOException {
InputStream is = new FileInputStream("en-ner-person.bin");
TokenNameFinderModel model = new TokenNameFinderModel(is);
is.close();
NameFinderME nameFinder = new NameFinderME(model);
Span nameSpans[] = nameFinder.find(input);
for(Span s: nameSpans)
System.out.println(s.toString());
}
另外,我怎样才能在另一个类中使用这个标记 arrayList,例如,
public class Main{
public static void main( String[] args) throws Exception
{
Anotherclass.Tokenize(input);
Anotherclass.findName(tokens);
}
}
我无法弄清楚这一点!请帮帮我。
非常感谢!
【问题讨论】:
-
调用那个Tokenize()并使用它
-
你在哪里声明了 ArrayList?
-
你的方法返回的不是
ArrayList对象而是一个字符串数组;它们是不同的。只需为您的方法String[] tokens声明一个新的输入参数并将其用于您的代码。 -
^^ 这里:字符串令牌[] = tokenizer.tokenize(input);
标签: java arrays string arraylist opennlp