У меня есть база данных MDB со следующими атрибутами около сообщений на форуме:Узел кол-график не соответствует
thread
author (posted in the thread)
children (a list of authors who replied to the post)
child_count (number of children in the list)
Im пытается построить граф со следующими узлами:
thread
author
child authors
общее разные авторы в моей базе данных составляют более 30 000, но граф, который генерируется автором, составляет около 3000. Или, из общего числа 33000 узлов, следующий код генерирует около 5000. Что здесь происходит?
for doc in coll.find():
thread = doc['thread'].encode('utf-8')
author_parent = doc['author'].encode('utf-8')
children = doc['children']
children_count = len(children)
#print G.nodes()
#print post_parent, author, doc['thread']
try:
if thread in G:
continue
else:
G.add_node(thread, color='red')
thread_count+=1
if author_parent in G:
G.add_edge(author_parent, thread)
else:
G.add_node(author_parent, color='green')
G.add_edge(author_parent, thread, weight=0)
author_count+=1
if doc['child_count']!=0:
for doc in children:
if doc['author'].encode("utf-8") in G:
print doc['author'].encode("utf-8"), 'in G'
G.add_edge(doc['author'].encode("utf-8"), author_parent)
else:
G.add_node(doc['author'].encode("utf-8"),color='green')
G.add_edge(doc['author'].encode("utf-8"), author_parent, weight=0)
author_count+=1
except:
print "failed"
nx.write_dot(G,PATH)
print thread_count, author_count, children_count
Вы уверены, что 'coll.find()' возвращает 30000 результатов? – brice
@brice coll.find() возвращает более 500 000 результатов. Отдельные авторы составляют около 30 000 человек. – codious