2013-10-07 62 views
0

我正在編寫一個應用程序,其目的是從日誌數據集創建圖表。該數據集是一個xml文件,該文件被解析以提取葉數據。使用這個列表我寫了一個py2neo腳本來創建圖。該文件附加到此消息。 由於腳本處理的異常升高:py2neo中未處理的異常:類型錯誤

的調試程序引發的異常未處理的類型錯誤 「(1676 {」 TITULO 「:」 reconhecimentoêagrupamento德objetos德aprendizagem semelhantes 「})」 文件:在/ usr /lib/python2.7/site-packages/py2neo-1.5.1-py2.7.egg/py2neo/neo4j.py,行:472

我不知道如何處理這個。我認爲代碼語法正確...但是...

我不知道如果我在這裏768,16張貼整個代碼,所以代碼爲:https://gist.github.com/herlimenezes/6867518

有云代碼: ++ +++++++++++++++++++++++++++++++++ ' #!的/ usr /斌/包膜蟒蛇 #

from py2neo import neo4j, cypher 
from py2neo import node, rel 

# calls database service of Neo4j 
# 
graph_db = neo4j.GraphDatabaseService("DEFAULT_DOMAIN") 
# 
# following nigel small suggestion in http://stackoverflow.com 
# 
titulo_index = graph_db.get_or_create_index(neo4j.Node, "titulo") 
autores_index = graph_db.get_or_create_index(neo4j.Node, "autores") 
keyword_index = graph_db.get_or_create_index(neo4j.Node, "keywords") 
dataPub_index = graph_db.get_or_create_index(neo4j.Node, "data") 
# 
# to begin, database clear... 

graph_db.clear() # not sure if this really works...let's check... 
# 
# the big list, next version this is supposed to be read from a file... 
# 
listaBase = [['2007-12-18'], ['RECONHECIMENTO E AGRUPAMENTO DE OBJETOS DE APRENDIZAGEM SEMELHANTES'], ['Raphael Ghelman', 'SWMS', 'MHLB', 'RNM'], ['Objetos de Aprendizagem', u'Personaliza\xe7\xe3o', u'Perfil do Usu\xe1rio', u'Padr\xf5es de Metadados', u'Vers\xf5es de Objetos de Aprendizagem', 'Agrupamento de Objetos Similares'], ['2007-12-18'], [u'LOCPN: REDES DE PETRI COLORIDAS NA PRODU\xc7\xc3O DE OBJETOS DE APRENDIZAGEM'], [u'Maria de F\xe1tima Costa de Souza', 'Danielo G. Gomes', 'GCB', 'CTS', u'Jos\xe9 ACCF', 'MCP', 'RMCA'], ['Objetos de Aprendizagem', 'Modelo de Processo', 'Redes de Petri Colorida', u'Especifica\xe7\xe3o formal'], ['2007-12-18'], [u'COMPUTA\xc7\xc3O M\xd3VEL E UB\xcdQUA NO CONTEXTO DE UMA GRADUA\xc7\xc3O DE REFER\xcaNCIA'], ['JB', 'RH', 'SR', u'S\xe9rgio CCSPinto', u'D\xe9bora NFB'], [u'Computa\xe7\xe3o M\xf3vel e Ub\xedqua', u'Gradua\xe7\xe3o de Refer\xeancia', u' Educa\xe7\xe3o Ub\xedqua']] 
# 
pedacos = [listaBase[i:i+4] for i in range(0, len(listaBase), 4)] # pedacos = chunks 
# 
# lists to collect indexed nodes: is it really useful??? 
# let's think about it when optimizing code... 
dataPub_nodes = [] 
titulo_nodes = [] 
autores_nodes = [] 
keyword_nodes = [] 
# 
# 
for i in range(0, len(pedacos)): 
# fill dataPub_nodes and titulo_nodes with content. 

