[ 'keywords' => [ '有效', '好用', '好了', '治愈', '见效', '不错', '管用', '有用','感恩', '灵验', '缓解', '痊愈', '见效', '神效', '推荐', '感谢', '好了', '管用', '有效果', '有效果', '奏效', '改善', '见效快', '神奇', '有效', '有效果', '有效果', '有效果', '有效果', '有效果' ], 'patterns' => [ '/(喝|吃|用)了?\s*\d+\s*次?[就]?(好|痊愈|缓解|不咳|不痛)了/u', '/(效果|结果)\s*(非常|很)?\s*(好|明显|不错|显著|惊人)/u', '/(尝试|试了|用了)\s*\d+\s*[天个]?\s*(就)?(好|痊愈|缓解|见效)/u', '/(咳嗽|咳|痛|疼|症状)\s*(明显)?\s*(减轻|缓解|消失|好了)/u', '/(感谢|谢谢)\s*(分享|博主|张医生|宝旬)/u' ] ], 'negative' => [ 'keywords' => [ '无效', '没用', '不好', '没效果', '不行', '不见效', '没好转', '加重', '恶化', '白费', '失望', '避雷', '没用', '没效果', '无效果', '无改善', '没作用', '不灵', '骗人', '忽悠', '上当' ], 'patterns' => [ '/(还是|依然|仍旧|仍然)\s*(咳|难受|痛|疼|没效果)/u', '/(一点|完全|根本|丝毫)\s*没(效果|用|好转|作用|改善)/u', '/(不仅|不但)\s*没(好|改善).*(反而|而且)\s*(加重|恶化)/u', '/(浪费|白费|白忙|白折腾)\s*(时间|精力)/u', '/(失望|后悔|上当|骗人|忽悠|别信)\s*(了|吧|!)/u' ] ] ]; public function __construct() {} private function preprocess($comment) { $comment = preg_replace('/\s+/u', ' ', $comment); $comment = preg_replace('/[^\p{Han}\p{P}\w\s]/u', '', $comment); return trim($comment); } public function analyze($comment) { $comment = $this->preprocess($comment); foreach ($this->config['negative']['keywords'] as $word) { if (mb_strpos($comment, $word) !== false) return 'negative'; } foreach ($this->config['positive']['keywords'] as $word) { if (mb_strpos($comment, $word) !== false) return 'positive'; } foreach ($this->config['negative']['patterns'] as $pattern) { if (preg_match($pattern, $comment)) return 'negative'; } foreach ($this->config['positive']['patterns'] as $pattern) { if (preg_match($pattern, $comment)) return 'positive'; } return 'neutral'; } }