예제 #1
0
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")
예제 #2
0
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
예제 #3
0
def getItemDetail():

    try:
        print("Enter ItemId ")
        itemId = int(input())
        paintDict("Item Info", cbr.getItemDetail(itemId))
    except:
        print("Invalid ItemId")
        return
예제 #4
0
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
예제 #5
0
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