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_DATA_MANAGER_DATA_MANAGER_INTERFACE_H_
31 #define MOZC_DATA_MANAGER_DATA_MANAGER_INTERFACE_H_
32 
33 #include <string>
34 
35 #include "base/port.h"
36 #include "base/string_piece.h"
37 
38 namespace mozc {
39 
40 // Builds those objects that depend on a set of embedded data generated from
41 // files in data/dictionary, such as dictionary.txt, id.def, etc.
42 class DataManagerInterface {
43  public:
44   virtual ~DataManagerInterface() = default;
45 
46   // Returns data set for UserPOS.
47   virtual void GetUserPOSData(StringPiece *token_array_data,
48                               StringPiece *string_array_data) const = 0;
49 
50   // Returns a reference to POSMatcher class handling POS rules. Don't
51   // delete the returned pointer, which is owned by the manager.
52   virtual const uint16 *GetPOSMatcherData() const = 0;
53 
54   // Returns the address of an array of lid group.
55   virtual const uint8 *GetPosGroupData() const = 0;
56 
57   // Returns the address of connection data and its size.
58   virtual void GetConnectorData(const char **data, size_t *size) const = 0;
59 
60   // Returns the addresses and their sizes necessary to create a segmenter.
61   virtual void GetSegmenterData(
62       size_t *l_num_elements, size_t *r_num_elements,
63       const uint16 **l_table, const uint16 **r_table,
64       size_t *bitarray_num_bytes, const char **bitarray_data,
65       const uint16 **boundary_data) const = 0;
66 
67   // Returns the address of system dictionary data and its size.
68   virtual void GetSystemDictionaryData(const char **data, int *size) const = 0;
69 
70   // Returns the array containing keys, values, and token (lid, rid, cost).
71   virtual void GetSuffixDictionaryData(StringPiece *key_array,
72                                        StringPiece *value_array,
73                                        const uint32 **token_array) const = 0;
74 
75   // Gets a reference to reading correction data array and its size.
76   virtual void GetReadingCorrectionData(
77       StringPiece *value_array_data, StringPiece *error_array_data,
78       StringPiece *correction_array_data) const = 0;
79 
80   // Gets the address of collocation data array and its size.
81   virtual void GetCollocationData(const char **array, size_t *size) const = 0;
82 
83   // Gets the address of collocation suppression data array and its size.
84   virtual void GetCollocationSuppressionData(const char **array,
85                                              size_t *size) const = 0;
86 
87   // Gets an address of suggestion filter data array and its size.
88   virtual void GetSuggestionFilterData(const char **data,
89                                        size_t *size) const = 0;
90 
91   // Gets an address of symbol rewriter data array and its size.
92   virtual void GetSymbolRewriterData(StringPiece *token_array_data,
93                                      StringPiece *string_array_data) const = 0;
94 
95   // Gets an address of symbol rewriter data array and its size.
96   virtual void GetEmoticonRewriterData(
97       StringPiece *token_array_data, StringPiece *string_array_data) const = 0;
98 
99   // Gets EmojiRewriter data.
100   virtual void GetEmojiRewriterData(
101       StringPiece *token_array_data, StringPiece *string_array_data) const = 0;
102 
103   // Gets SingleKanjiRewriter data.
104   virtual void GetSingleKanjiRewriterData(
105       StringPiece *token_array_data,
106       StringPiece *string_array_data,
107       StringPiece *variant_type_array_data,
108       StringPiece *variant_token_array_data,
109       StringPiece *variant_string_array_data,
110       StringPiece *noun_prefix_token_array_data,
111       StringPiece *noun_prefix_string_array_data) const = 0;
112 
113 #ifndef NO_USAGE_REWRITER
114   // Gets the usage rewriter data.
115   virtual void GetUsageRewriterData(
116       StringPiece *base_conjugation_suffix_data,
117       StringPiece *conjugation_suffix_data,
118       StringPiece *conjugation_suffix_index_data,
119       StringPiece *usage_items_data,
120       StringPiece *string_array_data) const = 0;
121 #endif  // NO_USAGE_REWRITER
122 
123   // Gets the address and size of a sorted array of counter suffix values.
124   virtual void GetCounterSuffixSortedArray(const char **array,
125                                            size_t *size) const = 0;
126 
127   // Gets the zero query prediction data.
128   virtual void GetZeroQueryData(
129       StringPiece *zero_query_token_array_data,
130       StringPiece *zero_query_string_array_data,
131       StringPiece *zero_query_number_token_array_data,
132       StringPiece *zero_query_number_string_array_data) const = 0;
133 
134   // Gets the typing model binary data for the specified name.
135   virtual StringPiece GetTypingModel(const string &name) const = 0;
136 
137   // Gets the data version string.
138   virtual StringPiece GetDataVersion() const = 0;
139 
140  protected:
141   DataManagerInterface() = default;
142 
143  private:
144   DISALLOW_COPY_AND_ASSIGN(DataManagerInterface);
145 };
146 
147 }  // namespace mozc
148 
149 #endif  // MOZC_DATA_MANAGER_DATA_MANAGER_INTERFACE_H_
150