Skip to content

Commit

Permalink
Do not break compilation for users with old SentencePiece versions (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumekln authored Oct 1, 2018
1 parent e1a0a93 commit 5eb614a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes and improvements

* Do not break compilation for users with old SentencePiece versions

## [v1.9.0](https://github.com/OpenNMT/Tokenizer/releases/tag/v1.9.0) (2018-09-25)

### New features
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ else()
if(HAS_SAMPLE_ENCODE)
add_definitions(-DSP_HAS_SAMPLE_ENCODE)
endif()

file(STRINGS ${SP_INCLUDE_DIR}/sentencepiece_processor.h HAS_VOCAB_RESTRICTION REGEX "SetVocabulary")
if(HAS_VOCAB_RESTRICTION)
add_definitions(-DSP_HAS_VOCAB_RESTRICTION)
endif()
endif()

add_library(${PROJECT_NAME} ${SOURCES})
Expand Down
10 changes: 10 additions & 0 deletions src/SentencePiece.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ namespace onmt

void SentencePiece::set_vocabulary(const std::vector<std::string>& vocabulary)
{
#ifdef SP_HAS_VOCAB_RESTRICTION
_processor.SetVocabulary(vocabulary);
#else
throw std::runtime_error("The project was built against a SentencePiece version "
"that does not support vocabulary restriction");
#endif
}

void SentencePiece::reset_vocabulary()
{
#ifdef SP_HAS_VOCAB_RESTRICTION
_processor.ResetVocabulary();
#else
throw std::runtime_error("The project was built against a SentencePiece version "
"that does not support vocabulary restriction");
#endif
}

void SentencePiece::enable_regularization(int nbest_size, float alpha)
Expand Down

0 comments on commit 5eb614a

Please sign in to comment.