我正在存储前一个节点和当前节点的对象,以便我可以在前一个节点和当前节点之间创建关系,例如字符串是“有一只猫”,每个单词都是 neo4j 中的节点,关系为“:下一个” " 与下一个节点,所以 "there"-[]->"is" 等等,但我面临 TypError:TypeError:不支持类型节点的参数我知道我的节点密码变量有问题,但我想不通出来,请帮忙我被困在这里
我已经尝试将 previousNode.single()[0] 分配给错误出现的密码变量
import nltk
from neo4j import GraphDatabase
from nltk.corpus import wordnet as wn
from nltk.tokenize import sent_tokenize
class DefFromNltk:
#listToTokenize = input("Enter string for NEO4J")
text = "There is a cat. Cat is sitting on the couch. Cat is very dirty"
sentenses = sent_tokenize(text)
# Establishing Connection
graphdb = GraphDatabase.driver(uri="bolt://localhost:7687", auth=("neo4j", "huwaiza"))
# Making Session Object
session = graphdb.session()
print(sentenses)
counter1=0
counter2=0
previousNode=None
#Creating node of sentence
for sentense in sentenses:
q1 = "CREATE(s:Sentence{label:$sentense}) return s"
sentenceNode=session.run(q1, sentense=sentense)
print(sentense)
wordsFromSentence = nltk.word_tokenize(sentense)
print(wordsFromSentence)
counter1 = counter1 +1
#Creating nodes of words
for word in wordsFromSentence:
print(word)
q2 = "CREATE(w:Words{label:$word}) return w"
##################################
wordNode = session.run(q2, word=word)
#print(dict(wordNode.single()[0]))
if previousNode is not None:
print("what ther")
#q2 = "MATCH (p:Words{label:$word}),(n:Words{label:$word}) create (p)-[:next]->(n)"
#q2 = "MATCH (p:Words{label:$previousNode.label}),(n:Words{label:$wordNode.label}) create (p)-[:next]->(n)"
#q2 = "MATCH (p:$previousNode),(n:$wordNode) CREATE (p)-[:next]->(n)"
q2 = "CREATE ($previousNode)-[:next]->($wordNode)"
session.run(q2,previousNode=previousNode.single()[0],wordNode=wordNode.single()[0])
else:
previousNode= wordNode
#previousNode = wordNode
#print(wordNode.single()[0])
counter2 = counter2+1
print(counter1,counter2)
session.close()
deficlass = DefFromNltk()
错误是引发 TypeError(obj) TypeError:
在处理上述异常的过程中,又出现了一个异常: