Skip to content

Instantly share code, notes, and snippets.

@ashunigion
Last active February 21, 2019 20:08
Show Gist options
  • Select an option

  • Save ashunigion/da5a7a2c53b7e0e652acb93bcba1a695 to your computer and use it in GitHub Desktop.

Select an option

Save ashunigion/da5a7a2c53b7e0e652acb93bcba1a695 to your computer and use it in GitHub Desktop.
# sentence :The sentence to be parsed as a list of words.
self.stack = ["ROOT"] # corresponds to first column in above image
self.buffer = (self.sentence).copy() # corresponds to second column in above image
self.dependencies = [] # corresponds to the third column in above image
# transition (str): A string that equals "S", "LA", or "RA" representing the shift,
# left-arc, and right-arc transitions. You can assume the provided
# transition is a legal transition.
# corresponds to the last column in above image
if transition == "S":
self.stack.append(self.buffer.pop(0))
elif transition == "LA":
self.dependencies.append((self.stack[-1],self.stack[-2]))
self.stack.pop(-2)
elif transition == "RA":
self.dependencies.append((self.stack[-2],self.stack[-1]))
self.stack.pop(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment