- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Regex 的“模糊匹配”功能模块。
如何获得“匹配”的“模糊值”,它表示模式与字符串的不同程度,就像 Levenshtein 中的“编辑距离”一样?
我以为我可以获取 Match 对象中的值,但它不存在。官方文档对此什么也没说。
例如:
regex.match('(?:foo){e}','for')
a.captures()
告诉我“for”这个词被匹配了,但是我想知道模糊度值,这里应该是1
案例。
有什么办法可以实现吗?
最佳答案
>>> import difflib
>>> matcher = difflib.SequenceMatcher(None, 'foo', 'for')
>>> sum(size for start, end, size in matcher.get_matching_blocks())
2
>>> max(map(len, ('foo', 'for'))) - _
1
>>>
>>>
>>> matcher = difflib.SequenceMatcher(None, 'foo', 'food')
>>> sum(size for start, end, size in matcher.get_matching_blocks())
3
>>> max(map(len, ('foo', 'food'))) - _
1
http://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher.get_matching_blocks http://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher.get_opcodes
关于Python "regex"模块 : Fuzziness value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17023862/
定义语言变量时,通常会指定最小值和最大值。例如,在定义温度变量时,有人可能会指定 -40C 和 +85C 作为该变量的范围。然后在变量的总体范围内定义模糊集的成员(例如冷、温、热)。 在实际应用中,如
你能推荐一些轻量级的模糊文本搜索库吗? 我想要做的是允许用户为有拼写错误的搜索词找到正确的数据。 我可以使用像 Lucene 这样的全文搜索引擎,但我认为这是一种矫枉过正。 编辑: 为了使问题更清楚,
我有一个字符串数据库(任意长度),其中包含超过一百万个项目(可能更多)。 我需要将用户提供的字符串与整个数据库进行比较,并检索相同的字符串(如果存在),否则返回最接近的模糊匹配(相似度为60%或更高)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
我制作了一个模糊模板,它将代表学生在某个领域的知识。问题是,在宣布学生 John 为 low 后,他也将被宣布为 med,因为 low 学生的年龄也在 30 到 40 之间。 如何在不医疗的情况下宣布
我所说的模糊匹配并不是指通过 Levenshtein 距离或类似的东西来表示相似的字符串,而是它在 TextMate/Ido/Icicles 中的使用方式:给定一个字符串列表,找到包含搜索字符串中所有
我正在尝试用 Java 编写一个简单的绘图小程序,但我在使用 BasicStroke 时遇到了问题。最初,我的计划是尝试以某种方式绘制一条有宽度的线,但 API 显然不支持。 我尝试使用 BasicS
使用 Excel 2010 和 Microsoft“模糊查找”添加来比较 2 个工作表中的一列。第一个工作表有大约 48,000 行(x 3 列),第二个工作表有大约 23,000 行(x 5 列)。
在我正在创建的应用程序中,我想添加将新闻故事组合在一起的功能。我想将来自不同来源的关于同一主题的新闻故事分组到同一个组中。例如,来自 CNN 和 MSNBC 的关于 XYZ 的文章将属于同一组。我猜它
我正在使用 ElasticSearch,我正在尝试实现 match_phrase/string + fuzziness,但似乎不可能(在线示例不多,文档中没有此类案例)。 我需要的是:短语/字符串匹配
检查 $barcode 和两个字符串之间的距离,第一个字符串在前面有相同的 12 个字符,另一个完全不同但都给出相同的距离? #!/usr/bin/perl use warnings; use str
对于我当前的项目,我需要找到一种“模糊”的方法——在客户端对 JavaScript 数组进行指纹识别。 问题在于数组中的元素会随时间变化。通过更改我的意思是订单是稳定的,但一些元素可能会被删除,而其他
我想知道是否有办法让模糊搜索工具“fzf”将查询复制到命令行以便能够对其进行编辑,以防没有令人满意的匹配。 谢谢。 最佳答案 您可以创建一个键绑定(bind),将所选文件的路径(或该文件的内容)复制到
我有 IMDb 的 100 部最佳电影列表。鉴于标题,我试图通过它找到一种“模糊搜索”的方法。即,如果您输入“shaw”,结果将显示“肖申克的救赎”。如果未输入任何内容(即 search 是空字符串)
我试图创建一个查询,以完全匹配某些字段,例如account_id和from_addresses(这是一个数组),同时也模糊匹配另一个字段(例如message_content)。做这个的最好方式是什么?
如果我使用以下代码,我将找到一个以“X”开头的 Item.ShowName - 如果存在的话。 List myList = new List(); //Fill list with items Art
我正在清理继承的脏数据库,需要“模糊匹配”名称以供人工审核。我想出了一个可行的解决方案,但速度非常慢——15k 行需要 7 分钟。我感觉我忽略了一些非常简单的解决方案。 记录示例: 1 John S
我正在尝试用 Rust 编写一个“模糊比较”函数。 这是一个例子: fn fuzzy_cmp(a: f64, b: f64, tolerance: f64) -> bool { a >= b
引用此 link它说 Fuzzy Like This(也是 Fuzzy Like This 查询)将在 ES 版本 > 1.6 中弃用,并在版本 2 中完全删除。我正在使用 Elasticsearch
我一直在尝试使用 American Fuzzy Lop,但我无法使用像这样的简单示例来实现它: #include #include int main(int argc, char * argv[]
我是一名优秀的程序员,十分优秀!