2014-07-10 2 views
0

140 만 개 이상의 노드와 1 억 6 천만 개 이상의 관계가있는 거대한 그래프 데이터베이스를 만들고 있습니다. 내 코드는 다음과 같습니다TypeError : JSON을 직렬화 할 수 없습니다. Py2neo Batch submit

from py2neo import neo4j 
# first we create all the nodes 
batch = neo4j.WriteBatch(graph_db) 
nodedata = [] 

for index, i in enumerate(words): # words is predefined 
    batch.create({"term":i}) 
    if index%5000 == 0: #so as not to exceed the batch restrictions 
     results = batch.submit() 
     for x in results: 
      nodedata.append(x) 
     batch = neo4j.WriteBatch(graph_db) 

results = batch.submit() 
for x in results: 
    nodedata.append(x) 

#nodedata contains all the node instances now 
#time to create relationships 

batch = neo4j.WriteBatch(graph_db) 
for iindex, i in enumerate(weightdata): #weightdata is predefined 
    batch.create((nodedata[iindex], "rel", nodedata[-iindex], {"weight": i})) #there is a different way how I decide the indexes of nodedata, but just as an example I put iindex and -iindex 
    if iindex%5000 == 0: #again batch constraints 
     batch.submit() #this is the line that shows error 
     batch = neo4j.WriteBatch(graph_db) 
batch.submit() 

나는 다음과 같은 오류가 점점 오전 :

Traceback (most recent call last): 
    File "test.py", line 53, in <module> 
    batch.submit() 
    File "/usr/lib/python2.6/site-packages/py2neo/neo4j.py", line 2116, in submit 
    for response in self._submit() 
    File "/usr/lib/python2.6/site-packages/py2neo/neo4j.py", line 2085, in _submit 
    for id_, request in enumerate(self.requests) 
    File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 427, in _send 
    return self._client().send(request) 
    File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 351, in send 
    rs = self._send_request(request.method, request.uri, request.body, request.$ 
    File "/usr/lib/python2.6/site-packages/py2neo/rest.py", line 326, in _send_re$ 
    data = json.dumps(data, separators=(",", ":")) 
    File "/usr/lib64/python2.6/json/__init__.py", line 237, in dumps 
    **kw).encode(obj) 
    File "/usr/lib64/python2.6/json/encoder.py", line 367, in encode 
    chunks = list(self.iterencode(o)) 
    File "/usr/lib64/python2.6/json/encoder.py", line 306, in _iterencode 
    for chunk in self._iterencode_list(o, markers): 
    File "/usr/lib64/python2.6/json/encoder.py", line 204, in _iterencode_list 
    for chunk in self._iterencode(value, markers): 
    File "/usr/lib64/python2.6/json/encoder.py", line 309, in _iterencode 
    for chunk in self._iterencode_dict(o, markers): 
    File "/usr/lib64/python2.6/json/encoder.py", line 275, in _iterencode_dict 
    for chunk in self._iterencode(value, markers): 
    File "/usr/lib64/python2.6/json/encoder.py", line 317, in _iterencode 
    for chunk in self._iterencode_default(o, markers): 
    File "/usr/lib64/python2.6/json/encoder.py", line 323, in _iterencode_default 
    newobj = self.default(o) 
    File "/usr/lib64/python2.6/json/encoder.py", line 344, in default 
    raise TypeError(repr(o) + " is not JSON serializable") 
TypeError: 3448 is not JSON serializable 

사람이 바로 여기에 무슨 일이 일어나고 나는 어떻게 그것을 극복 할 수있는 걸 제안시겠습니까? 모든 종류의 도움을 주시면 감사하겠습니다. 미리 감사드립니다! :)

답변

1

그것은이다 동일한 데이터 세트로 코드를 실행할 수 없으면 알기가 어렵지만 이는 weightdata의 항목 유형으로 인해 발생할 수 있습니다.

의 형식이 관계 설명자 부분에 있는지 확인하기 위해 코드를 단계별로 실행하거나 데이터 형식을 인쇄하십시오. 이 숫자는 int이 아니며 JSON 번호 직렬화에 필요합니다. 이 이론이 맞다면 속성 집합에서 사용하기 전에 해당 속성 값을 캐스팅하거나 그렇지 않으면 int으로 변환하는 방법을 찾아야합니다.

+0

고마워요! :) – AnotherCodingEnthusiast

1

은 내가 p2neo을 사용한 적이 있지만이 문서

를 보면이 :

batch.create((nodedata[iindex], "rel", nodedata[-iindex], {"weight": i})) 

가 확인해 누락() 부 :

batch.create(rel(nodedata[iindex], "rel", nodedata[-iindex], {"weight": i})) 
+0

관계는 다음과 같이 (node1, "rel", node2, { "property": value}) 같이 호출 할 수도 있습니다. http://book.py2neo.org/en/latest/graphs_nodes_relationships/ 노드를 다른 방식으로 생성 했음에도 불구하고 노드를 생성했음을 주목하십시오. 그래서 다른 문제가 있다고 생각합니다. – AnotherCodingEnthusiast

관련 문제