def addRating(): print("Enter userId,bookId,rating seperated by spaces") inps = list(map(int, input().split())) try: cbr.getUserDetail(inps[0]) cbr.getItemDetail(inps[1]) except: print("Invalid userId or itemId") return try: cbr.addRating(inps[0], inps[1], inps[2]) except: print("Mismatch in no. of input values")
def searchForItems(searchTerm, userId, attributes=[ 'title', 'author', 'pub-year', 'publisher', 'category', 'description' ]): hybridItems = getHybridSimilarItemsForAUser(userId, 1000) hybridItemsExtended = [] for hybridItem in hybridItems: id, simScore = hybridItem[0], hybridItem[1] item = cbr.getItemDetail(id) text = "" for attribute in attributes: text += str(item[attribute]) text = text.lower() searchScore = getScoreForText(text, searchTerm) hybridItemsExtended.append((id, searchScore, simScore)) hybridItemsExtended.sort(key=lambda x: (x[1], x[2]), reverse=True) print(hybridItemsExtended[:20]) return hybridItemsExtended
def getItemDetail(): try: print("Enter ItemId ") itemId = int(input()) paintDict("Item Info", cbr.getItemDetail(itemId)) except: print("Invalid ItemId") return
def processQueryByItemId(): print("Enter ItemId ") try: itemId = int(input()) paintDict("Item Info", cbr.getItemDetail(itemId)) CBRItems = getCBRSimilarItemsForAItem(itemId) CFRItems = getCFRSimilarItemsForAItem(itemId) HybridItems = getHybridSimilarItemsForAItem(itemId) #computeMetrics(CBRItems,CFRItems,HybridItems,["category","author"]) paint("CBR Items", CBRItems, printableMatterIndex=1) paint("CFR Items", CFRItems) paint("Hybrid Items", HybridItems) except: print("Invalid ItemId") return
def getVector(Items, Attributes, title): vector = {} for itemId, score in Items: try: item = cbr.getItemDetail(itemId) except: continue for attribute in Attributes: entity = item[attribute] if entity not in vector: vector[entity] = 0 vector[entity] += 1 print() printFocusPoints(vector, title) return vector