String matching algorithm when matching words inside two Strings?

时间:2015-12-08 19:28:17

标签: textmatching

For example, when String A has a total of 10 words and String B has total of 100 words, all words in String A are found in String B the result would be a 100% match. If half are found, it is a 50% match. What algorithm produces results like this?

1 个答案:

答案 0 :(得分:0)

我会尝试编写类似PHP的代码

wordsA = explode(' ', A);
wordsB = explode(' ', B);
match = 0;
foreach (wordsA as word) {
    if (in_array(word, wordsB)) {
        match++;
    }
}
echo (count(wordsB)/match*100.'%');