def parse(self): '''CKY parsing.''' span = defaultdict(set) tree = {} for i in range(len(self)): span[i, i] = {Result(self.pres[i])} for step in range(1, len(self)): for i in range(len(self) - step): k = i + step for j in range(i + 1, k + 1): for x in span[i, j - 1]: for y in span[j, k]: res = x + y for r in res: if r not in tree: tree[r] = (x, y) span[i, k].update(res) if not Result._earlyCollapse: span[0, len(self) - 1] = {r.collapse() for r in span[0, len(self) - 1]} if self._matchCon: for r in span[0, len(self) - 1]: r.links |= catIden(r.cat, self.con)[1] self._proofSpan = span self._tree = tree
def _lowering(s:str): a, d, e = towerSplit(s) if not d: return a, frozenset() else: c, pairs = Result._lowering(a) iden, more = catIden(c, e) if iden: return d, pairs | more else: c = addHypo(e, '^', c) c = addHypo(d, '!', c) return c, pairs
def cellAppl(xlist, ylist, i, j, slash): if i < len(xlist) - 1: if xlist[i + 1][1] == slash: iden, pairs = catIden(xlist[i + 1][2], ylist[j][0]) if iden: cat = propogate(xlist, ylist, i, j, xlist[i + 1][0]) return {Result(cat, pairs)} if j == len(ylist) - 1: c, a, b = towerSplit(ylist[j][0]) if a: if slash == '/': res = reduce(Result(xlist[i][0]), Result(c)) elif slash == '\\': res = reduce(Result(c), Result(xlist[i][0])) for r in res: r.cat = addHypo(b, '^', r.cat) r.cat = addHypo(a, '!', r.cat) if r._earlyCollapse: r.collapse() r.cat = propogate(xlist, ylist, i, j, r.cat) return {r for r in res} return set()
def islandDiv(slash, left, right, islands=Islands): if slash == '/': return any(catIden(right, i)[0] for i in islands) elif slash == '\\': return any(catIden(left, i)[0] for i in islands)
def proofs(self): return list(filter(lambda r: catIden(r.cat, self.con)[0], self.allProofs))