label_transitions.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 2017 Google Inc. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef SYNTAXNET_LABEL_TRANSITIONS_H_
  13. #define SYNTAXNET_LABEL_TRANSITIONS_H_
  14. #include "syntaxnet/parser_state.h"
  15. #include "syntaxnet/parser_transitions.h"
  16. namespace syntaxnet {
  17. // Label transition system. For each token in a sentence, predicts the label of
  18. // the dependency between that token and its head.
  19. class LabelTransitionSystem : public ParserTransitionSystem {
  20. public:
  21. class State; // defined in the .cc file
  22. // There is one type of action: predicting a label.
  23. int NumActionTypes() const override { return 1; }
  24. int NumActions(int num_labels) const override { return num_labels; }
  25. // Returns the default action, which is to assign the root label.
  26. ParserAction GetDefaultAction(const ParserState &state) const override;
  27. // Returns the gold label for the current token of the |state|.
  28. ParserAction GetNextGoldAction(const ParserState &state) const override;
  29. // Returns true if the |action| is allowed for the |state|.
  30. bool IsAllowedAction(ParserAction action,
  31. const ParserState &state) const override;
  32. // Performs the |action| on the |state|, without adding the |action| to the
  33. // |state|'s history.
  34. void PerformActionWithoutHistory(ParserAction action,
  35. ParserState *state) const override;
  36. // Returns true if the |state| is at the end of the input.
  37. bool IsFinalState(const ParserState &state) const override;
  38. // Returns a string representation of performing the |action| on the |state|.
  39. string ActionAsString(ParserAction action,
  40. const ParserState &state) const override;
  41. // Returns a new transition state to be used to enhance the parser state.
  42. ParserTransitionState *NewTransitionState(bool training_mode) const override;
  43. // Returns false, since no states are deterministic.
  44. bool IsDeterministicState(const ParserState &state) const override {
  45. return false;
  46. }
  47. };
  48. } // namespace syntaxnet
  49. #endif // SYNTAXNET_LABEL_TRANSITIONS_H_