Skip to content

Commit

Permalink
Changed Evaluation-> Execution in SQL mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Senna committed May 26, 2023
1 parent fd4ac01 commit ecd47c9
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 648 deletions.
2 changes: 1 addition & 1 deletion das/database/redis_mongo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .db_interface import DBInterface, WILDCARD, UNORDERED_LINK_TYPES

USE_CACHED_NODES = False
USE_CACHED_NODES = True
USE_CACHED_LINK_TYPES = True
USE_CACHED_NODE_TYPES = True

Expand Down
7 changes: 2 additions & 5 deletions environment
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Redis variables
export DAS_REDIS_HOSTNAME=localhost
export DAS_REDIS_PORT=6380
# MongoDB variables
export DAS_REDIS_HOSTNAME=45.32.140.218
export DAS_REDIS_PORT=7000
export DAS_MONGODB_HOSTNAME=149.28.201.61
export DAS_MONGODB_PORT=27018
# Change the following values when running on a public instance
export DAS_DATABASE_USERNAME=dbadmin
export DAS_DATABASE_PASSWORD=dassecret
8 changes: 0 additions & 8 deletions environment_cluster

This file was deleted.

8 changes: 0 additions & 8 deletions environment_das

This file was deleted.

62 changes: 19 additions & 43 deletions flybase2metta/sql_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ def _file_line_count(file_name):

class AtomTypes(str, Enum):
CONCEPT = "Concept"
PREDICATE = "Predicate"
SCHEMA = "Schema"
NUMBER = "Number"
VERBATIM = "Verbatim"
INHERITANCE = "Inheritance"
EVALUATION = "Evaluation"
EXECUTION = "Execution"
LIST = "List"

TYPED_NAME = [AtomTypes.CONCEPT, AtomTypes.PREDICATE, AtomTypes.SCHEMA]
TYPED_NAME = [AtomTypes.CONCEPT, AtomTypes.SCHEMA]

CREATE_TABLE_PREFIX = "CREATE TABLE "
CREATE_TABLE_SUFFIX = ");"
Expand All @@ -77,8 +75,8 @@ def filter_field(line):
"timestamp" in line or \
"CONSTRAINT" in line

def _compose_name(name1, name2):
return f"{name1}_{name2}"
def _compose_name(str_list):
return "_".join(str_list)

def short_name(long_table_name):
return long_table_name.split(".")[1] if long_table_name is not None else None
Expand Down Expand Up @@ -169,28 +167,6 @@ def _open_new_output_file(self):
self.current_output_file = open(fname, "w")
self._emit_file_header()

#def _emit_precomputed_tables(self, output_file):
# self.log_precomputed_nodes = True
# for table in self.precomputed.all_tables:
# #print(table)
# for row in table.rows:
# #print(row)
# for key1, value1 in zip(table.header, row):
# if key1 not in table.mapped_fields:
# #print(f"key1: {key1} not in table.mapped_fields")
# continue
# sql_table1, sql_field1 = table.mapping[key1]
# node1 = self._add_value_node(short_name(sql_table1), self._get_type(sql_table1, sql_field1), value1)
# #print("1:", node1)
# for key2, value2 in zip(table.header, row):
# if key2 != key1:
# sql_table2, sql_field2 = table.mapping[key2] if key2 in table.mapping else (None, None)
# node2 = self._add_value_node(short_name(sql_table2), self._get_type(sql_table2, sql_field2), value2)
# #print("2:", node2)
# schema = self._add_node(AtomTypes.SCHEMA, key2)
# self._add_execution(schema, node1, node2)
# self.log_precomputed_nodes = False

