Esempio n. 1
0
def home(request):
    q = '''match(m:Movie) where m.release_date contains "''' + str(
        currdate) + '''" return count(m)'''
    n = pd.DataFrame(driver.session().run(q))[0][0]
    print(n)
    if n > 0 and n <= 6:
        b = 0
    elif n > 6:
        a = range(0, n - 6)
        b = random.choice(a)
    else:
        c = 1000
        a = range(0, c - 6)
        b = random.choice(a)
    query = '''match(m:Movie) where m.release_date contains "''' + str(
        currdate) + '''" with m skip ''' + str(b) + ''' limit 6
match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d) with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster'''
    movie_frame = pd.DataFrame(driver.session().run(query))
    movie_frame.columns = [
        'id', 'imdb_id', 'Title', 'Actors', 'Directors', 'overview', 'Poster'
    ]
    movie_list = list(movie_frame.head(6).apply(set_movie, axis=1))
    print(movie_list)
    title = "Top 5 movies"
    search_type, search_key = 'All', ''
    if request.method == 'POST':
        search_type = request.POST['search_type']
        search_key = request.POST['search_key']
        if len(search_key) > 0:
            title = 'Search results for {} in category {}'.format(
                search_key, search_type)
            movie_list = search_movies(search_type, search_key)

        context = {
            'movies': movie_list,
            'title': title,
            'search_key': search_key,
            'search_type': search_type,
            'radios': 'All Title Actors Directors'.split()
        }
        return render(request, 'neo4j/search.html', context)
    #print("Showing {} results".format(len(movie_list)))
    context = {
        'movies': movie_list,
        'title': title,
        'search_key': search_key,
        'search_type': search_type,
        'radios': 'All Title Actors Directors'.split()
    }
    #print(context)
    return render(request, 'neo4j/index.html', context)
Esempio n. 2
0
def recommendation_algo_three(key):

    query = '''MATCH (m:Movie)
    WHERE m.imdb_id = "''' + str(key) + '''"
    WITH m, split(m.rec_item, ' | ') AS wsa
  
    unwind wsa[1..] as w1
    with w1
    match(a )-[:ACTED_IN]->(rec:Movie{title: w1})<-[:DIRECTED]-(d )

    with distinct rec, collect(distinct a.name) as actors, collect(distinct d.name) as directors
    WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, rec
    RETURN  toString(ID(rec)) as id, rec.imdb_id as imdb_id, rec.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, rec.overview as overview, rec.Poster as Poster limit 6'''

    #print(mask)

    movie_frame = pd.DataFrame(driver.session().run(query))
    print(
        '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
    )
    print(len(movie_frame))
    if (len(movie_frame) == 0):
        return ('Empty')
    #movie_frame = pd.DataFrame(driver.session().run(query))
    movie_frame.columns = [
        'id', 'imdb_id', 'Title', 'Actors', 'Directors', 'overview', 'Poster'
    ]
    movie_list = list(movie_frame.head(6).apply(set_movie, axis=1))
    return movie_list
Esempio n. 3
0
def detail(request, key):
    query = '''match(p1:Product)<-[:HasProduct]-(c:Category)
    where p1.ProductId = "''' + str(key) + '''"
    RETURN  toString(p1.ProductId) as id, p1.ProductName as ProductName, p1.Manufacturer as Manufacturer, p1.Style as Style, p1.Finish as Finish, c.Category as Category,p1.Price as Price, p1.poster as Poster limit 6'''

    product_frame = pd.DataFrame(driver.session().run(query))
    print('%%%%%%%')

    product_frame.columns = [
        'ProductId', 'ProductName', 'Manufacturer', 'Style', 'Finish',
        'Category', 'Price', 'Poster'
    ]
    print(product_frame)
    product_frame.index = [0]

    context = {
        'products': set_product(product_frame.loc[0]),
        'algo_one': recommendation_algo_one(key),
        'algo_two': recommendation_algo_one(key),
        'algo_three': recommendation_algo_three(key),
        'search_key': "",
        'search_type': 'All',
        'radios': 'All Product Manufacturer Category'.split()
    }

    context['PAGE_NAME'] = context['products'].productname

    return render(request, 'neo4j/detail.html', context)
