1

假设我们有一个关键字字典

Dictionary A: {A1, A2, A3}

假设我们有第二个关键字词典(与第一个不同)

Dictionary B: {B1, B2, B3, B4}

我想从输入文本中的两个字典中查找序列中无序关键字对的所有可能匹配项(即,仅由空格分隔)。例如,将以下内容视为输入文本

We are not looking for single words from either dictionary on their own, like 
A2 or B4, nor are we looking for sequences of words from only one dictionary, 
like A1 A3 or B4 B2. We are looking for tuples of words from both dictionaries
in a sequence together, like B1 A3 and A2 B4 and B4 A2.

Aho-Corasick 算法是一种传统的解决方案,它通过构造一个类似 trie 的自动机并逐个字符地扫描文本,从而有效地从输入文本中的单个关键字词典中找到所有匹配项。

对于多个字典的情况,是否有一种有效的方法来扩展 Aho-Corasick ?

4

1 回答 1

0

是的,您可以为每个文档构建一个通用的 aho-corasick 自动机和一个个体:使用 Aho-Corasick,可以在构建初始树后添加字符串吗?

于 2016-04-10T09:35:08.693 回答