How to check if two Strings are approximately equal?

前端 未结 6 2007
醉酒成梦
醉酒成梦 2021-02-04 05:30

I\'m making a chat responder for a game and i want know if there is a way you can compare two strings and see if they are approximatley equal to each other for example:

相关标签:
6条回答
  • 2021-02-04 05:45

    I found a few projects that do text to phonemes translations, don't know which one is best

    • http://mary.dfki.de/
    • http://www2.eng.cam.ac.uk/~tpl/asp/source/Phoneme.java
    • http://java.dzone.com/announcements/announcing-phonemic-10
    0 讨论(0)
  • 2021-02-04 05:47

    If you want to find similar word beginnings, you can use a stemmer. Stemmers reduce words to a common beginning. The most known algorithm if the Port Stemmer (http://tartarus.org/~martin/PorterStemmer).

    Levenshtein, as pointed above, is great, but computational heavy for distances greater than one or two.

    0 讨论(0)
  • 2021-02-04 05:53

    You can use Levenshtein distance.

    0 讨论(0)
  • 2021-02-04 05:56

    Perhaps what you need is a large dictionary for similar words and common spelling mistakes, for which you would use for each word to "translate" to one single entry or key.

    This would be useful for custom words, so you could add "str" in the same key as "strength".

    However, you could also make a few automated methods, i.e. when your word isn't found in the dictionary, to loop recursively for 1 letter difference (either missing or replaced) and can recurse into deeper levels, i.e. 2 missing letters etc.

    0 讨论(0)
  • 2021-02-04 06:04

    I believe you should use one of Edit distance algorithms to solve your problem. Here is for example Levenstein distance algorithm implementation in java. You may use it to compare words in the sentences and if sum of their edit distances would be less than for example 10% of sentence length consider them equals.

    0 讨论(0)
  • 2021-02-04 06:08

    See this question and answer: Getting the closest string match

    Using some heuristics and the Levenshtein distance algorithm, you can compute the similarity of two strings and take a guess at whether they're equal.

    enter image description here

    Your only option other than that would be a dictionary of accepted words similar to the one you're looking for.

    0 讨论(0)
提交回复
热议问题