/** * Gives back the relevant node based on the given radius * * @param position starting point to calculate recommendation * @param radius defines how many levels above start position should be incorporated */ public INode collectNode(INode position, int radius) { INode relevantNode = null; // Going one level up if radius parameter stills allows it if (radius > 0) { if (!position.isRoot()) { INode parent = position.getParent(); relevantNode = collectNode(parent, radius - 1); } else { relevantNode = position; } } else { relevantNode = position; } return relevantNode; }
/** * Collect ratings of all content given by the input node * * @param position this is the starting point for collecting * @param inputNodeID this node defines the content that needs to be collected */ public Map<Integer, IAttribute> collectRatings( INode position, INode testNode, Map<Integer, IAttribute> contentRatings) { // Create Map for content of test user with empty values if not existing if (contentRatings == null) { contentRatings = new HashMap<Integer, IAttribute>(); // DatasetID, AttributeData Set<INode> testContentKeys = testNode.getAttributeKeys(); for (INode testContentKey : testContentKeys) { contentRatings.put((int) testContentKey.getDatasetId(), null); } } // Look for content nodes on the list and add it to collected ratings map Set<INode> posContentKeys = position.getAttributeKeys(); Map<Integer, IAttribute> posContentMap = new HashMap<Integer, IAttribute>(); for (INode posContentKey : posContentKeys) { // Find Dataset ID of Content Node -> FIXME: very inefficient int contentDatasetID = 0; for (Iterator<Entry<Integer, INode>> iter = leavesMapC.entrySet().iterator(); iter.hasNext(); ) { Map.Entry<Integer, INode> e = (Map.Entry<Integer, INode>) iter.next(); if (posContentKey.getId() == e.getValue().getId()) { contentDatasetID = e.getKey(); } } posContentMap.put(contentDatasetID, position.getAttributeValue(posContentKey)); } for (Entry<Integer, IAttribute> contentRating : contentRatings.entrySet()) { int datasetID = contentRating.getKey(); IAttribute rating = contentRating.getValue(); // Check if value still needs to be found if (rating == null) { try { IAttribute contentAttributes = posContentMap.get(datasetID); contentRatings.put(datasetID, posContentMap.get(datasetID)); } catch (Exception e) { System.out.println(e); } } } // Check if all movies were found if (contentRatings.containsValue(null) != true) { return contentRatings; } else { // Go one level up if possible if (position.getParent() != null) { contentRatings = collectRatings(position.getParent(), testNode, contentRatings); if (contentRatings != null) { return contentRatings; } } else { return contentRatings; } } return null; }