Esempio n. 4
0
def recommendation_algo_one(key):
    query = '''MATCH (m:Movie) WHERE m.imdb_id = "''' + str(key) + '''"
    MATCH (m)-[:HAS_GENRE]->(g:Genre)<-[:HAS_GENRE]-(rec:Movie)

    WITH m, rec, COUNT(*) AS gs

    OPTIONAL MATCH (m)<-[:HAS_MOVIES]-(pc:productionCompany)-[: HAS_MOVIES ]->(rec)
    WITH m, rec, gs, COUNT(pc) AS PC

    OPTIONAL MATCH (m)<-[: HAS_MOVIES ]-(cn:collectionName)-[: HAS_MOVIES ]->(rec)
    WITH m, rec, gs, COUNT(cn) AS CN, PC
    with rec, (gs)+(3*PC)+(3*CN) AS score
    ORDER BY score DESC 
    match(a)-[:ACTED_IN]->(rec:Movie)<-[:DIRECTED]-(d)
    with rec, collect(distinct a.name) as actors, collect(distinct d.name) as directors
    WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, rec
    RETURN  toString(ID(rec)) as id, rec.imdb_id as imdb_id, rec.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, rec.overview as overview, rec.Poster as Poster limit 6'''

    #print(mask)

    movie_frame = pd.DataFrame(driver.session().run(query))
    print(
        '8888888888888888888888888888888888888888888888888888888888888888888888888888888888'
    )
    print(len(movie_frame))

    #movie_frame = pd.DataFrame(driver.session().run(query))
    if (len(movie_frame) == 0):
        return ('Empty')
    movie_frame.columns = [
        'id', 'imdb_id', 'Title', 'Actors', 'Directors', 'overview', 'Poster'
    ]
    movie_list = list(movie_frame.head(6).apply(set_movie, axis=1))

    return movie_list
Esempio n. 5
0
def detail(request, key):
    query = '''match(m:Movie) where m.imdb_id = "''' + str(key) + '''"
match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d) with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster'''
    movie_frame = pd.DataFrame(driver.session().run(query))
    movie_frame.columns = [
        'id', 'imdb_id', 'Title', 'Actors', 'Directors', 'overview', 'Poster'
    ]
    print(
        "#########################################################################"
    )
    print(len(movie_frame))
    print(movie_frame)
    movie_frame.index = [0]

    context = {
        'movie': set_movie(movie_frame.loc[0]),
        'algo_one': recommendation_algo_one(key),
        'algo_two': recommendation_algo_two(key),
        'algo_three': recommendation_algo_three(key),
        'search_key': "",
        'search_type': 'All',
        'radios': 'All Title Actors Directors'.split()
    }

    context['PAGE_NAME'] = context['movie'].title

    if context['algo_one'] == 'Empty' and context[
            'algo_two'] != 'Empty' and context['algo_three'] != 'Empty':
        return render(request, 'neo4j/genreerror.html', context)

    if context['algo_two'] == 'Empty' and context[
            'algo_one'] != 'Empty' and context['algo_three'] != 'Empty':
        return render(request, 'neo4j/nlperror.html', context)

    if context['algo_three'] == 'Empty' and context[
            'algo_one'] != 'Empty' and context['algo_two'] != 'Empty':
        return render(request, 'neo4j/itemerror.html', context)

    if context['algo_one'] == 'Empty' and context[
            'algo_two'] == 'Empty' and context['algo_three'] != 'Empty':
        return render(request, 'neo4j/genrenlperror.html', context)

    if context['algo_one'] == 'Empty' and context[
            'algo_two'] != 'Empty' and context['algo_three'] == 'Empty':
        return render(request, 'neo4j/genreitemerror.html', context)

    if context['algo_one'] != 'Empty' and context[
            'algo_two'] == 'Empty' and context['algo_three'] == 'Empty':
        return render(request, 'neo4j/nlpitemerror.html', context)

    if context['algo_one'] == 'Empty' and context[
            'algo_two'] == 'Empty' and context['algo_three'] == 'Empty':
        return render(request, 'neo4j/all.html', context)

    return render(request, 'neo4j/detail.html', context)
