【问题标题】:Fast way to find substring in text using suffix array and lcp使用后缀数组和 lcp 在文本中查找子字符串的快速方法
【发布时间】:2014-05-10 19:23:39
【问题描述】:

我正在尝试在大文本中查找包含子字符串(作为输入)的单词。 文本如下所示:*america*python*erica*escape*.. 示例:输入:“rica” => 输出:america,erica

我使用后缀数组。

我的伪代码(pythonlike)是:

firstChar=input[0] // the first character of input
suffixArray=getSuffixArray(text) // suffix array
result=[]

for every index of suffix array which points to firstChar:
    length=len(input)
    indexText=text[suffixArray[index]]
    indexes=[]

    if input in text[indexText: indexText+length]:
        word=find whole word containig this index between '*' 
        result.append(word)

这行得通,但是太慢了。 LCP 阵列应该改善算法的运行时间,但我不知道如何。你能给我一个建议吗?

提前致谢!

【问题讨论】:

    标签: python arrays string full-text-search suffix-array


    【解决方案1】:

    后缀数组的免费 Python 代码位于 Effcient way to find longest duplicate string。它可以在个人计算机上处​​理多达 1 亿个字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多