图形工具中的Python类型错误。查找顶点
我编写了一个函数,可以从边列表(取自数据库)中创建图形。我使用图形工具库。Python和这个库对我来说是非常新的 图中的每个顶点都应该用一对字符串和数字来描述。在函数中,如果考虑将新顶点添加到图中,首先检查图中是否存在相同属性的顶点。为此,我使用find_顶点函数。我不明白为什么会出现打字错误,请帮忙。这里有此函数的代码和回溯(如下所示): 编辑:还有一件事我必须处理unicode字符串图形工具中的Python类型错误。查找顶点,python,graph,graph-tool,Python,Graph,Graph Tool,我编写了一个函数,可以从边列表(取自数据库)中创建图形。我使用图形工具库。Python和这个库对我来说是非常新的 图中的每个顶点都应该用一对字符串和数字来描述。在函数中,如果考虑将新顶点添加到图中,首先检查图中是否存在相同属性的顶点。为此,我使用find_顶点函数。我不明白为什么会出现打字错误,请帮忙。这里有此函数的代码和回溯(如下所示): 编辑:还有一件事我必须处理unicode字符串 def make_graph(): conn = get_connection() curs
def make_graph():
conn = get_connection()
cursor = conn.cursor()
cursor.execute(sql)
wordnetList = cursor.fetchall()
g= Graph(directed=False)
vprop = g.new_vertex_property("python::object")
g.vertex_properties['lexicalunit'] = vprop
for (hyponym, v1, hyperonym, v2) in wordnetList: # hyponym and v1 (string and integer respectively) are properties of first vertex, hyperonym and v2 for the second
matched1 = find_vertex(g, g.vp['lexicalunit'], (hyponym, v1)) # this is line with problem
if len(matched1) == 0:
ver1 = g.add_vertex()
vprop[ver1] = (hyponym, v1)
elif len(matched1) >= 1:
ver1 = matched1[0]
matched2 = find_vertex(g, g.vp['lexicalunit'], (hyperonym, v2))
if len(matched2) == 0:
ver2 = g.add_vertex()
vprop[ver2] = (hyperonym, v2)
elif len(matched2) >= 1:
ver2 = matched2[0]
g.add_edge(ver1, ver2)
return g
回溯:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/olorin/Dokumenty/nlp-rr/CRFRelationRecogniser/python/wordnet_explorer/<ipython-input-2-163ed9b92398> in <module>()
----> 1 grf = make_graph()
/home/olorin/Dokumenty/nlp-rr/CRFRelationRecogniser/python/wordnet_explorer/hypgraph.py in make_graph()
65 for (hyponym, v1, hyperonym, v2) in wordnetList:
66 print(hyponym, v1, hyperonym, v2)
---> 67 matched1 = find_vertex(g, g.vp['lexicalunit'], (hyponym, v1))
68 if len(matched1) == 0:
69 ver1 = g.add_vertex()
/usr/lib/python2.7/dist-packages/graph_tool/util/__init__.pyc in find_vertex(g, prop, match)
53 can be either a :class:`~graph_tool.PropertyMap` or string with value "in",
54 "out" or "total", representing a degree type."""
---> 55 val = _convert(prop, match)
56 ret = libgraph_tool_util.\
57 find_vertex_range(weakref.ref(g), _degree(g, prop),
/usr/lib/python2.7/dist-packages/graph_tool/__init__.pyc in _convert(prop, val)
232 if type(vtype) is tuple:
233 return [vtype[1](x) for x in val]
--> 234 return vtype(val)
235
236
TypeError: object.__new__() takes no parameters
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
/home/olorin/Dokumenty/nlp-rr/CRFRelationRecogniser/python/wordnet_-explorer/in()
---->1 grf=生成图()
/make_graph()中的home/olorin/Dokumenty/nlp rr/crfrelationrecognizer/python/wordnet_explorer/hypgraph.py
65用于wordnetList中的(下位词,v1,hyperonym,v2):
66印刷体(下位词,v1,hyperonym,v2)
--->67 matched1=查找顶点(g,g.vp['lexicalunit'],(下位词,v1))
68如果len(matched1)==0:
69 ver1=g.添加_顶点()
/查找顶点中的usr/lib/python2.7/dist packages/graph_tool/util/__init__.pyc(g,prop,match)
53可以是:class:`~graph_tool.PropertyMap`或值为“in”的字符串,
54“out”或“total”,表示学位类型
--->55瓦尔=_换算(道具,匹配)
56 ret=libgraph\u tool\u util\
57查找顶点范围(weakref.ref(g),_度(g,prop),
/usr/lib/python2.7/dist packages/graph_tool/_init__.pyc in_convert(prop,val)
232如果类型(vtype)是元组:
233返回[V类型[1](x)表示val中的x]
-->234返回V类型(val)
235
236
TypeError:object.\uuuuu new\uuuuuu()不接受任何参数
这是图形工具中的一个错误。它现在已在git版本中修复: