【发布时间】:2014-01-08 09:22:43
【问题描述】:
这是我尝试做的一个非常基本的例子。
我有这个字符串。
$text = 'stackoverflow is intelligent';
删除停用词后
$stopwords=array(
'is',
'the',
);
$text = preg_replace($stopwords, "", $text);`
输出:
stackoverflow 智能
用空格分解字符串后
$text = explode(" ", $text);
在数组中输出:
stackoverflow,智能
现在我有两个字了
$text[0]; // stackoverflow
$text[1]; // intelligent
在我的 sql 数据库中,我有 3 个列。第一个是单词,第二个是她的同义词,第三个是长度最短的同义词。像这样:
word synonym shortsynonym
intelligent clever smart
这是问题的难点:
第一步是检查来自字符串的words在数据库中是否有同义词
在这种情况下,我们必须检查
$text[0]; // stackoverflow
$text[1]; // intelligent
在检查两者之后,我们发现$text[0]; // stackoverflow dosent 有一个同义词,所以我们保持原样。 $text[1]; // intelligent 的结果是肯定的。
检查后我想在数据库和replace 中执行搜索,在这种情况下,单词intelligent 和她的同义词,if word 有一个shortest synonym 替换为shortest,@ 987654339@dosent这个词有同义词leave as is。
possibility1: output: 'stackoverflow is smart'
possibility2: output: 'stackoverflow is clever'
possibility3: output: 'stackoverflow is intelligent'
在这种情况下,返回后的输出将是:
output: `stackoverflow is smart`
(也许这不是一个真正的问题,但我们将不胜感激您的任何帮助。抱歉我的英语不好)
【问题讨论】:
-
那么not究竟有什么作用呢?
-
那么,您希望整个程序都能实现这一点吗?
-
我不知道如何在数据库中执行搜索。 Step1:检查一个词是否有同义词,如果没有,则保持原样。 step2:在step1检查结果为肯定后进行替换。
-
这是一个非常基本的任务。为什么不看教程?阅读此w3schools.com/php/php_mysql_intro.asp
-
像
SELECT word,synonym,shortsynonym FROM words WHERE word IN('stackoverflow','intelligent');这样简单的东西应该有望为您指明正确的方向。