Spaces:
Sleeping
Sleeping
Update app.py
#16
by olcapone - opened
298 unmodified lines299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388298 unmodified lines return m.group(1).strip() return None
def _parse_op_table_from_text(self, text: str): """ Parse a Markdown table like: |*|a|b|c| |---|---|---|---| |a|a|b|c| |b|b|c|a| |c|c|a|b| Returns (S, T) where S is a list of symbols, and T is a dict-of-dicts T[row][col] = result. """ if not text: return None lines = [ln.strip() for ln in text.splitlines() if "|" in ln] if not lines: return None
# find header line (the one starting with |*|) header = None for ln in lines: cells = [c.strip() for c in ln.strip("|").split("|")] if cells and cells[0] in {"*", "∗"}: header = cells break if not header: return None symbols = header[1:] if not symbols: return None
# build table from subsequent lines that look like rows T = {r: {} for r in symbols} for ln in lines: cells = [c.strip() for c in ln.strip("|").split("|")] if not cells or cells[0] not in symbols: continue row = cells[0] vals = cells[1:] if len(vals) != len(symbols): continue for col, val in zip(symbols, vals): T[row][col] = val
# sanity: ensure all rows present if any(r not in T or len(T[r]) != len(symbols) for r in symbols): return None
return symbols, T
def _find_identity(self, S, T): # two-sided identity e satisfies e*x = x and x*e = x for all x for e in S: if all(T[e][x] == x for x in S) and all(T[x][e] == x for x in S): return e return None
def _is_commutative(self, S, T): for x in S: for y in S: if T[x][y] != T[y][x]: return False return True
def _is_associative(self, S, T): for x in S: for y in S: for z in S: if T[T[x][y]][z] != T[x][T[y][z]]: return False return True
def _inverse_of(self, x, S, T, e): if e is None: return None for y in S: if T[x][y] == e and T[y][x] == e: return y return None
def _idempotents(self, S, T): return [x for x in S if T[x][x] == x] def _answer_from_op_table(self, question: str, table_text: str): parsed = self._parse_op_table_from_text(table_text)app.py+84