bdict_writer.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef THIRD_PARTY_HUNSPELL_GOOGLE_BDICT_WRITER_H_
  5. #define THIRD_PARTY_HUNSPELL_GOOGLE_BDICT_WRITER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/macros.h"
  9. namespace hunspell {
  10. class DicNode;
  11. // Class for creating a binary dictionary file from data read from Hunspell
  12. // spellchecker files.
  13. class BDictWriter {
  14. public:
  15. typedef std::vector< std::pair<std::string, std::vector<int> > > WordList;
  16. BDictWriter();
  17. ~BDictWriter();
  18. // Affix setters.
  19. void SetComment(const std::string& comment) {
  20. comment_ = comment;
  21. }
  22. void SetAffixRules(const std::vector<std::string>& rules) {
  23. affix_rules_ = rules;
  24. }
  25. void SetAffixGroups(const std::vector<std::string>& groups) {
  26. affix_groups_ = groups;
  27. }
  28. void SetReplacements(
  29. const std::vector< std::pair<std::string, std::string> >& replacements) {
  30. replacements_ = replacements;
  31. }
  32. void SetOtherCommands(const std::vector<std::string>& commands) {
  33. other_commands_ = commands;
  34. }
  35. // The words must be sorted already.
  36. void SetWords(const WordList& words);
  37. // Returns the serialized data for the entire file. You must call all the
  38. // setters above before this.
  39. std::string GetBDict() const;
  40. private:
  41. // Converts the affix members to a string.
  42. void SerializeAff(std::string* output) const;
  43. // Affix members.
  44. std::string comment_;
  45. std::vector<std::string> affix_rules_;
  46. std::vector<std::string> affix_groups_;
  47. std::vector< std::pair<std::string, std::string> > replacements_;
  48. std::vector<std::string> other_commands_;
  49. // Root of the generated trie. Filled by SetWords.
  50. DicNode* trie_root_;
  51. DISALLOW_COPY_AND_ASSIGN(BDictWriter);
  52. };
  53. } // namespace hunspell
  54. #endif // THIRD_PARTY_HUNSPELL_GOOGLE_BDICT_WRITER_H_