How to find similar words in two strings in c#

前端 未结 1 1734
轮回少年
轮回少年 2021-01-13 13:00

I have a string containing words that i need to match like the one below, it is constant and the other string that can be changed may contain words from this string \'s\'.

1条回答
  •  再見小時候
    2021-01-13 13:44

    What I would do is use a stemmer (such as the Porter stemmer), split the strings using a split(' ') and go through each. Compare the stemmed version of both words and then bold the ones which match.

    foreach (string t1 in term1.split(' '){
    
    foreach (string t2 in term2.split(' '){
    
    if (Stemmer.Stem(t1).equals(Stemmer.Stem(t2)){
    
    //do whatever here
    
    }
    
    }    
    
        }
    

    On the porter stemmer including source code:

    http://tartarus.org/martin/PorterStemmer/

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