cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Python stock driver and assigning Python lists as attributes

lytellie
Node Link

I'm running a neo4j causal cluster on Google Cloud and feeding it large volumes of data from my work server on DigitalOcean. Right now, I'm doing some analysis of a database using the Python TextBlob library, which does natural language parsing of data. I'm trying to iterate through a list of video game reviews, one at a time, like so:

query="""match (n:review)
where n.game_name = "The Last of Us Part II" and not exists(n.sentiment_analyzed)
return n.review_text
limit 1"""
conn = Neo4jConnection("bolt+s://xxxxxx", "username", neo4j_password)
output = conn.query(query)

The idea is that I pull the review text into a variable and then do TextBlob analysis on it; this works, but the problem is that Textblob returns Python lists, not variables, and outside of the sentiment analysis function they are separated by a lot of commas, which seems to kill off my query syntax. This is the query syntax which I've been using to try to assign these properties and then iterate to the next review:

query=F"""match (n:review)
where n.game_name = "The Last of Us Part II" and not exists(n.sentiment_analyzed)
set n.pos_tags = {pos_tags}
set n.pos_noun_phrases = {pos_noun_phrases}
set n.pos_sentence_polarity = {pos_sentence_polarity}
set n.sentiment_analyzed = 1
return n.review_text
limit 1
"""
conn = Neo4jConnection("bolt+s://xxxxx", username", neo4j_password)
output = conn.query(query)
print(output)

The error I get from doing this is

Query failed: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input ',': expected whitespace, '.', node labels, '[', '^', '', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or ')' (line 3, column 33 (offset: 135))
" set n.pos_tags = [('trailer', 'NN'), ('was', 'VBD'), ('like', 'IN'), ('a', 'DT'), ('movie', 'NN'), ('same', 'JJ'), ('as', 'IN'), ('watch', 'NN'), ('dogs', 'NNS'), ('one', 'CD'), ('fiasco', 'NN'), ('story', 'NN'), ('was', 'VBD'), ('
', 'JJ'), ('', 'NNP'), ('', 'NNP'), ('*', 'NNP'), ('we', 'PRP'), ('pay', 'VBP'), ('to', 'TO'), ('enjoy', 'VB'), ('the', 'DT'), ('game', 'NN'), ('not', 'RB'), ('to', 'TO'), ('torture', 'VB'), ('ourselves', 'PRP'), ('by', 'IN'), ('the', 'DT'), ('horrible', 'JJ'), ('gameplay', 'NN'), ('every', 'DT'), ('puzzle', 'NN'), ('was', 'VBD'), ('the', 'DT'), ('same', 'JJ'), ('even', 'RB'), ('the', 'DT'), ('character', 'NN'), ('you', 'PRP'), ('control', 'VBP'), ('says', 'VBZ'), ('that', 'IN'), ('it', 'PRP'), ('would', 'MD'), ('be', 'VB'), ('too', 'RB'), ('easy', 'JJ'), ('if', 'IN'), ('the', 'DT'), ('door', 'NN'), ('was', 'VBD'), ("n't", 'RB'), ('clogged', 'VBN'), ('up', 'RP'), ('poor', 'JJ'), ('dialogue', 'NN'), ('writing', 'NN'), ('almost', 'RB'), ('every', 'DT'), ('character', 'NN'), ('was', 'VBD'), ('one', 'CD'), ('bad', 'JJ'), ('story', 'NN'), ('telling', 'NN'), ('and', 'CC'), ('so', 'RB'), ('much', 'RB'), ('more', 'JJR')]"
^}
None

I'm pretty sure this is the special characters. Is there a solution for the stock driver, or should I move to py2neo or that one ORM-like interface?

I appreciate any tips. I've googled and I can't find much on how to make neo4j elegantly handle lists. Or at all.

0 REPLIES 0