1

Ubuntu Linux の Python 3.2 で py2neo を使用して、SQLite3 データベースから neo4j にグラフを作成しています。速度はそれほど重要ではありませんが、グラフは合計 500 万行のうち、約 3 時間で 40,000 行 (SQL 行ごとに 1 つのリレーション) しか取得していません。

メインループは次のとおりです。

from py2neo import neo4j as neo
import sqlite3 as sql

#select all 5M rows from sql-database
sql_str =  """select * from bigram_with_number"""  

#loop through each row
for (freq, first, firstfreq, second, secondfreq) in sql_cursor.execute(sql_str):

    # create the Cypher query string using cypher 2.0 with merge
    # so that nodes are created only if needed

    query = neo.CypherQuery(neo4j_db,"""
        CYPHER 2.0 
            merge (n:word {form: {firstvar}, freq: {freqfirst}})
            merge(m:word {form: {secondvar}, freq: {freqsecond}}) 
            create unique (n)-[:bigram {freq: {freqbigram}}]->(m) return n, m""")
    #execute the string with parameters from sql-query
    result = query.execute(freqbigram = freq, firstvar = first, freqfirst=firstfreq, secondvar=second, freqsecond=secondfreq)

データベースは問題なく作成されますが、完了するまでに数週間かかります。これをより速く行うことは可能だと思います。

4

1 に答える 1

2

一括読み込みの場合は、REST インターフェースをバイパスし、Michael Hunger の読み込みツール ( https://github.com/jexp/neo4j-shell-tools )などの低レベルのものを使用することをお勧めします。最適なパフォーマンスであっても、REST インターフェースが求めている速度を達成することはほとんどありません。

余談ですが、Python 3.3 はサポートしていますが、Python 3.2 を公式にサポートしていないことに注意してください。

于 2013-09-26T10:30:55.327 に答える