Spaces:
Sleeping
Sleeping
Update app.py
Browse files298 unmodified lines299300301302303304298 unmodified linesreturn m.group(1).strip()return Nonedef _answer_from_op_table(self, question: str, table_text: str):parsed = self._parse_op_table_from_text(table_text)298 unmodified lines299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388298 unmodified linesreturn m.group(1).strip()return Nonedef _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, andT is a dict-of-dicts T[row][col] = result."""if not text:return Nonelines = [ln.strip() for ln in text.splitlines() if "|" in ln]if not lines:return None# find header line (the one starting with |*|)header = Nonefor ln in lines:cells = [c.strip() for c in ln.strip("|").split("|")]if cells and cells[0] in {"*", "∗"}:header = cellsbreakif not header:return Nonesymbols = header[1:]if not symbols:return None# build table from subsequent lines that look like rowsT = {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:continuerow = cells[0]vals = cells[1:]if len(vals) != len(symbols):continuefor col, val in zip(symbols, vals):T[row][col] = val# sanity: ensure all rows presentif any(r not in T or len(T[r]) != len(symbols) for r in symbols):return Nonereturn symbols, Tdef _find_identity(self, S, T):# two-sided identity e satisfies e*x = x and x*e = x for all xfor e in S:if all(T[e][x] == x for x in S) and all(T[x][e] == x for x in S):return ereturn Nonedef _is_commutative(self, S, T):for x in S:for y in S:if T[x][y] != T[y][x]:return Falsereturn Truedef _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 Falsereturn Truedef _inverse_of(self, x, S, T, e):if e is None:return Nonefor y in S:if T[x][y] == e and T[y][x] == e:return yreturn Nonedef _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