1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LATINIME_UNIGRAM_PROPERTY_H
18#define LATINIME_UNIGRAM_PROPERTY_H
19
20#include <vector>
21
22#include "defines.h"
23#include "dictionary/property/historical_info.h"
24
25namespace latinime {
26
27class UnigramProperty {
28 public:
29    class ShortcutProperty {
30     public:
31        ShortcutProperty(const std::vector<int> &&targetCodePoints, const int probability)
32                : mTargetCodePoints(std::move(targetCodePoints)),
33                  mProbability(probability) {}
34
35        const std::vector<int> *getTargetCodePoints() const {
36            return &mTargetCodePoints;
37        }
38
39        int getProbability() const {
40            return mProbability;
41        }
42
43     private:
44        // Default copy constructor is used for using in std::vector.
45        DISALLOW_DEFAULT_CONSTRUCTOR(ShortcutProperty);
46
47        const std::vector<int> mTargetCodePoints;
48        const int mProbability;
49    };
50
51    UnigramProperty()
52            : mRepresentsBeginningOfSentence(false), mIsNotAWord(false),
53              mIsBlacklisted(false), mIsPossiblyOffensive(false), mProbability(NOT_A_PROBABILITY),
54              mHistoricalInfo(), mShortcuts() {}
55
56    // In contexts which do not support the Blacklisted flag (v2, v4<403)
57    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
58            const bool isPossiblyOffensive, const int probability,
59            const HistoricalInfo historicalInfo, const std::vector<ShortcutProperty> &&shortcuts)
60            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
61              mIsNotAWord(isNotAWord), mIsBlacklisted(false),
62              mIsPossiblyOffensive(isPossiblyOffensive), mProbability(probability),
63              mHistoricalInfo(historicalInfo), mShortcuts(std::move(shortcuts)) {}
64
65    // Without shortcuts, in contexts which do not support the Blacklisted flag (v2, v4<403)
66    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
67            const bool isPossiblyOffensive, const int probability,
68            const HistoricalInfo historicalInfo)
69            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
70              mIsNotAWord(isNotAWord), mIsBlacklisted(false),
71              mIsPossiblyOffensive(isPossiblyOffensive), mProbability(probability),
72              mHistoricalInfo(historicalInfo), mShortcuts() {}
73
74    // In contexts which DO support the Blacklisted flag (v403)
75    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
76            const bool isBlacklisted, const bool isPossiblyOffensive, const int probability,
77            const HistoricalInfo historicalInfo, const std::vector<ShortcutProperty> &&shortcuts)
78            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
79              mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted),
80              mIsPossiblyOffensive(isPossiblyOffensive), mProbability(probability),
81              mHistoricalInfo(historicalInfo), mShortcuts(std::move(shortcuts)) {}
82
83    // Without shortcuts, in contexts which DO support the Blacklisted flag (v403)
84    UnigramProperty(const bool representsBeginningOfSentence, const bool isNotAWord,
85            const bool isBlacklisted, const bool isPossiblyOffensive, const int probability,
86            const HistoricalInfo historicalInfo)
87            : mRepresentsBeginningOfSentence(representsBeginningOfSentence),
88              mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted),
89              mIsPossiblyOffensive(isPossiblyOffensive), mProbability(probability),
90              mHistoricalInfo(historicalInfo), mShortcuts() {}
91
92    bool representsBeginningOfSentence() const {
93        return mRepresentsBeginningOfSentence;
94    }
95
96    bool isNotAWord() const {
97        return mIsNotAWord;
98    }
99
100    bool isPossiblyOffensive() const {
101        return mIsPossiblyOffensive;
102    }
103
104    bool isBlacklisted() const {
105        return mIsBlacklisted;
106    }
107
108    bool hasShortcuts() const {
109        return !mShortcuts.empty();
110    }
111
112    int getProbability() const {
113        return mProbability;
114    }
115
116    const HistoricalInfo getHistoricalInfo() const {
117        return mHistoricalInfo;
118    }
119
120    const std::vector<ShortcutProperty> &getShortcuts() const {
121        return mShortcuts;
122    }
123
124 private:
125    // Default copy constructor is used for using as a return value.
126    DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty);
127
128    const bool mRepresentsBeginningOfSentence;
129    const bool mIsNotAWord;
130    const bool mIsBlacklisted;
131    const bool mIsPossiblyOffensive;
132    const int mProbability;
133    const HistoricalInfo mHistoricalInfo;
134    const std::vector<ShortcutProperty> mShortcuts;
135};
136} // namespace latinime
137#endif // LATINIME_UNIGRAM_PROPERTY_H
138