python - Unhandled exception in py2neo: Type error -
i writing application purpose create graph journal dataset. dataset xml file parsed in order extract leaf data. using list wrote py2neo script create graph. file attached message. script processed exception raised:
the debugged program raised exception unhandled typeerror "(1676 {"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
i don't know how handle this. think code syntactically correct...but...
i dont know if shoud post entire code here, code at: https://gist.github.com/herlimenezes/6867518
there goes code: +++++++++++++++++++++++++++++++++++ ' #!/usr/bin/env python #
from py2neo import neo4j, cypher 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") # # begin, database clear... graph_db.clear() # not sure if works...let's check... # # big list, next version supposed read 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 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] in range(0, len(listabase), 4)] # pedacos = chunks # # lists collect indexed nodes: useful??? # let's think when optimizing code... datapub_nodes = [] titulo_nodes = [] autores_nodes = [] keyword_nodes = [] # # in range(0, len(pedacos)): # fill datapub_nodes , titulo_nodes 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... -------------------------------- # debugged program raised 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 # ------------------------------ 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]) # processing autores sublist , collecting in autores_nodes # 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... # 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]) `
the fragment of py2neo raised exception
def get_or_create_relationships(self, *abstracts): """ fetch or create relationships specified criteria depending on whether or not such relationships exist. each relationship descriptor should tuple of (start, type, end) or (start, type, end, data) start , end either existing :py:class:`node` instances or :py:const:`none` (both nodes cannot :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) abstract in abstracts: if 3 <= len(abstract) <= 4: batch.get_or_create_relationship(*abstract) else: raise typeerror(abstract) # 472 line. try: return batch.submit() except cypher.cyphererror: raise notimplementederror( "the neo4j server @ <{0}> not support " \ "cypher create unique clauses or query contains " \ "an unsupported property type".format(self.__uri__) ) ====== help?
i have fixed it, nigel small. made mistake wrote line on creating relationships. typed: publicacao = graph_db.get_or_create_relationships(titulo_nodes[i], "publicado_em", datapub_nodes[i])
and must be:
publicacao = graph_db.get_or_create_relationships((titulo_nodes[i], "publicado_em", datapub_nodes[i]))
by way, there coding error: keyword_nodes.append(keyword_index.get_or_create("keyword", pedacos[i][3][k])) must keyword_nodes.append(keyword_index.get_or_create("keyword", pedacos[i][3][k], {"keyword":pedacos[i][3][k]}))
Comments
Post a Comment