/* @getRecommendations: * This method implements the Hybrid recommender system, first it finds most similar users by * checking their tastes (favorite books, musics, movies and athletes) them the next recommender * algorithm filter users based on Demographic correlation (Location, gender and age), it also features * their ratings on each product, the output will be a list with the items most appealing to the user */ @RequestMapping(value = "/recommendations", method = RequestMethod.GET) public ResponseEntity<ArrayList<Prediction>> getRecommendations(@RequestParam("id") String id) { /* Retrieve all users to cluster */ User baseUser = userRepository.findOne(id); if (baseUser != null) { List<User> users = userRepository.findAll(); /* Knowledge Correlation */ ArrayList<Neighbor> knowledgeSimilarity = ClusterUtils.getKnowledgeNeighborhood(baseUser, users); List<User> filteredUsers = new ArrayList<User>(); for (int i = 0; i <= (knowledgeSimilarity.size() - 1); i++) { filteredUsers.add(knowledgeSimilarity.get(i).getUser()); } ArrayList<Neighbor> neighborhood = ClusterUtils.getMergedCorrelations(baseUser, filteredUsers); /* Order arrayList by similar users from highest to lowest correlation */ Collections.sort(neighborhood); ArrayList<Prediction> predictions = PredictionUtils.getPredictions(baseUser, neighborhood); Collections.sort(predictions); return new ResponseEntity<>(predictions, HttpStatus.OK); } else { ArrayList<Prediction> predictions = new ArrayList<>(); return new ResponseEntity<>(predictions, HttpStatus.OK); } }
@RequestMapping(value = "/trending", method = RequestMethod.GET) public ResponseEntity<ArrayList<Trending>> getTrending() { List<User> userList = userRepository.findAll(); List<Occupation> occupationList = occupationRepository.findAll(); ArrayList<Trending> trending = ClusterUtils.getTrendingOccupations(userList, occupationList); Collections.sort(trending); return new ResponseEntity<>(trending, HttpStatus.OK); }
@RequestMapping(value = "/users", method = RequestMethod.GET) public ResponseEntity<List<User>> users() { return new ResponseEntity<>(userRepository.findAll(), HttpStatus.OK); }