2014-12-01 24 views
1

我正在玩neo4j數據庫,當我想將列表添加到節點屬性時卡住了。 基本上我想一個新的條目「links_in」添加到爲傳入節點屬性到節點在Python中的圖形節點對象的字典中添加新密鑰的錯誤

以下列表中的一個節點屬性哪些節點:

| n                  
---+-------------------------------------------------------------------------- 
1 | (n4096:Site {name:"http://www.example.org/"})    
2 | (n4097:Site {name:"http://www.example.org/our-services"})    
3 | (n4098:Site {name:"http://www.example.org/our-services#solution"})  
4 | (n4099:Site {name:"http://www.example.org/our-services#consult"})  
5 | (n4100:Site {name:"http://www.example.org/our-services#technologies"}) 
6 | (n4101:Site {name:"http://www.example.org/about"})      
7 | (n4102:Site {name:"http://www.example.org/careers"})     
8 | (n4103:Site {name:"http://www.example.org/blog"})      
9 | (n4104:Site {name:"http://www.example.org/contact"}) 

和節點關係如下:

"http://www.example.org/" -> "http://www.example.org/our-services" 
"http://www.example.org/" -> "http://www.example.org/our-services#solution" 
"http://www.example.org/" -> "http://www.example.org/our-services#consult" 
"http://www.example.org/" -> "http://www.example.org/our-services#technologies" 
"http://www.example.org/" -> "http://www.example.org/about" 
"http://www.example.org/" -> "http://www.example.org/careers" 
"http://www.example.org/" -> "http://www.example.org/blog" 
"http://www.example.org/" -> "http://www.example.org/cont" 

而且我期待輸出爲:

| n                  
---+-------------------------------------------------------------------------- 
1 | (n4096:Site {name:"http://www.example.org/","links_in":[]})    
2 | (n4097:Site {name:"http://www.example.org/our-services","links_in":["http://www.example.org/"]})    
3 | (n4098:Site {name:"http://www.example.org/our-services#solution,"links_in":["http://www.example.org/"]"})  
4 | (n4099:Site {name:"http://www.example.org/our-services#consult,"links_in":["http://www.example.org/"]"})  
5 | (n4100:Site {name:"http://www.example.org/our-services#technologies,"links_in":["http://www.example.org/"]"}) 
6 | (n4101:Site {name:"http://www.example.org/about,"links_in":["http://www.example.org/"]"})      
7 | (n4102:Site {name:"http://www.example.org/careers,"links_in":["http://www.example.org/"]"})     
8 | (n4103:Site {name:"http://www.example.org/blog,"links_in":["http://www.example.org/"]"})      
9 | (n4104:Site {name:"http://www.example.org/contact,"links_in":["http://www.example.org/"]"}) 

所以我嘗試以下方法來獲得上述結果:

def FindLinks(): 
    links_in = [] 
    for i in graph.cypher.execute("match n return n"): 
     for j in graph.cypher.execute("match()-[r:ok]->(n) where n.name ='%s' return r"%i.n.properties['name']): 
      if graph.node(i.n.ref).properties.has_key('links_in'): 
       graph.node(i.n.ref).properties["links_in"].append(j.r.start_node.properties) 
      else: 
       links_in.append(j.r.start_node.properties) 
     graph.node(i.n.ref).properties.update({"links_in":links_in}) 
     links_in = [] 

但我得到了錯誤

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-171-e762c2030688> in <module>() 
     5   else: 
     6    links_in.append(j.r.start_node.properties) 
----> 7  graph.node(i.n.ref).properties.update({"links_in":links_in}) 
     8  links_in = [] 

/usr/local/lib/python2.7/dist-packages/py2neo/core.pyc in update(self, iterable, **kwargs) 
    1071      self[key] = iterable[key] 
    1072    except (AttributeError, TypeError): 
-> 1073     for key, value in iterable: 
    1074      self[key] = value 
    1075   for key in kwargs: 

ValueError: too many values to unpack 

所以,我應該怎麼辦?

+0

請張貼其餘的追蹤。它包含有用的信息,例如發生錯誤的行。 – Kevin 2014-12-01 15:59:40

回答

3

我已經能夠重新創建這個問題,並已提交修復錯誤信息。這將在py2neo 2.0.1中發佈。

潛在的問題實際上是非法財產類型的分配。您正試圖設置由PropertySet對象列表組成的屬性值。 Neo4j中的列表可能只包含原始類型,並且它們必須是同類的。欲瞭解更多信息,請看這裏:http://neo4j.com/docs/stable/graphdb-neo4j-properties.html

相關問題