【问题标题】:Lucene TermPositionVector and retrieving terms at index locationsLucene TermPositionVector 和检索索引位置的术语
【发布时间】:2010-08-20 05:11:23
【问题描述】:

我一直在为这个问题的答案而疯狂,但我仍然在黑暗中:

我正在使用

int[] getTermPositions(int index)

我有一个 TermPositionVector 的字段(已设置为存储偏移量和位置)来获取我有兴趣在上下文中突出显示为关键字的术语的术语位置。

问题:这些位置对应什么?显然不是

String[] getTerms()

由 TermFreqVector 接口返回,因为它只包含我的术语的原始计数。

我正在寻找一种方法来获取我的字段的“标记化”数组,这样我就可以在getTermPositions(int index) 返回的索引值周围提取周围的术语

帮助?非常感谢。

【问题讨论】:

    标签: indexing lucene keyword


    【解决方案1】:
    int[] getTermPositions(int index)
    

    返回术语 i 的术语位置数组。您可以使用 i 获取索引

    int indexOf(String term)
    

    TermFreqVector 的方法。术语位置是给定术语出现的位置(以术语为单位)。例如,

    // source text:
    // term position 0   1     2     3   4     5    6   7    8
    //               the quick brown fox jumps over the lazy dog
    
    // terms:
    // term index 0     1   2   3    4    5    6     7
    //            brown dog fox jump lazy over quick the
    
    // Suppose we want to find the positions where "the" occurs
    
    int index = termPositionVector.indexOf("the"); // 7
    int positions = termPositionVector.getTermPositions(index); // {0, 6}
    

    【讨论】:

    • 我已经做到了这一点,但是现在如果我想获取源中位置 5 和 7 的单词,以便我可以输出在上下文中显示“the”的“over the lazy”,该怎么办?
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2012-02-11
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      相关资源
      最近更新 更多