Dictionary Aho搜索关键字对

Dictionary Aho搜索关键字对,dictionary,pattern-matching,string-search,aho-corasick,Dictionary,Pattern Matching,String Search,Aho Corasick,假设我们有一本关键字词典 Dictionary A: {A1, A2, A3} 假设我们有第二个关键字词典(不同于第一个) 我想从输入文本中的两个词典中找到一个序列(即,仅由空格分隔)中无序关键字对的所有可能匹配项。例如,考虑以下作为输入文本 We are not looking for single words from either dictionary on their own, like A2 or B4, nor are we looking for sequences of wo

假设我们有一本关键字词典

Dictionary A: {A1, A2, A3}
假设我们有第二个关键字词典(不同于第一个)

我想从输入文本中的两个词典中找到一个序列(即,仅由空格分隔)中无序关键字对的所有可能匹配项。例如,考虑以下作为输入文本

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,以适应多个词典的情况?

是的,您可以为每个文档构建一个通用Aho Corasick自动机和一个单独的:

是的,您可以为每个文档构建一个通用Aho Corasick自动机和一个单独的:

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.