Commit dfbf46ce authored by Haoyu Z's avatar Haoyu Z
Browse files

debug

parent bd05b7b9
......@@ -74,14 +74,10 @@ def preprocess_query(query, cur, conn):
#fs: [formula1, formula2, ...]
def process_formula(fs, tables):
elements = []
base_formula = ut.baseFormula(fs[0])
for i, formula in enumerate(fs):
nf, idx = ut.remove1sAndAddTablename(formula, tables[i])
elements.append(((nf, idx)))
elements.sort(key=operator.itemgetter(1))
formula_tmp = [x[0] for x in elements]
output = " ".join(formula_tmp)
return output
base_formula = ut.remove1sAndAddTablename(formula, tables[i], base_formula)
return base_formula
def get_header(query):
parsed = sp.parse(query)[0]
......
......@@ -2,52 +2,73 @@ def commitAndExecute(conn, cur, command):
cur.execute(command)
conn.commit()
#find the formula and return it with the index it should be in the real formula
def findFormula(formula):
mylist = ["⊕", "⊗", "⊖", "𝟙"]
# Return formula composed with 𝟙.
def baseFormula(formula):
charset = ["⊕", "⊗", "⊖", "𝟙", " ", "(", ")"]
output = ""
state = "before first character"
idx = 0
for i, char in enumerate(formula):
if (char in mylist or char in ["(", ")", " "]) and state == "before first character":
if char == "𝟙":
idx += 1
continue
state = 0
for c in formula:
if c in charset:
if state == 1:
output = output + "𝟙" + c
state = 0
else:
output = output + c
else:
if state == "after first character":
if char == "𝟙":
break
else:
output += char
if state == 1:
continue
else:
#reach formula
for j in range(i, -1, -1):
if formula[j] == " ":
break
else:
output = formula[j] + output
state = "after first character"
print("find formula", output)
return (output.strip(), idx)
state = 1
return output
def updateBaseFormula(tname, count, base):
charset = ["⊕", "⊗", "⊖", " ", "(", ")"]
output = ""
tmp = 0
state = 0
for i, c in enumerate(base):
if c in charset:
if state == 1:
tmp += 1
state = 0
output += c
continue
elif c == "𝟙":
if tmp == count:
output = output + tname
output = output + base[i+1:]
break
else:
output += c
tmp += 1
else:
if state == 0:
state = 1
output += c
return output
def remove1sAndAddTablename(formula, table):
nf, idx = findFormula(formula)
elements = nf.split(" ")
for i, e in enumerate(elements):
if e in ["⊕", "⊗", "⊖"]:
continue
def remove1sAndAddTablename(formula, table, base):
charset = ["⊕", "⊗", "⊖", " ", "(", ")"]
count = 0
state = 0
tname = ""
for c in formula:
if c in charset:
if state == 1:
state = 0
base = updateBaseFormula(table + "." + tname, count, base)
tname = ""
count += 1
continue
elif c == "𝟙":
count += 1
else:
if "(" in e:
eidx = e.index("(") + 1
ne = e[:eidx] + table + "." + e[eidx:]
elements[i] = ne
else:
ne = table + "." + e
elements[i] = ne
output = " ".join(elements)
return (output.strip(), idx)
if state == 0:
state = 1
tname = tname + c
return base
def compareTwoRows(row1, row2):
for i in range(1, len(row1)-1):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment