/src/im/gpinyin/command/pinyinime_dictbuilder.cpp

http://ftk.googlecode.com/ · C++ · 56 lines · 30 code · 7 blank · 19 comment · 5 complexity · e56f3a96a3c4aa87668e7e46bcfeb443 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <assert.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <time.h>
  20. #include <unistd.h>
  21. #include "../include/dicttrie.h"
  22. using namespace ime_pinyin;
  23. /**
  24. * Build binary dictionary model. Make sure that ___BUILD_MODEL___ is defined
  25. * in dictdef.h.
  26. */
  27. int main(int argc, char* argv[]) {
  28. DictTrie* dict_trie = new DictTrie();
  29. bool success;
  30. if (argc >= 3)
  31. success = dict_trie->build_dict(argv[1], argv[2]);
  32. else
  33. success = dict_trie->build_dict("./data/rawdict_utf16_65105_freq.txt",
  34. "./data/valid_utf16.txt");
  35. if (success) {
  36. printf("Build dictionary successfully.\n");
  37. } else {
  38. printf("Build dictionary unsuccessfully.\n");
  39. return -1;
  40. }
  41. success = dict_trie->save_dict("./dict_pinyin.dat");
  42. if (success) {
  43. printf("Save dictionary successfully.\n");
  44. } else {
  45. printf("Save dictionary unsuccessfully.\n");
  46. return -1;
  47. }
  48. return 0;
  49. }