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_SUFFIX_DICTIONARY_H_
31 #define MOZC_DICTIONARY_SUFFIX_DICTIONARY_H_
32 
33 #include "base/port.h"
34 #include "base/serialized_string_array.h"
35 #include "base/string_piece.h"
36 #include "dictionary/dictionary_interface.h"
37 
38 namespace mozc {
39 namespace dictionary {
40 
41 // SuffixDictionary is a special dictionary which handles
42 // Japanese bunsetsu suffixes.
43 //
44 // Japanese bunsetsu consists of two parts.
45 // Content words: ("自立語") and Functional words ("付属語")
46 // Japanese Bunsets = (Content word){1,1}(Functional words){1,}
47 //
48 // Suffix dictionary contains sequences of functional words
49 // frequently appear on the web.
50 // When user inputs a content word, we can predict an appropriate
51 // functional word with this dictionary.
52 class SuffixDictionary : public DictionaryInterface {
53  public:
54   SuffixDictionary(StringPiece key_array_data, StringPiece value_array_data,
55                    const uint32 *token_array);
56   ~SuffixDictionary() override;
57 
58   bool HasKey(StringPiece key) const override;
59   bool HasValue(StringPiece value) const override;
60 
61   // Kana modifier insensitive lookup is not supported.
62   void LookupPredictive(StringPiece key,
63                         const ConversionRequest &conversion_request,
64                         Callback *callback) const override;
65 
66   // SuffixDictionary doesn't support Prefix/Revese/Exact Lookup.
67   void LookupPrefix(StringPiece key,
68                     const ConversionRequest &conversion_request,
69                     Callback *callback) const override;
70 
71   void LookupExact(StringPiece key, const ConversionRequest &conversion_request,
72                    Callback *callback) const override;
73 
74   void LookupReverse(StringPiece str,
75                      const ConversionRequest &conversion_request,
76                      Callback *callback) const override;
77 
78  private:
79   SerializedStringArray key_array_;
80   SerializedStringArray value_array_;
81   const uint32 *token_array_;
82 
83   DISALLOW_COPY_AND_ASSIGN(SuffixDictionary);
84 };
85 
86 }  // namespace dictionary
87 }  // namespace mozc
88 
89 #endif  // MOZC_DICTIONARY_SUFFIX_DICTIONARY_H_
90