Commit b89e2c26 authored by bogdan's avatar bogdan

Merge branch 'dev' of workflow.ijs.si:mothra into searchFunct

parents 7dd33198 db580e10
...@@ -24,7 +24,7 @@ class DBConnection: ...@@ -24,7 +24,7 @@ class DBConnection:
return sql.connect(user=self.user, password=self.password, host=self.host, database=self.database) return sql.connect(user=self.user, password=self.password, host=self.host, database=self.database)
class DBContext: class DBContext:
def __init__(self, connection): def __init__(self, connection, find_connections=False):
''' '''
Initializes the fields: Initializes the fields:
tables: list of selected tables tables: list of selected tables
...@@ -36,7 +36,6 @@ class DBContext: ...@@ -36,7 +36,6 @@ class DBContext:
pkeys: private key for a given table pkeys: private key for a given table
target_table: selected table for learning target_table: selected table for learning
target_att: selected column for learning target_att: selected column for learning
target_att_val: selected target att value
''' '''
self.connection = connection self.connection = connection
con = connection.connect() con = connection.connect()
...@@ -54,18 +53,27 @@ class DBContext: ...@@ -54,18 +53,27 @@ class DBContext:
for col in cols: for col in cols:
cursor.execute("SELECT DISTINCT `%s` FROM `%s` LIMIT 51" % (col, table)) cursor.execute("SELECT DISTINCT `%s` FROM `%s` LIMIT 51" % (col, table))
self.col_vals[table][col] = [val for (val,) in cursor] self.col_vals[table][col] = [val for (val,) in cursor]
print self.col_vals
self.connected = {} self.connected = {}
cursor.execute( cursor.execute(
"SELECT table_name, column_name, referenced_table_name, referenced_column_name \ "SELECT table_name, column_name, referenced_table_name, referenced_column_name \
FROM information_schema.KEY_COLUMN_USAGE \ FROM information_schema.KEY_COLUMN_USAGE \
WHERE referenced_table_name IS NOT NULL AND table_schema='%s'" % connection.database) WHERE referenced_table_name IS NOT NULL AND table_schema='%s'" % connection.database)
self.fkeys = defaultdict(set) self.fkeys = defaultdict(set)
self.pkeys = {}
if find_connections:
for table in self.tables:
for col in self.cols[table]:
if col.endswith('_id'):
ref_table = (col[:-4] + 'ies') if col[-4] == 'y' else (col[:-3] + 's')
self.connected[(table, ref_table)] = (col, 'id')
self.connected[(ref_table, table)] = ('id', col)
self.fkeys[table].add(col)
if col == 'id':
self.pkeys[table] = col
for (table, col, ref_table, ref_col) in cursor: for (table, col, ref_table, ref_col) in cursor:
self.connected[(table, ref_table)] = (col, ref_col) self.connected[(table, ref_table)] = (col, ref_col)
self.connected[(ref_table, table)] = (ref_col, col) self.connected[(ref_table, table)] = (ref_col, col)
self.fkeys[table].add(col) self.fkeys[table].add(col)
self.pkeys = {}
cursor.execute( cursor.execute(
"SELECT table_name, column_name \ "SELECT table_name, column_name \
FROM information_schema.KEY_COLUMN_USAGE \ FROM information_schema.KEY_COLUMN_USAGE \
...@@ -126,5 +134,7 @@ class DBContext: ...@@ -126,5 +134,7 @@ class DBContext:
return types return types
def __repr__(self): def __repr__(self):
return str((self.target_table, self.target_att, self.tables, self.cols, self.connected)) #import pprint
#return pprint.pformat((self.target_table, self.target_att, self.tables, self.cols, self.connected, self.pkeys, self.fkeys))
return 'fkeys : ' + str(self.fkeys)
[ [
{ {
"pk": 39, "pk": 20,
"model": "workflows.category", "model": "workflows.category",
"fields": { "fields": {
"uid": "b66b71b1-99d6-4efc-b264-a914a3e42911", "uid": "b66b71b1-99d6-4efc-b264-a914a3e42911",
"parent": null, "parent": null,
"workflow": null, "workflow": null,
"user": null, "user": null,
"order": 1, "order": 1,
"name": "MySQL" "name": "MySQL"
} }
}, },
{ {
"pk": 190, "pk": 104,
"model": "workflows.abstractwidget", "model": "workflows.abstractwidget",
"fields": { "fields": {
"category": 39, "category": 20,
"treeview_image": "", "treeview_image": "",
"name": "Database Context", "name": "Database Context",
"is_streaming": false, "is_streaming": false,
"uid": "649015ac-ca53-43bc-a36a-c603b52f8775", "uid": "649015ac-ca53-43bc-a36a-c603b52f8775",
"interaction_view": "mysql_db_context", "interaction_view": "mysql_db_context",
"image": "", "image": "",
"package": "mysql", "package": "mysql",
"static_image": "mysql.png", "static_image": "mysql.png",
"post_interact_action": "mysql_db_context_finished", "post_interact_action": "mysql_db_context_finished",
"user": null, "user": null,
"visualization_view": "", "visualization_view": "",
"action": "mysql_db_context", "action": "mysql_db_context",
"wsdl_method": "", "wsdl_method": "",
"wsdl": "", "wsdl": "",
"interactive": true, "interactive": true,
"has_progress_bar": false, "has_progress_bar": false,
"order": 1, "order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 443, "pk": 213,
"model": "workflows.abstractinput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 190, "widget": 104,
"name": "connection", "name": "connection",
"short_name": "con", "short_name": "con",
"uid": "6c23b4a2-a18e-498e-a22c-4de86932da3e", "uid": "6c23b4a2-a18e-498e-a22c-4de86932da3e",
"default": "", "default": "",
"required": true, "required": true,
"multi": false, "multi": false,
"parameter_type": null, "parameter_type": null,
"variable": "connection", "variable": "connection",
"parameter": false, "parameter": false,
"order": 1, "order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 216, "pk": 236,
"model": "workflows.abstractoutput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 190, "widget": 104,
"name": "context", "name": "Table connection from names",
"short_name": "cxt", "short_name": "tbc",
"variable": "context", "uid": "be3718eb-062e-48f2-af2a-8c31e66524fe",
"uid": "171aa481-0f93-4315-a476-ed3b0aa8c9e4", "default": "false",
"order": 1, "required": true,
"multi": false,
"parameter_type": "checkbox",
"variable": "find_connections",
"parameter": true,
"order": 1,
"description": "Tries to detect connections between tables solely by looking at the attribute names."
}
},
{
"pk": 117,
"model": "workflows.abstractoutput",
"fields": {
"widget": 104,
"name": "context",
"short_name": "cxt",
"variable": "context",
"uid": "171aa481-0f93-4315-a476-ed3b0aa8c9e4",
"order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 191, "pk": 105,
"model": "workflows.abstractwidget", "model": "workflows.abstractwidget",
"fields": { "fields": {
"category": 39, "category": 20,
"treeview_image": "", "treeview_image": "",
"name": "Database To Aleph", "name": "Database To Aleph",
"is_streaming": false, "is_streaming": false,
"uid": "3c5ac714-84ca-4c93-befb-ce0c16148193", "uid": "3c5ac714-84ca-4c93-befb-ce0c16148193",
"interaction_view": "", "interaction_view": "",
"image": "", "image": "",
"package": "mysql", "package": "mysql",
"static_image": "mysql.png", "static_image": "mysql.png",
"post_interact_action": "", "post_interact_action": "",
"user": null, "user": null,
"visualization_view": "", "visualization_view": "",
"action": "mysql_aleph_converter", "action": "mysql_aleph_converter",
"wsdl_method": "", "wsdl_method": "",
"wsdl": "", "wsdl": "",
"interactive": false, "interactive": false,
"has_progress_bar": false, "has_progress_bar": false,
"order": 1, "order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 451, "pk": 235,
"model": "workflows.abstractinput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 191, "widget": 105,
"name": "Target attribute value", "name": "Target attribute value",
"short_name": "tgt", "short_name": "tgt",
"uid": "5b7354f1-35d8-41c8-a0ae-c3848855f29d", "uid": "5b7354f1-35d8-41c8-a0ae-c3848855f29d",
"default": "", "default": "",
"required": true, "required": true,
"multi": false, "multi": false,
"parameter_type": "text", "parameter_type": "text",
"variable": "target_att_val", "variable": "target_att_val",
"parameter": true, "parameter": true,
"order": 1, "order": 1,
"description": "Target attribute value to be used as the positive class" "description": "Target attribute value to be used as the positive class"
} }
}, },
{ {
"pk": 444, "pk": 214,
"model": "workflows.abstractinput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 191, "widget": 105,
"name": "context", "name": "context",
"short_name": "cxt", "short_name": "cxt",
"uid": "474e9673-9c55-48c5-bae8-a7b986aa0287", "uid": "474e9673-9c55-48c5-bae8-a7b986aa0287",
"default": "", "default": "",
"required": true, "required": true,
"multi": false, "multi": false,
"parameter_type": null, "parameter_type": null,
"variable": "context", "variable": "context",
"parameter": false, "parameter": false,
"order": 2, "order": 2,
"description": "Database context object" "description": "Database context object"
} }
}, },
{ {
"pk": 217, "pk": 118,
"model": "workflows.abstractoutput", "model": "workflows.abstractoutput",
"fields": { "fields": {
"widget": 191, "widget": 105,
"name": "pos_examples", "name": "pos_examples",
"short_name": "pex", "short_name": "pex",
"variable": "pos_examples", "variable": "pos_examples",
"uid": "48184527-16a5-446c-9181-48a6558430c2", "uid": "48184527-16a5-446c-9181-48a6558430c2",
"order": 2, "order": 2,
"description": "positive examples file" "description": "positive examples file"
} }
}, },
{ {
"pk": 218, "pk": 119,
"model": "workflows.abstractoutput", "model": "workflows.abstractoutput",
"fields": { "fields": {
"widget": 191, "widget": 105,
"name": "neg_examples", "name": "neg_examples",
"short_name": "nex", "short_name": "nex",
"variable": "neg_examples", "variable": "neg_examples",
"uid": "2c623064-95cd-48ac-8bff-617edf2b9468", "uid": "2c623064-95cd-48ac-8bff-617edf2b9468",
"order": 3, "order": 3,
"description": "negative examples file" "description": "negative examples file"
} }
}, },
{ {
"pk": 219, "pk": 120,
"model": "workflows.abstractoutput", "model": "workflows.abstractoutput",
"fields": { "fields": {
"widget": 191, "widget": 105,
"name": "bk", "name": "bk",
"short_name": "bk", "short_name": "bk",
"variable": "bk", "variable": "bk",
"uid": "5e61e44e-cc52-4471-9a41-3afa52f58ab1", "uid": "5e61e44e-cc52-4471-9a41-3afa52f58ab1",
"order": 4, "order": 4,
"description": "background knowledge" "description": "background knowledge"
} }
}, },
{ {
"pk": 192, "pk": 106,
"model": "workflows.abstractwidget", "model": "workflows.abstractwidget",
"fields": { "fields": {
"category": 39, "category": 20,
"treeview_image": "", "treeview_image": "",
"name": "Database To Orange Table", "name": "Database To Orange Table",
"is_streaming": false, "is_streaming": false,
"uid": "baa32a60-5acb-42a1-ba83-23a6ab2160e7", "uid": "baa32a60-5acb-42a1-ba83-23a6ab2160e7",
"interaction_view": "mysql_orange_converter", "interaction_view": "mysql_orange_converter",
"image": "", "image": "",
"package": "mysql", "package": "mysql",
"static_image": "mysql.png", "static_image": "mysql.png",
"post_interact_action": "mysql_orange_converter_finished", "post_interact_action": "mysql_orange_converter_finished",
"user": null, "user": null,
"visualization_view": "", "visualization_view": "",
"action": "mysql_orange_converter", "action": "mysql_orange_converter",
"wsdl_method": "", "wsdl_method": "",
"wsdl": "", "wsdl": "",
"interactive": false, "interactive": false,
"has_progress_bar": false, "has_progress_bar": false,
"order": 1, "order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 445, "pk": 215,
"model": "workflows.abstractinput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 192, "widget": 106,
"name": "context", "name": "context",
"short_name": "cxt", "short_name": "cxt",
"uid": "1f9b5ccf-65c3-4ccc-818e-afb3a6ffee20", "uid": "1f9b5ccf-65c3-4ccc-818e-afb3a6ffee20",
"default": "", "default": "",
"required": true, "required": true,
"multi": false, "multi": false,
"parameter_type": null, "parameter_type": null,
"variable": "context", "variable": "context",
"parameter": false, "parameter": false,
"order": 1, "order": 1,
"description": "Database context object" "description": "Database context object"
} }
}, },
{ {
"pk": 220, "pk": 121,
"model": "workflows.abstractoutput", "model": "workflows.abstractoutput",
"fields": { "fields": {
"widget": 192, "widget": 106,
"name": "Data table", "name": "Data table",
"short_name": "odt", "short_name": "odt",
"variable": "dataset", "variable": "dataset",
"uid": "8dc434fd-3307-432f-b1d7-74638390a077", "uid": "8dc434fd-3307-432f-b1d7-74638390a077",
"order": 1, "order": 1,
"description": "Orange data table" "description": "Orange data table"
} }
}, },
{ {
"pk": 193, "pk": 107,
"model": "workflows.abstractwidget", "model": "workflows.abstractwidget",
"fields": { "fields": {
"category": 39, "category": 20,
"treeview_image": "", "treeview_image": "",
"name": "Database To RSD", "name": "Database To RSD",
"is_streaming": false, "is_streaming": false,
"uid": "e5b68e38-cb53-408a-a58f-26742d6ecb3c", "uid": "e5b68e38-cb53-408a-a58f-26742d6ecb3c",
"interaction_view": "", "interaction_view": "",
"image": "", "image": "",
"package": "mysql", "package": "mysql",
"static_image": "mysql.png", "static_image": "mysql.png",
"post_interact_action": "", "post_interact_action": "",
"user": null, "user": null,
"visualization_view": "", "visualization_view": "",
"action": "mysql_rsd_converter", "action": "mysql_rsd_converter",
"wsdl_method": "", "wsdl_method": "",
"wsdl": "", "wsdl": "",
"interactive": false, "interactive": false,
"has_progress_bar": false, "has_progress_bar": false,
"order": 1, "order": 1,
"description": "" "description": ""
} }
}, },
{ {
"pk": 446, "pk": 216,
"model": "workflows.abstractinput", "model": "workflows.abstractinput",
"fields": { "fields": {
"widget": 193, "widget": 107,
"name": "context", "name": "context",
"short_name": "cxt", "short_name": "cxt",
"uid": "4f1397a8-4e72-4b34-b31d-d09bf9a7e7d9", "uid": "4f1397a8-4e72-4b34-b31d-d09bf9a7e7d9",
"default": "", "default": "",
"required": true, "required": true,
"multi": false, "multi": false,
"parameter_type": null, "parameter_type": null,
"variable": "context", "variable": "context",
"parameter": false, "parameter": false,
"order": 1, "order": 1,
"description": "Database context object" "description": "Database context object"
} }
}, },
{ {
"pk": 221, "pk": 122,
"model": "workflows.abstractoutput", "model": "workflows.abstractoutput",
"fields": { "fields": {