栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Lucene中使用WikipediaTokenizer的示例

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Lucene中使用WikipediaTokenizer的示例

在Lucene
3.0中,删除了next()方法。现在,您应该使用增量令牌遍历令牌,并且在到达输入流的末尾时将返回false。要获取每个令牌,应使用AttributeSource类的方法。根据要获取的属性(术语,类型,有效负载等),您需要使用addAttribute方法将相应属性的类类型添加到令牌生成器中。

以下部分代码示例来自WikipediaTokenizer的测试类,如果您下载了Lucene的源代码,则可以找到该类。

...WikipediaTokenizer tf = new WikipediaTokenizer(new StringReader(test));int count = 0;int numItalics = 0;int numBoldItalics = 0;int numCategory = 0;int numCitation = 0;TermAttribute termAtt = tf.addAttribute(TermAttribute.class);TypeAttribute typeAtt = tf.addAttribute(TypeAttribute.class);while (tf.incrementToken()) {  String tokText = termAtt.term();  //System.out.println("Text: " + tokText + " Type: " + token.type());  String expectedType = (String) tcm.get(tokText);  assertTrue("expectedType is null and it shouldn't be for: " + tf.toString(), expectedType != null);  assertTrue(typeAtt.type() + " is not equal to " + expectedType + " for " + tf.toString(), typeAtt.type().equals(expectedType) == true);  count++;  if (typeAtt.type().equals(WikipediaTokenizer.ITALICS)  == true){    numItalics++;  } else if (typeAtt.type().equals(WikipediaTokenizer.BOLD_ITALICS)  == true){    numBoldItalics++;  } else if (typeAtt.type().equals(WikipediaTokenizer.CATEGORY)  == true){    numCategory++;  }  else if (typeAtt.type().equals(WikipediaTokenizer.CITATION)  == true){    numCitation++;  }}...


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/438951.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号