1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef MOZC_DICTIONARY_USER_POS_INTERFACE_H_
31 #define MOZC_DICTIONARY_USER_POS_INTERFACE_H_
32 
33 #include <string>
34 #include <vector>
35 
36 #include "base/port.h"
37 
38 namespace mozc {
39 
40 // Provides a list of part-of-speech (POS) used by Mozc.  This minimal interface
41 // is used by GUI tools so that we can minimize the data embedded in
42 // executables.
43 class POSListProviderInterface {
44  public:
45   virtual ~POSListProviderInterface() = default;
46 
47   // Sets posssible list of POS which Mozc can handle.
48   virtual void GetPOSList(std::vector<string> *pos_list) const = 0;
49 
50  protected:
51   POSListProviderInterface() = default;
52 
53  private:
54   DISALLOW_COPY_AND_ASSIGN(POSListProviderInterface);
55 };
56 
57 // Interface of the helper class used by POS.
58 class UserPOSInterface : public POSListProviderInterface {
59  public:
60   struct Token {
61     string key;
62     string value;
63     uint16 id;
64     int16  cost;
65     string comment;  // This field comes from user dictionary.
66   };
67 
68   virtual ~UserPOSInterface() = default;
69 
70   // Returns true if the given string is one of the POSes Mozc can handle.
71   virtual bool IsValidPOS(const string &pos) const = 0;
72 
73   // Returns iid from Mozc POS. If the pos has inflection, this method only
74   // returns the ids of base form.
75   virtual bool GetPOSIDs(const string &pos, uint16 *id) const = 0;
76 
77   // Converts the given tuple (key, value, pos) to Token.  If the pos has
78   // inflection, this function expands possible inflections automatically.
79   virtual bool GetTokens(const string &key,
80                          const string &value,
81                          const string &pos,
82                          std::vector<Token> *tokens) const = 0;
83 
84  protected:
85   UserPOSInterface() = default;
86 
87  private:
88   DISALLOW_COPY_AND_ASSIGN(UserPOSInterface);
89 };
90 
91 }  // namespace mozc
92 
93 #endif  // MOZC_DICTIONARY_USER_POS_INTERFACE_H_
94