difflib中的get_close_matches()有多模糊? [英] How fuzzy is get_close_matches() in difflib?

查看:788
本文介绍了difflib中的get_close_matches()有多模糊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道difflib中的get_close_matches()是什么。什么是神奇的?b $ b?为获得比赛我需要多么模糊?

解决方案

2006年11月16日星期四16:40:49 -0800,John Henry写道:


我只是想知道difflib中的get_close_matches()是什么。什么是神奇的?b $ b?为了获得匹配,我需要多么模糊?



为什么不试试看?


>>来自difflib import get_close_matches
get_close_matches(" appel",[" ape"," apple"," peach"," puppy"])



[''apple'',''ape'']

< blockquote class =post_quotes>


>> import keyword as _keyword
get_close_matches(" wheel",_ keyword.kwlist)



[''while'']


>> get_close_matches(" apple",_ keyword.kwlist)



[]


>> get_close_matches(" accept",_ keyword.kwlist)



[''除了'']

这些例子,顺便说一下,来自这里:


>> help(get_close_matches)



-

史蒂文


我确实尝试了它们,我印象深刻。它帮助我找到了很多有用的

信息。我只是想了解什么是匹配。

Steven D''Aprano写道:


On Thu ,2006年11月16日16:40:49 -0800,John Henry写道:


我只是想知道difflib中的get_close_matches()是什么。什么是神奇的?b $ b?为了获得匹配,我需要多么模糊?




为什么不试试看?


>来自difflib import get_close_matches
get_close_matches(" appel",[" ape"," apple"," peach"," puppy"])



[''apple'',''ape'']


>导入关键字为_keyword
get_close_matches(" wheel",_ keyword.kwlist)



[''while'']


> get_close_matches(" apple",_ keyword.kwlist)



[]


> get_close_matches(" accept",_ keyword.kwlist)



[''除了'']


这个例子,顺便说一下,来自这里:


> help(get_close_matches)




-

Steven


On Thu,2006年11月16日20:19:50 -0800,John Henry写道:


我确实试过了,给我留下了深刻的印象。它帮助我找到了很多有用的

信息。我只是想了解什么构成了匹配。



源代码有很多注释,但是他们没有解释基本的

算法(至少在difflib中没有。 py提供Python 2.3)。


没有单一的diff算法,但我相信基本的想法是

寻找插入和/或删除字符串。如果你想要更多

的详细信息,请谷歌diff。一旦你有一个差异列表,最接近的

匹配是差异最小的搜索字符串。


至于了解构成匹配的内容,我真的不能做任何更好的建议,而不仅仅是用交互式的

Python shell尝试很多例子。


-

Steven D''Aprano


I am just wondering what''s with get_close_matches() in difflib. What''s
the magic? How fuzzy do I need to get in order to get a match?

解决方案

On Thu, 16 Nov 2006 16:40:49 -0800, John Henry wrote:

I am just wondering what''s with get_close_matches() in difflib. What''s
the magic? How fuzzy do I need to get in order to get a match?


Why don''t you try it and see?

>>from difflib import get_close_matches
get_close_matches("appel", ["ape", "apple", "peach", "puppy"])

[''apple'', ''ape'']

>>import keyword as _keyword
get_close_matches("wheel", _keyword.kwlist)

[''while'']

>>get_close_matches("apple", _keyword.kwlist)

[]

>>get_close_matches("accept", _keyword.kwlist)

[''except'']
Those example, by the way, come from here:

>>help(get_close_matches)


--
Steven


I did try them and I am impressed. It helped me found a lot of useful
info. I just want to get a feel as to what constitutes a "match".
Steven D''Aprano wrote:

On Thu, 16 Nov 2006 16:40:49 -0800, John Henry wrote:

I am just wondering what''s with get_close_matches() in difflib. What''s
the magic? How fuzzy do I need to get in order to get a match?



Why don''t you try it and see?

>from difflib import get_close_matches
get_close_matches("appel", ["ape", "apple", "peach", "puppy"])

[''apple'', ''ape'']

>import keyword as _keyword
get_close_matches("wheel", _keyword.kwlist)

[''while'']

>get_close_matches("apple", _keyword.kwlist)

[]

>get_close_matches("accept", _keyword.kwlist)

[''except'']
Those example, by the way, come from here:

>help(get_close_matches)



--
Steven


On Thu, 16 Nov 2006 20:19:50 -0800, John Henry wrote:

I did try them and I am impressed. It helped me found a lot of useful
info. I just want to get a feel as to what constitutes a "match".

The source code has lots of comments, but they don''t explain the basic
algorithm (at least not in the difflib.py supplied with Python 2.3).

There is no single diff algorithm, but I believe that the basic idea is to
look for insertions and/or deletions of strings. If you want more
detail, google "diff". Once you have a list of differences, the closest
match is the search string with the fewest differences.

As for getting a feel of what constitutes a match, I really can''t make any
better suggestion than just try lots of examples with the interactive
Python shell.

--
Steven D''Aprano


这篇关于difflib中的get_close_matches()有多模糊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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