sentence_input_batch.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "dragnn/io/sentence_input_batch.h"
  16. #include "syntaxnet/sentence.pb.h"
  17. namespace syntaxnet {
  18. namespace dragnn {
  19. void SentenceInputBatch::SetData(
  20. const std::vector<string> &stringified_sentence_protos) {
  21. for (const auto &stringified_proto : stringified_sentence_protos) {
  22. std::unique_ptr<Sentence> sentence(new Sentence);
  23. std::unique_ptr<WorkspaceSet> workspace_set(new WorkspaceSet);
  24. CHECK(sentence->ParseFromString(stringified_proto))
  25. << "Unable to parse string input as syntaxnet.Sentence.";
  26. SyntaxNetSentence aug_sentence(std::move(sentence),
  27. std::move(workspace_set));
  28. data_.push_back(std::move(aug_sentence));
  29. }
  30. }
  31. const std::vector<string> SentenceInputBatch::GetSerializedData() const {
  32. std::vector<string> output_data;
  33. output_data.resize(data_.size());
  34. for (int i = 0; i < data_.size(); ++i) {
  35. data_[i].sentence()->SerializeToString(&(output_data[i]));
  36. }
  37. return output_data;
  38. }
  39. } // namespace dragnn
  40. } // namespace syntaxnet