How to search for similar words

僤鯓⒐⒋嵵緔 提交于 2020-01-04 05:51:20

问题


I have a record file and I need to make a program that should help find any word into that record by typing a word into a search field. The record file contains a list of words so I need to search into that list to find any word that could be similar to my word.

I am using Delphi 2007


回答1:


Delphi 2007 should have a number of string matching routines in StrUtils that use the Soundex algorithm to find similar "sounding" words. Depending on how your file is formatted you may be able to load it into a TStringList then in the OnChange event handler of your input field call a routine that iterates through the list and performs a soundex comparison with the user's input and each entry in the list.

Look at ResemblesText, SoundexCompare, SoundexProc and SoundexSimilar. One of those should get you going.




回答2:


A Levenshtein distance algorithm can be used to calculate word differences.

The Levenshtein distance is a metric for measuring the amount of difference between two sequences (i.e. an edit distance).

There are some Pascal implementations available in the Internet, for example

Friends of Free pascal - http://fofpc.org/wunder/Levenshtein_Comparison




回答3:


Use a regular expression.

www.regular-expressions.info/delphi.html



来源:https://stackoverflow.com/questions/886835/how-to-search-for-similar-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!