- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题 - 我正在尝试使用我在搜索网络时为 C++ 找到的 aho-corasick 算法,它目前仅搜索基于字符的字符串,我希望它修改它以搜索基于十六进制的各种字符的字符串。非常感谢任何改进代码的帮助。如果我只是修改字符串文本,它就会进入无限循环。
int buildMatchingMachine(const vector<string> &words, char lowestChar = 'a', char highestChar = 'z')
{
memset(out, 0, sizeof out);
memset(f, -1, sizeof f);
memset(g, -1, sizeof g);
int states = 1; // Initially, we just have the 0 state
for (int i = 0; i < words.size(); ++i)
{
const string &keyword = words[i];
int currentState = 0;
for (int j = 0; j < keyword.size(); ++j)
{
int c = keyword[j] - lowestChar;
if (g[currentState][c] == -1)
{ // Allocate a new node
g[currentState][c] = states++;
}
currentState = g[currentState][c];
}
out[currentState] |= (1 << i); // There's a match of keywords[i] at node currentState.
}
// State 0 should have an outgoing edge for all characters.
for (int c = 0; c < MAXC; ++c)
{
if (g[0][c] == -1)
{
g[0][c] = 0;
}
}
// Now, let's build the failure function
queue<int> q;
for (int c = 0; c <= highestChar - lowestChar; ++c)
{ // Iterate over every possible input
// All nodes s of depth 1 have f[s] = 0
if (g[0][c] != -1 && g[0][c] != 0)
{
f[g[0][c]] = 0;
q.push(g[0][c]);
}
}
while (q.size())
{
int state = q.front();
q.pop();
for (int c = 0; c <= highestChar - lowestChar; ++c)
{
if (g[state][c] != -1)
{
int failure = f[state];
while (g[failure][c] == -1)
{
failure = f[failure];
}
failure = g[failure][c];
f[g[state][c]] = failure;
out[g[state][c]] |= out[failure]; // Merge out values
q.push(g[state][c]);
}
}
}
return states;
}
int openFile::findNextState(int currentState, char nextInput, char lowestChar = 'a')
{
int answer = currentState;
int c = nextInput - lowestChar;
while (g[answer][c] == -1)
answer = f[answer];
return g[answer][c];
}
最佳答案
我找到了一个可行的解决方案,您只需将基于十六进制的符号的最低字符和最高字符重新定义为其相应的ascii值而不是int值,还将MAXS和MAXC更改为合适的数字,现在代码适用于基于十六进制的符号值(value)观。
关于c++ - C/C++ 中的 Aho-Corasick 算法(十六进制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29210215/
我想在大量文档中搜索字符串。我有一个预定义的可用字符串列表,我想在每个文档中找到它。每个文档的开头都包含一个标题,后面是文本,标题中是我想在标题下方的文本中搜索的其他字符串。 在文档的每次迭代中,是否
请帮助我理解 Aho-Corasick 算法中多于一种模式的状态转换表的构造。 请简单详细的解释一下,让我明白。 我正在关注 this纸和here是那个的动画。 谢谢。 最佳答案 第一阶段 创建关键字
我正在尝试理解 aho-corasick 字符串匹配算法。假设我们的模式是 abcd 和 bc。我们最终得到这样一棵树 [] /\ [a]..[b] /
我想在文本文档中搜索关键短语数据库(从维基百科文章标题中提取)中出现的关键短语。 (即给定一份文件,我想查找是否有任何短语具有相应的维基百科文章)我发现了 Aho-Corasick 算法。我想知道为包
我正在尝试解决 HackerRank 上的一个问题; “确定 DNA 健康状况。”在查看了一些讨论后,我决定 Aho-Corasick 算法将是最佳选择。该问题涉及在字符串中搜索具有关联值的各种序列。
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
如果是这样,有人可以解释后缀树中后缀链接的用途,以实现精确的字符串匹配吗? 最佳答案 没有。后缀链接是后缀树中的特定转换。给定树中表示子串 (si) 的状态,其中 0 < i < n,从该状态出发的后
我有 Aho-Corasick 算法的代码。但是我仍然不明白在给定字符串列表中搜索文本时如何在查找过程中使用状态信息。 例如,我有一个字符串列表 [MOSCOW][COLA],现在我需要确定 CA 是
我正在使用 Aho-Corasick 文本匹配,想知道是否可以更改它以匹配术语 而不是字符。换句话说,我希望术语成为匹配的基础而不是字符。例如: 搜索查询:“他”, 句子:“Hello world”,
有没有像Aho-Corasick这样的算法, 可以同时匹配一组模式,适用于反恶意软件比较?所有已知的商业防病毒软件都使用 Aho-Corasick 算法吗? 与Boyer-Moore 相比,Aho-C
我有一个大文本 (5MB-500MB) 文件和一组数千个模式。对于每个模式,我想获取该模式在文件中出现的次数。文本不包含空格,是一个基本的长字母数字字符串。 为此,我尝试使用 Aho-Corasick
我发现的关于 Aho-Corasick 的所有文献和实现都是关于从一组短语预先构建整个 trie 的。但是,我对将其作为可变数据结构使用的方法很感兴趣,它可以处理偶尔的添加和删除,而无需重建整个 tr
我们的 ruby on rails 应用程序使用 aho corasick gem 来查找任何给定文本是否包含任何预先列出的坏词(这些是在加载应用程序时从静态配置中挑选出来的)。 但是,使用它会产
是否有 Aho–Corasick 的有效实现?在 PHP 中?有一个 Aho-Corasick string matching in PHP维基百科文章中提到: patterns_array = $w
我的问题 - 我正在尝试使用我在搜索网络时为 C++ 找到的 aho-corasick 算法,它目前仅搜索基于字符的字符串,我希望它修改它以搜索基于十六进制的各种字符的字符串。非常感谢任何改进代码的帮
首先,我是二进制文件的新手,希望这不是一个愚蠢的问题。 我已经生成了包含来自二进制文件的 .text 部分的指令序列的表。具有 2 条指令序列的表如下所示: sequence | to
我有一段 PHP 代码可以成功地在 $post 数据中搜索 $list 关键字,并在相似度约为 80-90% 的地方回显结果。下面是代码: $list = array( "Data" => "
有谁知道是否可以修改 Aho-Corasick 字符串匹配算法以用于 DAWG(有向无环词图)而不是 Trie? 最佳答案 Aho-Corasick 算法中的 trie 不是简单的单词 trie,而是
使用三叉树的 FSA 和将转换表实现为搜索树(例如 std::map)的 trie 有什么区别?看起来两者都具有读取一个符号的 O(log k) 复杂度和 O(S) 内存复杂度,其中 k 是字母表大小
我是一名优秀的程序员,十分优秀!