/** * Toggle artist/studio recommendation * * @return View */ public function recommend(Request $request) { $res['success'] = false; $res['recommendCount'] = 0; $user = Auth::user(); $whom = User::find($request->input('id')); if ($whom) { $isAlreadyRecommended = Recommend::where('user_id', $whom->id)->where('recommended_by', $user->id)->first(); if ($isAlreadyRecommended) { $isAlreadyRecommended->delete(); $res['success'] = true; $res['message'] = 'Unrecommended'; } else { $recommend = new Recommend(); $recommend->user_id = $whom->id; $recommend->recommended_by = $user->id; $recommend->save(); $res['success'] = true; $res['message'] = 'Recommended'; } } $res['recommendCount'] = Recommend::where('user_id', $whom->id)->count(); return $res; }
public function recommend_analyze() { $data = Input::all(); spl_autoload_register(function ($class_name) { $file_name = str_replace('\\', '/', $class_name); $file_name = str_replace('_', '/', $file_name); $file = dirname(__FILE__) . "/src/{$file_name}.php"; if (is_file($file)) { include $file; } }); $tokenizer = new Recommend(); $classifier = new Classifier($tokenizer); $train = Recommend::all(); // training file here foreach ($train as $key) { # code... $classifier->train($key['label'], $key['context']); } // $classifier->train('Hot', 'It is so hot'); // $classifier->train('Cold', 'it is very cold'); $groups = $classifier->classify($data['content']); $rec = classification::find($groups); $content = $data['content']; $nav = new category(); $menu_top = $nav->menu_top($nav->all()->toArray()); $pro = new Product(); $product = $pro->getRecommend($groups); return view('frontend.pages.result', array('groups' => $groups, 'content' => $content, 'menu_top' => $menu_top, 'rec' => $rec, 'product' => $product)); //return $groups; }