这是一个非常基本的例子,即时消息试图做的事情。用字符串中的同义词代替单词
我有这个字符串。
$text = 'stackoverflow is intelligent';
移除停止词
后$stopwords=array(
'is',
'the',
);
$text = preg_replace($stopwords, "", $text);`
输出:
计算器智能
后通过空间
爆炸字符串$text = explode(" ", $text);
输出在阵列:
计算器,智能
现在我有2个字
$text[0]; // stackoverflow
$text[1]; // intelligent
在我的sql数据库中,我有3个colums。第一个是单词,第二个是她的同义词,第三个是单词leng的最短同义词。像这样:
word synonym shortsynonym
intelligent clever smart
这是问题的最困难的部分:
第一步是检查从字符串words
在数据库 的代名词在这种情况下,我们必须检查
$text[0]; // stackoverflow
$text[1]; // intelligent
检查都WE R之后因为$text[0]; // stackoverflow
dosent有一个同义词,所以我们按原样离开。并且$text[1]; // intelligent
的结果为正值。
检查后,我想在这种情况下与她的同义词执行数据库和replace
搜索词intelligent
,并if
的word
有shortest synonym
与shortest
,if
字dosent有一个同义词保留原样更换。
possibility1: output: 'stackoverflow is smart'
possibility2: output: 'stackoverflow is clever'
possibility3: output: 'stackoverflow is intelligent'
在这种情况下
返回输出将是后:
output: `stackoverflow is smart`
(也许这是不是一个真正的问题要问在这里,但你从将不胜感激任何帮助。和对不起我的英文不好)
那么究竟是什么*不*工作? –
那么,你想让整个程序达到这个目标? –
我不知道如何在数据库中执行搜索。第一步:检查一个词是否有同义词,如果不是,则按原样保留。步骤2:在步骤1中检查并且结果为肯定后,进行替换。 – mwweb