【问题标题】:String matching algorithm when matching words inside two Strings?匹配两个字符串中的单词时的字符串匹配算法?
【发布时间】:2023-03-11 12:22:01
【问题描述】:

例如,当字符串 A 共有 10 个单词而字符串 B 共有 100 个单词时,字符串 A 中的所有单词都在字符串 B 中找到,结果将是 100% 匹配。如果找到一半,则为 50% 匹配。什么算法会产生这样的结果?

【问题讨论】:

标签: textmatching


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 2013-10-16
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    相关资源
    最近更新 更多