def _emit_precomputed_tables(self, output_file):
self.log_precomputed_nodes = True
table_count = 0
Expand All @@ -211,12 +187,12 @@ def _emit_precomputed_tables(self, output_file):
sql_table2, sql_field2 = table.mapping[key2] if key2 in table.mapping else (None, None)
node2 = self._add_value_node(short_name(sql_table2), self._get_type(sql_table2, sql_field2), value2)
#print("2:", node2)
schema = self._add_node(AtomTypes.SCHEMA, key2)
schema = self._add_node(AtomTypes.SCHEMA, _compose_name(["preref", table.name, key2]))
self._add_execution(schema, node1, node2)
for key1, value1 in zip(table.header, row):
for key2, value2 in zip(table.header, row):
if key2 != key1:
schema = self._add_node(AtomTypes.SCHEMA, f"{table.name}.{key2}")
schema = self._add_node(AtomTypes.SCHEMA, _compose_name(["pre", table.name, key2]))
node1 = self._add_node(AtomTypes.VERBATIM, value1)
node2 = self._add_node(AtomTypes.VERBATIM, value2)
self._add_execution(schema, node1, node2)
Expand Down Expand Up @@ -327,12 +303,12 @@ def _add_inheritance(self, node1, node2):
self.current_link_list.append(f"({AtomTypes.INHERITANCE} {node1} {node2})")
self.expression_chunk_count += 1

def _add_evaluation(self, predicate, node1, node2):
# metta
#print(f"add_evaluation {predicate} {node1} {node2}")
if predicate and node1 and node2:
self.current_link_list.append(f"({AtomTypes.EVALUATION} {predicate} ({AtomTypes.LIST} {node1} {node2}))")
self.expression_chunk_count += 1
#def _add_evaluation(self, predicate, node1, node2):
# # metta
# #print(f"add_evaluation {predicate} {node1} {node2}")
# if predicate and node1 and node2:
# self.current_link_list.append(f"({AtomTypes.EVALUATION} {predicate} ({AtomTypes.LIST} {node1} {node2}))")
# self.expression_chunk_count += 1

def _add_execution(self, schema, node1, node2):
# metta
Expand Down Expand Up @@ -408,17 +384,17 @@ def _new_row_relevant_fkeys(self, line):
continue
if name in fkeys:
referenced_table, referenced_field = table['foreign_key'][name]
predicate_node = self._add_node(AtomTypes.PREDICATE, referenced_table)
fkey_node = self._add_node(AtomTypes.CONCEPT, _compose_name(referenced_table, value))
self._add_evaluation(predicate_node, pkey_node, fkey_node)
schema_node = self._add_node(AtomTypes.SCHEMA, referenced_table)
fkey_node = self._add_node(AtomTypes.CONCEPT, _compose_name(["fwfk", referenced_table, value]))
self._add_execution(schema_node, pkey_node, fkey_node)
elif name != pkey:
ftype = self.current_field_types.get(name, None)
if not ftype:
continue
value_node = self._add_value_node(table_short_name, ftype, value)
if not value_node:
continue
schema_node = self._add_node(AtomTypes.SCHEMA, _compose_name(table_short_name, name))
schema_node = self._add_node(AtomTypes.SCHEMA, _compose_name(["fw", table_short_name, name]))
self._add_execution(schema_node, pkey_node, value_node)

def _new_row(self, line):
Expand Down Expand Up @@ -462,17 +438,17 @@ def _new_row(self, line):
if referenced_table not in self.relevant_fkeys:
self.relevant_fkeys[referenced_table] = set()
self.relevant_fkeys[referenced_table].add(value)
predicate_node = self._add_node(AtomTypes.PREDICATE, referenced_table)
fkey_node = self._add_node(AtomTypes.CONCEPT, _compose_name(referenced_table, value))
self._add_evaluation(predicate_node, pkey_node, fkey_node)
schema_node = self._add_node(AtomTypes.SCHEMA, _compose_name(["sqlfk", referenced_table]))
fkey_node = self._add_node(AtomTypes.CONCEPT, _compose_name([referenced_table, value]))
self._add_execution(schema_node, pkey_node, fkey_node)
elif name != pkey:
ftype = self.current_field_types.get(name, None)
if not ftype:
continue
value_node = self._add_value_node(table_short_name, ftype, value)
if not value_node:
continue
schema_node = self._add_node(AtomTypes.SCHEMA, _compose_name(table_short_name, name))
schema_node = self._add_node(AtomTypes.SCHEMA, _compose_name(["sql", table_short_name, name]))
self._add_execution(schema_node, pkey_node, value_node)

def _primary_key(self, first_line, second_line):
Expand Down
Loading

0 comments on commit ecd47c9

Please sign in to comment.