【问题标题】:How to Counting Word support and confidence with lucene如何使用 lucene 计算 Word 支持和信心
【发布时间】:2013-06-16 19:06:06
【问题描述】:

我想在 Java 应用程序中使用 Lucene 来计算单词的支持度和置信度。 我有超过 500 个 .txt 文档,一个 ArrayList 包含两个术语,术语 i 和术语 j

The formula for counting Confidence

Dti-tj/Dti

Dti-tj: Total document contains term i,term j
Dti : Total document contains term i

The formula for counting Support

Dti-tj/D

Dti-tj = Total document contains term i,term j
D = Total Document in the collection

是否可以使用 Lucene 来搜索和计算单词? 我必须使用什么类?

【问题讨论】:

    标签: java lucene full-text-search information-retrieval


    【解决方案1】:

    我会简单地搜索您的两个术语,术语i 和术语j,然后从搜索返回的totalHits 中获取您的计数。

    int docCount = indexReader.numDocs();
    IndexSearcher searcher = new IndexSearcher(indexReader);
    
    Query queryI = new TermQuery(new Term(fieldName, termI));
    Query queryJ = new TermQuery(new Term(fieldName, termJ));
    
    Query queryIJ = new BooleanQuery();
    queryIJ.add(new BooleanClause(queryI, BooleanClause.Occur.SHOULD));
    queryIJ.add(new BooleanClause(queryJ, BooleanClause.Occur.SHOULD));
    
    int countI = searcher.search(nqueryI, maxDocs).totalHits;
    int countIJ = searcher.search(, maxDocs).totalHits;
    
    float confidence = (float)countIJ / (float)countI;
    float support = (float)countIJ / (float)docCount;
    

    【讨论】:

    • 可能 BooleanClause.Occur.Should 必须编辑为 Occur.Must,因为文档必须包含这两个术语
    • 当我读到它时,我认为Dti-tj 是为了代表一个工会。如果它是一个交叉点,那么你会想要使用Occur.MUST,是的。
    猜你喜欢
    • 1970-01-01
    • 2013-02-22
    • 2013-02-23
    • 2023-03-30
    • 2011-03-27
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 2012-05-08
    相关资源
    最近更新 更多