Esempio n. 6
0
def search_products(search_type, search_key):

    if search_type == 'All':
        query = '''match(p:Product)<-[:HasProduct]-(c)
        where toLower(p.ProductName) contains toLower("''' + str(
            search_key
        ) + '''") or toLower(p.Manufacturer) contains toLower("''' + str(
            search_key
        ) + '''") or toLower(p.Style) contains toLower("''' + str(
            search_key
        ) + '''") or toLower(p.Finish) contains toLower("''' + str(
            search_key
        ) + '''") or toLower(c.Category) contains toLower("''' + str(
            search_key) + '''")
        RETURN  toString(p.ProductId) as id, p.ProductName as ProductName, p.Manufacturer as Manufacturer, p.Style as Style, p.Finish as Finish, c.Category as Category, p.Price as Price, p.poster as Poster limit 12'''

    elif search_type == 'Product':
        query = '''match(p:Product)<-[:HasProduct]-(c)
        where toLower(p.ProductName) contains toLower("''' + str(
            search_key) + '''") 
        RETURN  toString(p.ProductId) as id, p.ProductName as ProductName, p.Manufacturer as Manufacturer, p.Style as Style, p.Finish as Finish, c.Category as Category, p.Price as Price, p.poster as Poster limit 12'''

    elif search_type == 'Manufacturer':
        query = '''match(p:Product)<-[:HasProduct]-(c)
        where toLower(p.Manufacturer) contains toLower("''' + str(
            search_key) + '''") 
        RETURN  toString(p.ProductId) as id, p.ProductName as ProductName, p.Manufacturer as Manufacturer, p.Style as Style, p.Finish as Finish, c.Category as Category, p.Price as Price, p.poster as Poster limit 12'''

    elif search_type == 'Category':
        query = '''match(p:Product)<-[:HasProduct]-(c)
        where toLower(c.Category) contains toLower("''' + str(
            search_key) + '''")
        RETURN  toString(p.ProductId) as id, p.ProductName as ProductName, p.Manufacturer as Manufacturer, p.Style as Style, p.Finish as Finish, c.Category as Category, p.Price as Price, p.poster as Poster limit 12'''

    try:
        product_frame = pd.DataFrame(driver.session().run(query))
        print('%%%%%%%')

        product_frame.columns = [
            'ProductId', 'ProductName', 'Manufacturer', 'Style', 'Finish',
            'Category', 'Price', 'Poster'
        ]
        print(product_frame)
        product_list = list(product_frame.apply(set_product, axis=1))

        return product_list

    except:
        return []
Esempio n. 7
0
def home(request):

    query = '''match(h:CategoryRollUp)
    with collect(h) as v
    unwind v as c
    match(c)-[:HasCategory]->(d)-[:HasProduct]->(p)
    with c,collect(p) as k
    with c,k
    unwind k[..1]  as l
    return c.CategoryRollUp,l.poster'''
    categoryrollup_frame = pd.DataFrame(driver.session().run(query))
    categoryrollup_frame.columns = ['CategoryRollUp', 'Poster']
    categoryrollup_list = list(
        categoryrollup_frame.head(10).apply(set_categoryrollup, axis=1))
    #print(categoryrollup_frame)
    title = "Top 5 products"
    search_type, search_key = 'All', ''
    if request.method == 'POST':
        search_type = request.POST['search_type']
        search_key = request.POST['search_key']
        if len(search_key) > 0:
            title = 'Search results for {} in category {}'.format(
                search_key, search_type)
            product_list = search_products(search_type, search_key)
        print('######################################################')
        print(product_list)
        context = {
            'products': product_list,
            'title': title,
            'search_key': search_key,
            'search_type': search_type,
            'radios': 'All Product Manufacturer Category'.split()
        }
        return render(request, 'neo4j/search.html', context)
    #print("Showing {} results".format(len(movie_list)))
    context = {
        'categoryrollup': categoryrollup_list,
        'title': title,
        'search_key': search_key,
        'search_type': search_type,
        'radios': 'All Product Manufacturer Category'.split()
    }
    #print(context)
    return render(request, 'neo4j/index.html', context)
Esempio n. 8
0
def recommendation_algo_one(key):
    query = '''MATCH (p:Product)
        where p.ProductId ="''' + str(key) + '''"
        WITH p
        match(p1:Product{SubCategory:p.SubCategory})<-[:HasProduct]-(c:Category) where p<>p1
        with p,p1,c,apoc.text.sorensenDiceSimilarity(p.ProductName, p1.ProductName) as sim order  by sim desc
        RETURN  toString(p1.ProductId) as id, p1.ProductName as ProductName, p1.Manufacturer as Manufacturer, p1.Style as Style, p1.Finish as Finish, c.Category as Category,p1.Price as Price, p1.poster as Poster limit 6'''

    product_frame = pd.DataFrame(driver.session().run(query))

    if (len(product_frame) == 0):
        return ('Empty')

    product_frame.columns = [
        'ProductId', 'ProductName', 'Manufacturer', 'Style', 'Finish',
        'Category', 'Price', 'Poster'
    ]
    product_list = list(product_frame.apply(set_product, axis=1))
    return product_list
Esempio n. 9
0
def recommendation_algo_three(key):
    query = '''MATCH (p:Product)
        where p.ProductId ="''' + str(key) + '''"
        WITH p
        match(u)-[x:InteractsWith]->(p) where x.EventScore >= 0.25
with collect (u) as s
unwind s as d
match (d)-[x:InteractsWith]->(p1)<-[:HasProduct]-(c) where x.EventScore >.5
with c, collect (distinct(p1)) as d 
unwind  d[..6] as p1
return toString(p1.ProductId) as id, p1.ProductName as ProductName, p1.Manufacturer as Manufacturer, p1.Style as Style, p1.Finish as Finish, c.Category as Category,p1.Price as Price, p1.poster as Poster limit 6'''
    product_frame = pd.DataFrame(driver.session().run(query))

    if (len(product_frame) == 0):
        return ('Empty')

    product_frame.columns = [
        'ProductId', 'ProductName', 'Manufacturer', 'Style', 'Finish',
        'Category', 'Price', 'Poster'
    ]
    product_list = list(product_frame.apply(set_product, axis=1))
    return product_list
Esempio n. 10
0
def recommendation_algo_two(key):
    query = ''' MATCH (p1:Product)
	where p1.ProductId ="''' + str(key) + '''"
	MATCH (c:Customer)-[x:InteractsWith]->(p1)
	where x.Event = 'PURCHASE'
	with collect(c.CustomerId) as ws, p1
	unwind ws as ws1
	MATCH (c1:Customer{CustomerId: ws1})-[x:InteractsWith]->(p:Product)
	where x.Event = 'PURCHASE'
	with collect(distinct p) as wsa,  p1
	MATCH (c2)-[x:InteractsWith]->(p:Product{ProductId: p1.ProductId})
	where x.Event = 'PRODUCT VIEW' or x.Event  = 'CART ITEM ADDITION' or x.Event = 'WISHLIST'
	with collect(distinct id(c2)) as targetviews, wsa, p1
	unwind wsa as w2
	MATCH (c2)-[x:InteractsWith]->(p:Product{ProductId: w2.ProductId})<-[:HasProduct]-(cat)
	where x.Event = 'PRODUCT VIEW' or x.Event  = 'CART ITEM ADDITION' or x.Event = 'WISHLIST'
	with collect(distinct id(c2)) as listitemviews, w2, targetviews, p1, cat
	with p1 , w2, cat, gds.alpha.similarity.jaccard(targetviews, listitemviews) AS similarity
	where similarity<1 and similarity>=0.01
	with p1,w2, similarity, cat
	ORDER BY similarity DESC
	with p1, collect([w2,similarity, cat])[..6] as products
	unwind products as recommendation
	return toString(recommendation[0].ProductId) as ProductId, recommendation[0].ProductName as ProductName, recommendation[0].Manufacturer as Manufacturer, recommendation[0].Style as Style, recommendation[0].Finish as Finish,recommendation[2].Category as Category, recommendation[0].Price as Price, recommendation[0].poster as Poster'''

    product_frame = pd.DataFrame(driver.session().run(query))
    print(product_frame)

    if (len(product_frame) == 0):
        return ('Empty')

    product_frame.columns = [
        'ProductId', 'ProductName', 'Manufacturer', 'Style', 'Finish',
        'Category', 'Price', 'Poster'
    ]
    product_list = list(product_frame.apply(set_product, axis=1))
    return product_list
