update dict
[QFreeRecite.git] / src / core / Dict.h
blob9226a383bb68d7480853071d81413d6882de90fe
1 /**
2 * FileName: Dict.h.
3 * Used to define the class Dict which can handle dictionary.
5 * Copyright (C) 2008 Kermit Mei <kermit.mei@gmail.com>
6 * All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation.
22 * Written by Kermit Mei <kermit.mei@gmail.com>
24 * Many of the ideas implemented here are from the author's experiment.
25 * But the dictionary's format coincide with the other word recite software
26 * to help the users get more available data. And the review times designed
27 * by means of the theory named Forgetting Curve which dicoveried by the
28 * German psychologist named Hermann Ebbinghaus(1850–1909).
30 **/
32 #ifndef DICT_HPP
33 #define DICT_HPP
35 #include <map>
36 #include <string>
38 #include "DictItem.h"
40 namespace freeRecite {
42 class Dict;
43 extern Dict dictionary;
45 class Dict
47 public:
48 Dict();
49 ~Dict();
50 //Initialize the dictionary
51 bool load();
53 //Fine the word 'word' in dictionaries
54 bool lookUp(const std::string &word);
56 bool isValid() const
57 { return validFlag; }
59 //Modify the local dictionary.
60 bool modify(const std::string &item);
62 //Merge the local and global dictionaries.
63 bool merge(const char *newDicName);
65 //Save the local dictionary when you modified
66 bool save();
68 //Get the current word
69 const std::string &word() const;
71 //Get the current phonetics
72 const std::string &phonetics() const;
74 //Get the current raw phonetics();
75 const std::string &rawPhonetics() const;
77 //Get the translation
78 const std::string &translation() const;
80 //Get the example
81 const std::string &example()const;
83 //Get the plain text of translation
84 const std::string &plainTranslation() const;
86 private:
87 bool findInGlobl(const std::string &swatch);
88 void setPlainTranslation();
89 bool validFlag;
90 DictItem dictItem;
91 std::string plainTran;
92 std::ifstream *ifsgdic;
93 std::map<std::string,std::string> dict;
96 inline
97 Dict::Dict()
98 : validFlag(false),ifsgdic(0)
99 { /* Do nothing! */ }
101 inline
102 const std::string &Dict::word() const {
103 return dictItem.getW();
106 inline
107 const std::string &Dict::rawPhonetics() const {
108 return dictItem.getT();
111 inline
112 const std::string &Dict::translation()const {
113 return dictItem.getM();
116 inline
117 const std::string &Dict::example()const {
118 return dictItem.getE();
122 inline
123 const std::string &Dict::plainTranslation() const{
124 return plainTran;
129 } // namespace freeRecite end
131 #endif