[文档]classNode:""" A node within the graph. """def__init__(self,node_id=None,alias=None,label=None,properties=None):""" Create a new node. """self.id=node_idself.alias=aliasifisinstance(label,list):label=[inner_labelforinner_labelinlabelifinner_label!=""]if(labelisNoneorlabel==""or(isinstance(label,list)andlen(label)==0)):self.label=Noneself.labels=Noneelifisinstance(label,str):self.label=labelself.labels=[label]elifisinstance(label,list)andall([isinstance(inner_label,str)forinner_labelinlabel]):self.label=label[0]self.labels=labelelse:raiseAssertionError("label should be either None, string or a list of strings")self.properties=propertiesor{}defto_string(self):res=""ifself.properties:props=",".join(key+":"+str(quote_string(val))forkey,valinsorted(self.properties.items()))res+="{"+props+"}"returnresdef__str__(self):res="("ifself.alias:res+=self.aliasifself.labels:res+=":"+":".join(self.labels)ifself.properties:props=",".join(key+":"+str(quote_string(val))forkey,valinsorted(self.properties.items()))res+="{"+props+"}"res+=")"returnresdef__eq__(self,rhs):# Type checkingifnotisinstance(rhs,Node):returnFalse# Quick positive check, if both IDs are set.ifself.idisnotNoneandrhs.idisnotNoneandself.id!=rhs.id:returnFalse# Label should match.ifself.label!=rhs.label:returnFalse# Quick check for number of properties.iflen(self.properties)!=len(rhs.properties):returnFalse# Compare properties.ifself.properties!=rhs.properties:returnFalsereturnTrue