Esempio n. 11
0
def search_movies(search_type, search_key):
    '''print("Got params", search_type, search_key)
    cols = 'Title Actors Directors overview'.split()
    if search_type != 'All':
        mask = movie_frame[search_type].apply(lambda x: compare(search_key, x))
    else:
        mask = False
        for search_type in cols:
            mask = mask | np.array(movie_frame[search_type].apply(lambda x: compare(search_key, x)))
    
    movie_list = movie_frame[mask].apply(set_movie, axis=1)'''
    if search_type == 'All':
        query = '''match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d)
        where m.title contains "''' + str(
            search_key) + '''" or m.overview contains "''' + str(
                search_key) + '''" or a.name contains "''' + str(
                    search_key
                ) + '''" or d.name contains "''' + str(search_key) + '''" 
        or toLower(m.title) contains toLower("''' + str(
                    search_key
                ) + '''") or toLower(m.overview) contains toLower("''' + str(
                    search_key
                ) + '''") or toLower(a.name) contains toLower("''' + str(
                    search_key
                ) + '''") or toLower(d.name) contains toLower("''' + str(
                    search_key) + '''")
        with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
        WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
        RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster limit 6'''

    elif search_type == 'Title':
        query = '''match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d)
        where m.title contains "''' + str(
            search_key) + '''" or toLower(m.title) contains toLower("''' + str(
                search_key) + '''") 
        with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
        WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
        RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster limit 6'''

    elif search_type == 'Actors':
        query = '''match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d)
        where a.name contains "''' + str(
            search_key) + '''" or toLower(a.name) contains toLower("''' + str(
                search_key) + '''") 
        with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
        WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
        RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster limit 6'''

    elif search_type == 'Directors':
        query = '''match(a)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d)
        where d.name contains "''' + str(
            search_key) + '''" or toLower(d.name) contains toLower("''' + str(
                search_key) + '''") 
        with m, collect(distinct a.name) as actors, collect(distinct d.name) as directors
        WITH REDUCE(mergedString = "",word IN actors | mergedString+word+',') as actorsString, REDUCE(mergedString = "",word IN directors | mergedString+word+',') as directorsString, m
        RETURN  toString(ID(m)) as id, m.imdb_id as imdb_id, m.title as Title, LEFT(actorsString,SIZE(actorsString)-1) as Actors, LEFT(directorsString,SIZE(directorsString)-1) as Directors, m.overview as overview, m.Poster as Poster limit 6'''

    try:
        movie_frame = pd.DataFrame(driver.session().run(query))
        movie_frame.columns = [
            'id', 'imdb_id', 'Title', 'Actors', 'Directors', 'overview',
            'Poster'
        ]
        movie_list = list(movie_frame.head(6).apply(set_movie, axis=1))

        print(movie_list)
        #print(mask)
        return movie_list
        #[:6] if len(movie_list) > 6 else movie_list
    except:
        return []