transition_state.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // =============================================================================
  15. #ifndef NLP_SAFT_OPENSOURCE_DRAGNN_CORE_INTERFACES_TRANSITION_STATE_H_
  16. #define NLP_SAFT_OPENSOURCE_DRAGNN_CORE_INTERFACES_TRANSITION_STATE_H_
  17. #include <memory>
  18. #include <vector>
  19. #include "syntaxnet/base.h"
  20. namespace syntaxnet {
  21. namespace dragnn {
  22. // TransitionState defines the minimal interface required to pass data between
  23. // Component objects. It is used to initialize one Component from the output of
  24. // another, and every backend should define one. Note that inheriting from
  25. // TransitionState directly is not sufficient to use the Beam class, which
  26. // requires extra functionality given by inheriting from the
  27. // ClonableTransitionState interface. (ClonableTransitionState is a subclass
  28. // of TransitionState, so inheriting from ClonableTransitionState is sufficient
  29. // to allow Components to pass your backing states.)
  30. class TransitionState {
  31. public:
  32. virtual ~TransitionState() {}
  33. // Initialize this TransitionState from a previous TransitionState. The
  34. // ParentBeamIndex is the location of that previous TransitionState in the
  35. // provided beam.
  36. virtual void Init(const TransitionState &parent) = 0;
  37. // Return the beam index of the state passed into the initializer of this
  38. // TransitionState.
  39. virtual const int ParentBeamIndex() const = 0;
  40. // Get the current beam index for this state.
  41. virtual const int GetBeamIndex() const = 0;
  42. // Set the current beam index for this state.
  43. virtual void SetBeamIndex(const int index) = 0;
  44. // Get the score associated with this transition state.
  45. virtual const float GetScore() const = 0;
  46. // Set the score associated with this transition state.
  47. virtual void SetScore(const float score) = 0;
  48. // Depicts this state as an HTML-language string.
  49. virtual string HTMLRepresentation() const = 0;
  50. };
  51. } // namespace dragnn
  52. } // namespace syntaxnet
  53. #endif // NLP_SAFT_OPENSOURCE_DRAGNN_CORE_INTERFACES_TRANSITION_STATE_H_