Skip to content

Commit

Permalink
minor tweak to earley
Browse files Browse the repository at this point in the history
  • Loading branch information
timvieira committed Jun 18, 2024
1 parent dcb0333 commit c922f37
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions genparse/experimental/earley.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,7 @@ def PREDICT(self, col):
rhs = self.rhs
for X in reachable:
for w, Ys in rhs.get(X, ()):
item = (k, X, Ys)
was = col_chart.get(item)
if was is None:
Y = self.first_Ys[Ys]
col_waiting_for[Y].add(item)
col_chart[item] = w
else:
col_chart[item] = was + w
self._update(col, k, X, Ys, w)

def _update(self, col, I, X, Ys, value):
K = col.k
Expand Down Expand Up @@ -287,15 +280,18 @@ def next_token_weights(self, cols):
for (I, X, Ys) in col_waiting_for[Y]:
if self.unit_Ys[Ys]:
node = (I, X)
value = q.get(node)
if value is None:
value = self._helper(node, cols, q)
value = self._helper(node, cols, q)
total += col_i_chart[I, X, Ys] * value
p[Y] = total

return p

def _helper(self, top, cols, q):

value = q.get(top)
if value is not None:
return value

zero = self.cfg.R.zero
stack = [Node(top, None, zero)]

Expand Down

0 comments on commit c922f37

Please sign in to comment.