2

フォーラム投稿に関する次の属性を持つ 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)

次のノードでグラフを作成しようとしています:

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
4

1 に答える 1

1

私は答えを得ました。継続ステートメントは次の反復にスキップしていたので、その方法で多くのノードを失っていました。

于 2012-04-23T12:10:35.907 に答える