2011-01-24 19 views

答えて

4

これはもっと複雑な質問ですが、私が尋ねたときのようでしたが、単純な答えはデータベースを完全に正規化することです。完全に正規化された後、各テーブルは述語を表し、1つの列の値はサブジェクトを表し、1つの列の値はオブジェクトを表します。これに基づいて任意のSQLデータベースをtriplestoreに変換することができます。

+0

。本当ですか? :-) ...大丈夫、真実:あなたは紙やリンク、あるいは何かを引用できますか?ありがとう! – Benjohn

+0

いいえ、私はこれがオリジナルであることを知っている限り、何も引用することはできません。それは他の方法(例えば、3つの列、A、B、およびそれらの間の関係のタイプ)を有する1つの大きなテーブルを実行することができる。しかし、あなたはテーブルが何であるかを深く考えるとき、あなたはそれが関係のタイプに立つことができることを理解しています。 – tjb

2

機能トリプル形式に、リレーショナル・データの任意の種類を変える3倍に変換:

def transform_to_triple(source,db_name,table,result): 
    #get the list of relations for the selected DB 
    max_records = 100 
    response = [] 
    x_print = lambda *x : response.append("(%s)\n" %("".join(["%s"%(v) for v in x]))) 

    id = 1 

    x_print(id,',(db_name:string),',db_name) 
    logger.info("(%s,(db_name,string), %s)" %(id,db_name)) 

    tables = [] 
    table_list = [table,] 
    for i, _table in enumerate(table_list): 
     _table_id = id + i + 1 
     x_print(id,',(rel:id),', _table_id) 
     logger.info("(%s,(rel, id), %s)" %(id, _table_id)) 

     _schema = get_column_list(source, db_name,_table) 
     tables.append((_table_id, _table, _schema)) 
    for _table in tables: 
     _table_id = _table[0] 
     x_print(_table_id,',(rel_name:string),',_table[1]) 
     for j,row in enumerate(result): 
      #lets assume there is always less than 10 k tuples in a table 
      _tuple_id = _table_id * max_records + j + 1 
      x_print(_table[0],',(tuple:id),', _tuple_id) 
      logger.info("(%s,(tuple, id), %s)" %(_table[0],_tuple_id)) 
     for j,row in enumerate(result): 
      _tuple_id = _table_id * max_records + j + 1 
      for k,value in enumerate(row): 
       x_print(_tuple_id, ",(%s : %s)," %(_table[2][k][0], _table[2][k][1]), value) 
    return "%s" %("".join(response)) 

get_column_list機能は、データベーステーブル内の列のリストを返します。これは素晴らしいですね

def get_column_list(src_name,db_name,table_name): 
    cur = get_connect() #Connecting with tool DB 
    query = '''select db_name, host, user_name, password from "DataSource" where src_name = '%s' and db_name = '%s' '''%(src_name, db_name) 
    cur.execute(query) 
    data = cur.fetchall() 
    (db, host, username, password) = data[0] 
    _module = get_module(src_name) 
    cursor = _module.get_connection(db, host, username, password) 
    try: 
      _column_query = _module.COLUMN_LIST_QUERY %(db_name, table_name) 
    except TypeError, e: 
      try: 
       _column_query = _module.COLUMN_LIST_QUERY %(table_name) 
      except TypeError, e: 
       _column_query = _module.COLUMN_LIST_QUERY 

    cursor.execute(_column_query) 
    column_list = cursor.fetchall() 
    return column_list 
+0

投票ボタンがありますが、ボタンはありません!私は好きになりたい。 – Benjohn

関連する問題