- name: Test
working-directory: ${{github.workspace}}/build
- run: ctest -C Release
+ run: ctest -C Release --output-on-failure
- name: Package
working-directory: ${{github.workspace}}/build
private:
bool die_;
};
-
-template <typename T>
-T &&CheckNotNull(const char *file, int line, const char *exprtext, T &&t) {
- if (t == nullptr) {
- std::cerr << file << "(" << line << ") " << exprtext;
- Abort();
- }
- return std::forward<T>(t);
-}
} // namespace error
namespace logging {
#define CHECK_LE(a, b) CHECK((a) <= (b))
#define CHECK_GT(a, b) CHECK((a) > (b))
#define CHECK_LT(a, b) CHECK((a) < (b))
-#define CHECK_NOTNULL(val) \
- ::sentencepiece::error::CheckNotNull( \
- ::sentencepiece::logging::BaseName(__FILE__), __LINE__, \
- "'" #val "' Must be non NULL", (val))
#define FRIEND_TEST(a, b) friend class a##_Test_##b;
// See the License for the specific language governing permissions and
// limitations under the License.!
+#include "normalizer.h"
+
#include <utility>
#include <vector>
#include "common.h"
-#include "normalizer.h"
#include "third_party/absl/memory/memory.h"
#include "third_party/absl/strings/match.h"
#include "third_party/absl/strings/string_view.h"
void Normalizer::Init() {
absl::string_view index = spec_->precompiled_charsmap();
- if (index.empty()) {
- LOG(INFO) << "precompiled_charsmap is empty. use identity normalization.";
- } else {
+ if (!index.empty()) {
absl::string_view trie_blob, normalized;
#ifdef IS_BIG_ENDIAN
status_ = DecodePrecompiledCharsMap(index, &trie_blob, &normalized,
const SentencePieceText_SentencePiece &sp)
: sp_(&sp) {}
-absl::string_view ImmutableSentencePieceText::ImmutableSentencePiece::piece()
+const std::string &ImmutableSentencePieceText::ImmutableSentencePiece::piece()
const {
return sp_->piece();
}
-absl::string_view ImmutableSentencePieceText::ImmutableSentencePiece::surface()
+const std::string &ImmutableSentencePieceText::ImmutableSentencePiece::surface()
const {
return sp_->surface();
}
spt_->pieces(index));
}
-absl::string_view ImmutableSentencePieceText::text() const {
- return spt_ ? spt_->text() : "";
+const std::string &ImmutableSentencePieceText::text() const {
+ if (spt_) return spt_->text();
+ static std::string *kEmptyString = new std::string();
+ return *kEmptyString;
}
float ImmutableSentencePieceText::score() const {
class ImmutableSentencePiece {
public:
~ImmutableSentencePiece() = default;
- absl::string_view piece() const;
- absl::string_view surface() const;
+ const std::string &piece() const;
+ const std::string &surface() const;
uint32_t id() const;
uint32_t begin() const;
uint32_t end() const;
std::vector<ImmutableSentencePiece> pieces() const;
size_t pieces_size() const;
ImmutableSentencePiece pieces(int index) const;
- absl::string_view text() const;
+ const std::string &text() const;
float score() const;
std::string SerializeAsString() const;
SentencePieceText *mutable_proto();
friend class ImmutableNBestSentencePieceText;
- friend class SentencePieceProcessor;
private:
explicit ImmutableSentencePieceText(const SentencePieceText &spt);
// it returns the raw pointer managed by the shared_ptr.
NBestSentencePieceText *mutable_proto();
- friend class SentencePieceProcessor;
-
private:
std::shared_ptr<NBestSentencePieceText> rep_;
};
template <typename T>
inline bool DecodePOD(absl::string_view str, T *result) {
- CHECK_NOTNULL(result);
if (sizeof(*result) != str.size()) {
return false;
}