Aho-Corasick文本在整个单词上都匹配吗? [英] Aho-Corasick text matching on whole words?

查看:129
本文介绍了Aho-Corasick文本在整个单词上都匹配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Aho-Corasick文本匹配,想知道是否可以更改它以匹配条款而不是字符.换句话说,我希望这些术语成为匹配的基础,而不是字符.例如:

I'm using Aho-Corasick text matching and wonder if it could be altered to match terms instead of characters. In other words, I want the the terms to be the basis of matching rather than the characters. As an example:

搜索查询:他",

句子:"Hello world",

Sentence: "Hello world",

Aho-Corasick会将"he"与以索引2结尾的句子"hello world"匹配,但我希望没有匹配项.因此,我指的是术语"一词,而不是字符.

Aho-Corasick will match "he" to the sentence "hello world" ending at index 2, but I would prefer to have no match. So, I mean by "terms" words rather than characters.

推荐答案

一种方法是照常使用Aho-Corasick,然后执行过滤步骤以消除所有误报.例如,每次找到匹配项时,您都可以确认输入中的下一个和上一个字符是非字母字符,例如空格或标点符号.这样,您可以获得Aho-Corasick查找的速度,但是只考虑在文本中显示为整个单词的匹配项.

One way to do this would be to use Aho-Corasick as usual, then do a filtering step where you eliminate all false positives. For example, every time you find a match, you can confirm that the next and previous characters in the input are non-letter characters like spaces or punctuation. That way, you get the speed of the Aho-Corasick lookup, but only consider matches that appear as whole words in the text.

希望这会有所帮助!

这篇关于Aho-Corasick文本在整个单词上都匹配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