简体   繁体   English

python 上没有 soundex

[英]no soundex on python

I use the sqlite3 librairy on python to interact with a.db file.我使用 python 上的 sqlite3 库与 a.db 文件进行交互。 With this request:有了这个要求:

SELECT * FROM LesFilms F JOIN LesRealisateurs R ON (F.film_id=R.film_id) WHERE realisateur="Tim Burtyn" or soundex("Tim Burtyn")=soundex(R.realisateur) or realisateur like"T%m Burtyn" or realisateur like"Tim B%rtyn" or realisateur like"Tim Burt%n";

I got this error:我收到了这个错误:

sqlite3.OperationalError: no such function: soundex

Do someone already face this problem?有人已经面临这个问题吗? I share the whole request in case, I'm a total beginner.我分享整个请求以防万一,我是一个初学者。

Thank you,谢谢,

Elias埃利亚斯

I think you are out of luck, as you have probably gathered from the comments.我认为您不走运,正如您可能从评论中收集到的那样。 The Python standard library module sqlite3 generally provides an up-to-date version of sqlite. Python 标准库模块sqlite3一般提供最新版本的 sqlite。

  • In Python 3.9 it is 3.32.3 from June 2020.在 Python 3.9 中,从 2020 年 6 月开始为 3.32.3。
  • In Python 3.8 it is 3.31.1 from January 2020.在 Python 3.8 中,它是 2020 年 1 月的 3.31.1。
  • In Python 3.7 and Python 2.7.17 it is 3.28.0 from April 2019.在 Python 3.7 和 Python 2.7.17 中,自 2019 年 4 月起为 3.28.0。

But the Python sqlite3 library does not provide optional sqlite features that come switched off by default.但是 Python sqlite3提供默认关闭的可选 sqlite 功能。 This includes the soundex function.这包括soundex function。 I can't recommend that you try building your own version of the Python standard library module with the option switched on.我不建议您在打开选项的情况下尝试构建自己的 Python 标准库模块版本。 That sort of thing is best left to Python implementers.这种事情最好留给 Python 的实施者。

As an alternative you might try the levenshtein module: pip install python-Levenshtein or the metaphone module: pip install Metaphone .作为替代方案,您可以尝试使用levenshtein模块: pip install python-Levenshteinmetaphone模块: pip install Metaphone

To use either you would need to fetch more records from the database than you really want, for example where realisateur like "T%" and then discard the mismatches in Python code rather than in the where clause.要使用其中任何一个,您需要从数据库中获取比您真正想要的更多的记录,例如where realisateur like "T%" ,然后丢弃 Python 代码而不是where子句中的不匹配。

This is not as bad as it sounds, and may have benefits.这并不像听起来那么糟糕,并且可能有好处。 Soundex was developed in the early 20th century and so it was intended for people to be able to compute it quickly by hand. Soundex 是在 20 世纪初开发的,因此它旨在让人们能够手动快速计算它。 It has significant deficiencies, as shown by the many attempts in the subsequent 100 years to improve it.它有很大的缺陷,正如随后 100 年来对其进行改进的许多尝试所表明的那样。 The primary reason for its popularity is because it is provided by many SQL implementations, not because it is particularly good.它受欢迎的主要原因是它由许多 SQL 实现提供,而不是因为它特别好。

load your data into a dataframe then use fuzzywuzzy to find similar string words将您的数据加载到 dataframe 然后使用fuzzywuzzy 查找相似的字符串单词

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM