关键词: 所有超过3个字符的单词
我想比较两个字符串之间的关键词,具体条件如下:
最后,我需要一个函数通过结果和关键词数量(所有超过3个字符的单词)来识别重复新闻。
有人知道如何编写这个程序吗?谢谢。
我想比较两个字符串之间的关键词,具体条件如下:
- 移动单词不重要 (例如1适用于此情况)
- 少于3个字符的单词不计算在内 (例如2适用于此情况)
- 将较短的句子放在str1中(按字符数计算)。(例如3适用于此情况)
- 我只想找出与str2相比,在str1中不同的单词。 (例如4适用于此情况)
str1= 'hello petter'
str2= 'petter hello'
result: 0
示例2: 不计算少于3个字符的单词
str1= 'hello !!'
str2= 'petter hello'
result: 0 // '!!' are less than 3characters and str1 is 'hello'. then result:0
或者
str1= 'hello petter how are u?'
str2= 'petter hello how are you'
result: 0 // str1 is 'hello petter how are'
示例3:变量必须被修改。
str1= 'hello petter how are you ?'
str2= 'petter hello how are you?'
// Then
str1= 'hello petter how are you?'
str2= 'petter hello how are you ?'
result:1 // 1 is for 'you' (in str1)
例子4: 在str2中,不同的单词并不重要。
str1= 'hello petter how are you?'
str2= 'petter hello how are you ?'
result: 1 // str2 is 'petter hello how are you', then 1 is for: 'you?' (in str1)
注意: str2 中的 'you' 对我来说不重要,因为它与 str1 中的任何单词都不匹配。
占位符示例:(更多信息)
str1= 'petter hello how are you pal?'
str2= 'petter hello how are... !!'
// In first str1 change with str2
str1= 'petter hello how are... !!'
str2= 'petter hello how are you pal?'
// Then remove '!!' (in str1)
str1= 'petter hello how are...'
str2= 'petter hello how are you pal?'
result: 1 // 1 for 'are...' (in str1) - ['are','you','pal?' does not matter (in str2)]
最后,我需要一个函数通过结果和关键词数量(所有超过3个字符的单词)来识别重复新闻。
$keywords_numb=7;
$result=2;
function identify_duplicate($keywords_numb,$result){
if($keywords_numb / 3 >= $result){
$Specified = 'this is a new news';
}
else $Specified = 'this is a duplicate news';
return $Specified;
}
echo $Specified;
输出:
this is a new news
有人知道如何编写这个程序吗?谢谢。