62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
/*
|
|
* Copyright (C) 2021 Patrick Goldinger
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "token.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace ime::nlp {
|
|
|
|
Token::Token() : data() {}
|
|
Token::Token(word_t &&_data) : data(std::move(_data)) {}
|
|
|
|
bool operator==(const Token &t1, const Token &t2) {
|
|
return t1.data == t2.data;
|
|
}
|
|
|
|
bool operator!=(const Token &t1, const Token &t2) {
|
|
return !(t1 == t2);
|
|
}
|
|
|
|
WeightedToken::WeightedToken() : Token(), freq(0) {}
|
|
WeightedToken::WeightedToken(word_t &&_data, freq_t _freq) : Token(std::move(_data)), freq(_freq) {}
|
|
|
|
bool operator==(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return t1.data == t2.data && t1.freq == t2.freq;
|
|
}
|
|
|
|
bool operator!=(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return !(t1 == t2);
|
|
}
|
|
|
|
bool operator<(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return t1.freq < t2.freq;
|
|
}
|
|
|
|
bool operator<=(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return t1.freq <= t2.freq;
|
|
}
|
|
|
|
bool operator>(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return t1.freq > t2.freq;
|
|
}
|
|
|
|
bool operator>=(const WeightedToken &t1, const WeightedToken &t2) {
|
|
return t1.freq >= t2.freq;
|
|
}
|
|
|
|
} // namespace ime::nlp
|