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_PREDICTION_PREDICTOR_INTERFACE_H_ 31 #define MOZC_PREDICTION_PREDICTOR_INTERFACE_H_ 32 33 #include <string> 34 35 #include "base/port_string.h" 36 37 namespace mozc { 38 39 class ConversionRequest; 40 class Segments; 41 42 class PredictorInterface { 43 public: 44 virtual ~PredictorInterface() = default; 45 46 // Returns suggestions. 47 // You may need to change the behavior according to the 48 // Segments::request_type flag 49 // SUGGESTION: automatic suggestions 50 // PREDICTION: invoked only when user pushes "tab" key. 51 // less aggressive than SUGGESTION mode. 52 virtual bool PredictForRequest(const ConversionRequest &request, 53 Segments *segments) const = 0; 54 55 // Hook(s) for all mutable operations. Finish(const ConversionRequest & request,Segments * segments)56 virtual void Finish(const ConversionRequest &request, Segments *segments) {} 57 58 // Reverts the last Finish operation. Revert(Segments * segments)59 virtual void Revert(Segments *segments) {} 60 61 // Clears all history data of UserHistoryPredictor. ClearAllHistory()62 virtual bool ClearAllHistory() { return true; } 63 64 // Clears unused history data of UserHistoryPredictor. ClearUnusedHistory()65 virtual bool ClearUnusedHistory() { return true; } 66 67 // Clears a specific history data of UserHistoryPredictor. ClearHistoryEntry(const string & key,const string & value)68 virtual bool ClearHistoryEntry(const string &key, 69 const string &value) { return true; } 70 71 // Syncs user history to local disk. Sync()72 virtual bool Sync() { return true; } 73 74 // Reloads user history data from local disk. Reload()75 virtual bool Reload() { return true; } 76 77 // Waits for syncer thread to complete. Wait()78 virtual bool Wait() { return true; } 79 80 virtual const string &GetPredictorName() const = 0; 81 82 protected: 83 // Disable the construction. 84 PredictorInterface() = default; 85 }; 86 87 } // namespace mozc 88 89 #endif // MOZC_PREDICTION_PREDICTOR_INTERFACE_H_ 90