#NEWLINE# def create_metadata_categorical( bdb , generator_id , colno ) : #NEWLINE# #INDENT# table = core . bayesdb_generator_table ( bdb , generator_id ) #NEWLINE# column_name = core . bayesdb_table_column_name ( bdb , table , colno ) #NEWLINE# qt = sqlite3_quote_name ( table ) #NEWLINE# qcn = sqlite3_quote_name ( column_name ) #NEWLINE# sql = ( '\n        SELECT DISTINCT CAST(%s AS TEXT)\n            FROM %s WHERE %s IS NOT NULL ORDER BY %s\n    ' % ( qcn , qt , qcn , qcn ) ) #NEWLINE# cursor = bdb . sql_execute ( sql ) #NEWLINE# codes = [ row [ 0 ] for row in cursor ] #NEWLINE# assert all ( ( isinstance ( value , unicode ) for value in codes ) ) #NEWLINE# ncodes = len ( codes ) #NEWLINE# return { #NEWLINE# #INDENT# 'modeltype' : 'symmetric_dirichlet_discrete' , #NEWLINE# 'value_to_code' : dict ( zip ( range ( ncodes ) , codes ) ) , #NEWLINE# 'code_to_value' : dict ( zip ( codes , range ( ncodes ) ) ) , #NEWLINE# #UNINDENT# }