%ignore sentencepiece::SentencePieceProcessor::model_proto;
%ignore sentencepiece::SentencePieceProcessor::Load;
%ignore sentencepiece::SentencePieceProcessor::LoadOrDie;
+%ignore sentencepiece::SentencePieceProcessor::SetModel;
+%ignore sentencepiece::SentencePieceProcessor::SetNormalizer;
%ignore sentencepiece::pretokenizer::PretokenizerForTrainingInterface;
%ignore sentencepiece::SentenceIterator;
%ignore sentencepiece::ConvertToUnicodeSpans;
%ignore sentencepiece::SentencePieceTrainer::SetPretokenizerForTraining;
%ignore sentencepiece::SentencePieceTrainer::GetPretokenizerForTraining;
+%ignore sentencepiece::io::LoadModelProto;
+%ignore sentencepiece::io::SaveModelProto;
+
%extend sentencepiece::SentencePieceProcessor {
sentencepiece::util::Status LoadFromFile(absl::string_view arg) {
return $self->Load(arg);
namespace absl {
using std::string_view;
} // namespace absl
-#endif
+#endif // SWIG
namespace sentencepiece {
namespace util {
virtual util::Status Decode(const std::vector<int> &ids,
SentencePieceText *spt) const;
-#ifdef SWIGPYTHON
-#define CONVERT_TO_UNICODE_SPAN output.ConvertToUnicodeSpans();
-#define SPP_SWIG_CHECK_AND_THROW \
- if (!status.ok()) throw status;
+#ifndef SWIGPYTHON
+
+#define DEFINE_SPP_DIRECT_FUNC_IMPL(FuncName, OutType, ...) \
+ OutType output; \
+ const auto status = FuncName(__VA_ARGS__, &output); \
+ return output;
+
+#define DEFINE_SPP_SERIALIZED_PROTO_IMPL(FuncName, OutType, ...) \
+ OutType output; \
+ const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \
+ return output.SerializeAsString();
+
+#define DEFINE_SPP_IMMUTABLE_PROTO_IMPL(FuncName, OutType, ...) \
+ OutType output; \
+ const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \
+ return output;
+
#else
-#define CONVERT_TO_UNICODE_SPAN
-#define SPP_SWIG_CHECK_AND_THROW \
- if (!status.ok()) { \
- }
-#endif // SWIGPYTHON
#define DEFINE_SPP_DIRECT_FUNC_IMPL(FuncName, OutType, ...) \
OutType output; \
const auto status = FuncName(__VA_ARGS__, &output); \
- SPP_SWIG_CHECK_AND_THROW; \
+ if (!status.ok()) throw status; \
return output;
#define DEFINE_SPP_SERIALIZED_PROTO_IMPL(FuncName, OutType, ...) \
OutType output; \
const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \
- SPP_SWIG_CHECK_AND_THROW; \
+ if (!status.ok()) throw status; \
return output.SerializeAsString();
#define DEFINE_SPP_IMMUTABLE_PROTO_IMPL(FuncName, OutType, ...) \
OutType output; \
const auto status = FuncName(__VA_ARGS__, output.mutable_proto()); \
- CONVERT_TO_UNICODE_SPAN; \
- SPP_SWIG_CHECK_AND_THROW; \
+ if (!status.ok()) throw status; \
+ output.ConvertToUnicodeSpans(); \
return output;
+#endif // SWIGPYTHON
+
//////////////////////////////////////////////////////////////
// Handy methods that return the result directly.
// These functions ignore internal errors.
// Returns PAD (<pad>) id.
virtual int pad_id() const;
-#ifndef SWIG
//////////////////////////////////////////////////////////////
// Model management.
//
// Allows injection of a normalizer instance. `normalizer` is moved.
void SetNormalizer(std::unique_ptr<normalizer::Normalizer> &&normalizer);
-#endif // SWIG
// Returns immutable model proto. Useful to obtain extended
// or experimental parameters encoded in model_proto.
// std::random_device.
void SetRandomGeneratorSeed(unsigned int seed);
-#ifndef SWIG
// IO related functions to absorb model formats.
namespace io {
// Loads `model_proto` from `filename`.
// Saves `model_proto` as `filename`.
util::Status SaveModelProto(absl::string_view, const ModelProto &model_proto);
} // namespace io
-#endif // SWIG
} // namespace sentencepiece
#endif // SENTENCEPIECE_PROCESSOR_H_