#dataPub_nodes.append(dataPub_index.get_or_create("data", pedacos[i][0], {"data":pedacos[i][0]})) # Publication date nodes... 
dataPub_nodes.append(dataPub_index.get_or_create("data", str(pedacos[i][0]).strip('[]'), {"data":str(pedacos[i][0]).strip('[]')})) 
# ------------------------------- Exception raised here...  -------------------------------- 
# The debugged program raised the exception unhandled TypeError 
#"(1649 {"titulo":["RECONHECIMENTO E AGRUPAMENTO DE OBJETOS DE APRENDIZAGEM SEMELHANTES"]})" 
#File: /usr/lib/python2.7/site-packages/py2neo-1.5.1-py2.7.egg/py2neo/neo4j.py, Line: 472 
# ------------------------------ What happened??? ---------------------------------------- 

titulo_nodes.append(titulo_index.get_or_create("titulo", str(pedacos[i][1]).strip('[]'), {"titulo":str(pedacos[i][1]).strip('[]')})) # title node... 

# creates relationship publicacao 
publicacao = graph_db.get_or_create_relationships(titulo_nodes[i], "publicado_em", dataPub_nodes[i]) 

# now processing autores sublist and collecting in autores_nodes 
# 
for j in range(0, len(pedacos[i][2])): 
    # fill autores_nodes list 
    autores_nodes.append(autores_index.get_or_create("autor", pedacos[i][2][j], {"autor":pedacos[i][2][j]})) 
    # creates autoria relationship... 
    # 
    autoria = graph_db.get_or_create_relationships(titulo_nodes[i], "tem_como_autor", autores_nodes[j]) 
    # same logic... 
    # 
    for k in range(0, len(pedacos[i][3])): 
     keyword_nodes.append(keyword_index.get_or_create("keyword", pedacos[i][3][k])) 
     # cria o relacionamento 'tem_como_keyword' 
     tem_keyword = graph_db.get_or_create_relationships(titulo_nodes[i], "tem_como_keyword", keyword_nodes[k]) 

`

引發異常的py2neo片段

def get_or_create_relationships(self, *abstracts): 
    """ Fetch or create relationships with the specified criteria depending 
    on whether or not such relationships exist. Each relationship 
    descriptor should be a tuple of (start, type, end) or (start, type, 
    end, data) where start and end are either existing :py:class:`Node` 
    instances or :py:const:`None` (both nodes cannot be :py:const:`None`). 

    Uses Cypher `CREATE UNIQUE` clause, raising 
    :py:class:`NotImplementedError` if server support not available. 

    .. deprecated:: 1.5 
     use either :py:func:`WriteBatch.get_or_create_relationship` or 
     :py:func:`Path.get_or_create` instead. 
    """ 
    batch = WriteBatch(self) 
    for abstract in abstracts: 
     if 3 <= len(abstract) <= 4: 
      batch.get_or_create_relationship(*abstract) 
     else: 
      raise TypeError(abstract) # this is the 472 line. 
    try: 
     return batch.submit() 
    except cypher.CypherError: 
     raise NotImplementedError(
      "The Neo4j server at <{0}> does not support " \ 
      "Cypher CREATE UNIQUE clauses or the query contains " \ 
      "an unsupported property type".format(self.__uri__) 
     ) 

====== 任何幫助?

+0

如果您無法發佈完整的代碼,請在第472行附近張貼幾條線。 – aIKid

+0

順便提一下,該錯誤不在該文件中。它在neo4j模塊中。 – aIKid

回答

0

我已經修好了,感謝Nigel Small。我寫了關於創建關係的一行,我犯了一個錯誤。我輸入: publicacao = graph_db.get_or_create_relationships(titulo_nodes [I]中, 「publicado_em」,dataPub_nodes [I])

,它必須是:

publicacao = graph_db.get_or_create_relationships((titulo_nodes [I], 「publicado_em」,dataPub_nodes [I]))

順便提一下,也有另一種編碼誤差: keyword_nodes.append(keyword_index.get_or_create( 「關鍵字」,pedacos [I] [3] [K])) 必須是 keyword_nodes.append(keyword_index.get_or_create(「keyword」,pedacos [i] [3] [k],{「keyword」:pedacos [i] [3] [k]}))

相關問題