@@ -0,0 +1,1673 @@
+package com.aht.recommend;%0A%0Aimport com.aht.neo4j.model.node.Item;%0Aimport com.aht.neo4j.model.node.User;%0Aimport com.aht.neo4j.model.relationship.Affinity;%0Aimport com.aht.neo4j.model.relationship.Event;%0Aimport com.aht.neo4j.model.relationship.Neighbor;%0A%0Aimport java.util.*;%0A%0A/**%0A * Created by azu on 18/04/16.%0A */%0A%0Apublic class ItemRecommender %7B%0A    public Set%3CItem%3E getTopNRecommendationsByItem(Item item, int N)%7B%0A        Set%3CItem%3E topNRecommendations = new HashSet%3CItem%3E();%0A        Set%3CAffinity%3E affinities = item.getAffinities();%0A        // Sort Affinities%0A%0A        for (Affinity affinity: affinities) %7B%0A            Item temp = affinity.getFirst();%0A            if(temp.getId() == item.getId())%7B%0A                temp = affinity.getSecond();%0A            %7D%0A            topNRecommendations.add(temp);%0A        %7D%0A        return topNRecommendations;%0A    %7D%0A%0A    public Set%3CItem%3E getTopNRecommendationsByUser(User user, int N)%7B%0A        Set%3CNeighbor%3E neighbors = user.getNeighbors();%0A        // Sort Affinities%0A%0A        Set%3CUser%3E users = new HashSet%3CUser%3E();%0A        for (Neighbor neighbor: neighbors) %7B%0A            User temp = neighbor.getFirst();%0A            if(temp.getId() == user.getId())%7B%0A                temp = neighbor.getSecond();%0A            %7D%0A            users.add(temp);%0A        %7D%0A%0A        Set%3CItem%3E topNRecommendations = new HashSet%3CItem%3E();%0A        for(User u: users)%7B%0A            // getList of items by user event sorted by value%0A            Set%3CEvent%3E events = u.getEvents();%0A            for(Event e: events)%7B%0A                Item temp = e.getItem();%0A                topNRecommendations.add(temp);%0A            %7D%0A        %7D%0A        return topNRecommendations;%0A    %7D%0A%7D%0A

Create recommendations by Item