java - 如何在 Lucene 3.4.0 中创建二元/三元索引?

标签 java lucene tokenize

我是 Lucene 的新手,我非常希望有一个关于如何在索引中包含二元组和三元组标记的示例。

我正在使用以下代码,我已经对其进行了修改,以便能够计算术语频率和权重,但我也需要对二元组和三元组执行此操作。我看不到标记化部分!我在网上搜索,一些建议的类在 Lucene 3.4.0 中不存在,因为它们已被弃用。

有什么建议吗?

谢谢, 萌

编辑:--------------------------------

现在我按照 mbonaci 的建议使用 NGramTokenFilter。 这是我标记文本以获得 uni、bi 和 trigrams 的代码的一部分。但这是在字符而不是单词级别上完成的。

代替: [H][e][l][l][o][HE][EL]

我正在寻找:[Hello][World][Hello World]

        int min =1;
        int max =3;
        WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_34);
        String text ="hello my world";
        TokenStream tokenStream = analyzer.tokenStream("Data", new StringReader(text));


        NGramTokenFilter myfilter = new NGramTokenFilter(tokenStream,min,max);
        OffsetAttribute offsetAttribute2 = myfilter.addAttribute(OffsetAttribute.class);
        CharTermAttribute charTermAttribute2 = myfilter.addAttribute(CharTermAttribute.class)
        while (myfilter.incrementToken()) {
            int startOffset = offsetAttribute2.startOffset();
            int endOffset = offsetAttribute2.endOffset();
            String term = charTermAttribute2.toString();
            System.out.println(term);
        };

最佳答案

你需要看看shingles .那篇文章展示了如何做到这一点。

关于java - 如何在 Lucene 3.4.0 中创建二元/三元索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11654737/

相关文章:

elasticsearch - 在Elasticsearch中更改文档的_type

elasticsearch - 在ElasticSearch中使用 token 化器“asciifolding”的“pattern”

c++ - CPP 字符串的字符串分词器?

mysql - HTTP ERROR 500 prbm accessing/solr/dataimport 无法配置 solr

apache - 为bm25相似性配置solr

java - Intellij IDEA 中的汉字——如何显示?

java - 如何使用 Jersey Rest 服务传送 .jad 文件?

python - 如何改进 NLTK 句子分割?

java - 为什么 http ://localhost:8080 available while 127. 0.0.1 不行? (MyEclipse+Tomcat上的JSP)

java - 安装后如何将应用程序注册为启动器