本文整理汇总了Java中opennlp.tools.tokenize.TokenizerME.tokenize方法的典型用法代码示例。如果您正苦于以下问题:Java TokenizerME.tokenize方法的具体用法?Java TokenizerME.tokenize怎么用?Java TokenizerME.tokenize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opennlp.tools.tokenize.TokenizerME
的用法示例。
在下文中一共展示了TokenizerME.tokenize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: segmentWords
import opennlp.tools.tokenize.TokenizerME; //导入方法依赖的package包/类
public List<String> segmentWords(String text) {
List<String> wordsList = new ArrayList<String>();
try {
InputStream modelIn = getClass().getResourceAsStream(wordBin);;
TokenizerModel model = new TokenizerModel(modelIn);
TokenizerME tokenizer = new TokenizerME(model);
String[] words = tokenizer.tokenize(text);
for(String word : words)
if (!punctuation.contains(word))
wordsList.add(word);
modelIn.close();
} catch (IOException e) {
e.printStackTrace();
}
return wordsList;
}
示例2: shouldNLP
import opennlp.tools.tokenize.TokenizerME; //导入方法依赖的package包/类
@Test
public void shouldNLP()
{
try
{
TokenizerME tokenizerME = new TokenizerME(new TokenizerModel(new ClassPathResource("opennlp-models/en/en-token.bin").getInputStream()));
String[] tokens001 = tokenizerME.tokenize("I love Vincent Van Gogh");
Assert.assertEquals("I" , tokens001[0]);
Assert.assertEquals("love" , tokens001[1]);
Assert.assertEquals("Vincent", tokens001[2]);
Assert.assertEquals("Van" , tokens001[3]);
Assert.assertEquals("Gogh" , tokens001[4]);
String[] tokens002 = tokenizerME.tokenize("He's so amazing");
Assert.assertEquals("He" , tokens002[0]);
Assert.assertEquals("'s" , tokens002[1]);
Assert.assertEquals("so" , tokens002[2]);
Assert.assertEquals("amazing", tokens002[3]);
}
catch (Exception e)
{
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
示例3: tokenize
import opennlp.tools.tokenize.TokenizerME; //导入方法依赖的package包/类
String[] tokenize(String sentence) {
TokenizerME tokenizer = new TokenizerME(tokenModel);
String cleanString = sentence.replace('’', '\''); // this is the type of apostrophe that OpenNLP expects
return tokenizer.tokenize(cleanString);
}