@@ -289,8 +289,8 @@ class SentenceTranslation : public Translation {
289
289
UserDictEntryCollector* user_phrase_collector,
290
290
const std::string& input,
291
291
size_t start);
292
- bool Next ();
293
- shared_ptr<Candidate> Peek ();
292
+ virtual bool Next ();
293
+ virtual shared_ptr<Candidate> Peek ();
294
294
295
295
protected:
296
296
void PrepareSentence ();
@@ -306,6 +306,18 @@ class SentenceTranslation : public Translation {
306
306
size_t start_;
307
307
};
308
308
309
+ class SentenceSyllabification : public Syllabification {
310
+ public:
311
+ SentenceSyllabification (shared_ptr<Sentence> sentence)
312
+ : syllabified_(sentence) {
313
+ }
314
+ virtual size_t PreviousStop (size_t caret_pos) const ;
315
+ virtual size_t NextStop (size_t caret_pos) const ;
316
+
317
+ protected:
318
+ shared_ptr<Sentence> syllabified_;
319
+ };
320
+
309
321
SentenceTranslation::SentenceTranslation (TableTranslator* translator,
310
322
shared_ptr<Sentence> sentence,
311
323
DictEntryCollector* collector,
@@ -380,6 +392,8 @@ void SentenceTranslation::PrepareSentence() {
380
392
if (!sentence_) return ;
381
393
sentence_->Offset (start_);
382
394
sentence_->set_comment (kUnityTableEncoder );
395
+ sentence_->set_syllabification (
396
+ make_shared<SentenceSyllabification>(sentence_));
383
397
384
398
if (!translator_) return ;
385
399
std::string preedit (input_);
@@ -423,6 +437,32 @@ bool SentenceTranslation::PreferUserPhrase() const {
423
437
return false ;
424
438
}
425
439
440
+ size_t SentenceSyllabification::PreviousStop (size_t caret_pos) const {
441
+ if (syllabified_) {
442
+ size_t stop = syllabified_->start ();
443
+ BOOST_FOREACH (size_t len, syllabified_->syllable_lengths ()) {
444
+ if (stop + len >= caret_pos) {
445
+ return stop;
446
+ }
447
+ stop += len;
448
+ }
449
+ }
450
+ return caret_pos;
451
+ }
452
+
453
+ size_t SentenceSyllabification::NextStop (size_t caret_pos) const {
454
+ if (syllabified_) {
455
+ size_t stop = syllabified_->start ();
456
+ BOOST_FOREACH (size_t len, syllabified_->syllable_lengths ()) {
457
+ stop += len;
458
+ if (stop > caret_pos) {
459
+ return stop;
460
+ }
461
+ }
462
+ }
463
+ return caret_pos;
464
+ }
465
+
426
466
template <class Iter >
427
467
shared_ptr<DictEntry> get_first_entry (Iter& iter, bool filter_by_charset) {
428
468
if (iter.exhausted ())
0 commit comments