Created
November 3, 2018 02:47
-
-
Save infinite-Joy/1fd0648d222070122137f87a9b735d6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def neo4j_most_similar(model, key): | |
with driver.session() as session: | |
find_movie_query = "MATCH (m:MovieId {name: '%s'}) return id(m)" % key | |
result = session.run(find_movie_query) | |
for r in result: | |
similar_movies = model.most_similar(str(r.value())) | |
for s_movie in similar_movies: | |
find_movie_query = "MATCH (m:MovieId) where id(m) = %s return m.name" % s_movie[0] | |
similar_movie_names = session.run(find_movie_query) | |
for sm in similar_movie_names: | |
# print the movie name with the cosine similarity | |
print(sm.value(), s_movie[1]) | |
neo4j_most_similar(model, 'Money Train (1995)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment