Ejemplo n.º 1
0
class ExceptPropbankEvokeDelegate(SoftmaxDelegate):
  def build(self, cascade, actions):
    """Build table of actions handled by the delegate."""
    self.table = Actions()
    for action in actions.table:
      if action.type != Action.SHIFT and \
        action.type != Action.MARK and not is_pbevoke(action):
        self.table.add(action)
    self.softmax_size = self.table.size() + 1  # +1 for CASCADE action
    self.pb_index = self.table.size()          # last action is CASCADE

    # Assume we will delegate PropBank EVOKES to PropbankEvokeDelegate.
    self.pb_action = Action(Action.CASCADE)
    self.pb_action.delegate = cascade.index_of("PropbankEvokeDelegate")

  def translate(self, action, output):
    if is_pbevoke(action):
      output.append(self.pb_action)
    else:
      output.append(action)

  def index(self, action):
    if action.is_cascade() and action.delegate == self.pb_action.delegate:
      return self.pb_index
    return self.table.index(action)

  def action(self, index, previous_action):
    if index == self.pb_index:
      return self.pb_action
    return self.table.action(index)
Ejemplo n.º 2
0
class PropbankEvokeDelegate(SoftmaxDelegate):
  def build(self, cascade, actions):
    self.table = Actions()
    for action in actions.table:
      if is_pbevoke(action): self.table.add(action)
    self.softmax_size = self.table.size()

  def translate(self, action, output):
    output.append(action)

  def index(self, action):
    return self.table.index(action)

  def action(self, index, previous_action):
    return self.table.action(index)