From 6ff6fe143049959ca92cb26fc6f66d65d8c59a98 Mon Sep 17 00:00:00 2001 From: yanyiwu Date: Sun, 17 Apr 2016 21:57:36 +0800 Subject: [PATCH] WordRange construct --- include/cppjieba/FullSegment.hpp | 4 ++-- include/cppjieba/HMMSegment.hpp | 4 ++-- include/cppjieba/MPSegment.hpp | 4 ++-- include/cppjieba/Unicode.hpp | 9 +++------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/cppjieba/FullSegment.hpp b/include/cppjieba/FullSegment.hpp index 8eeb70d..99cb8fa 100644 --- a/include/cppjieba/FullSegment.hpp +++ b/include/cppjieba/FullSegment.hpp @@ -63,13 +63,13 @@ class FullSegment: public SegmentBase { const DictUnit* du = dags[i].nexts[j].second; if (du == NULL) { if (dags[i].nexts.size() == 1 && maxIdx <= uIdx) { - unicode::WordRange wr = {begin + i, begin + nextoffset}; + unicode::WordRange wr(begin + i, begin + nextoffset); res.push_back(wr); } } else { wordLen = du->word.size(); if (wordLen >= 2 || (dags[i].nexts.size() == 1 && maxIdx <= uIdx)) { - unicode::WordRange wr = {begin + i, begin + nextoffset}; + unicode::WordRange wr(begin + i, begin + nextoffset); res.push_back(wr); } } diff --git a/include/cppjieba/HMMSegment.hpp b/include/cppjieba/HMMSegment.hpp index 18cd308..c5dd7f8 100644 --- a/include/cppjieba/HMMSegment.hpp +++ b/include/cppjieba/HMMSegment.hpp @@ -57,7 +57,7 @@ class HMMSegment: public SegmentBase { } right ++; } while (false); - unicode::WordRange wr = {left, right - 1}; + unicode::WordRange wr(left, right - 1); res.push_back(wr); left = right; } else { @@ -114,7 +114,7 @@ class HMMSegment: public SegmentBase { for (size_t i = 0; i < status.size(); i++) { if (status[i] % 2) { //if (HMMModel::E == status[i] || HMMModel::S == status[i]) right = begin + i + 1; - unicode::WordRange wr = {left, right - 1}; + unicode::WordRange wr(left, right - 1); res.push_back(wr); left = right; } diff --git a/include/cppjieba/MPSegment.hpp b/include/cppjieba/MPSegment.hpp index 811db44..a5b908b 100644 --- a/include/cppjieba/MPSegment.hpp +++ b/include/cppjieba/MPSegment.hpp @@ -99,11 +99,11 @@ class MPSegment: public SegmentBase { const DictUnit* p = dags[i].pInfo; if (p) { assert(p->word.size() >= 1); - unicode::WordRange wr = {begin + i, begin + i + p->word.size() - 1}; + unicode::WordRange wr(begin + i, begin + i + p->word.size() - 1); words.push_back(wr); i += p->word.size(); } else { //single chinese word - unicode::WordRange wr = {begin + i, begin + i}; + unicode::WordRange wr(begin + i, begin + i); words.push_back(wr); i++; } diff --git a/include/cppjieba/Unicode.hpp b/include/cppjieba/Unicode.hpp index b7307cb..4fe527d 100644 --- a/include/cppjieba/Unicode.hpp +++ b/include/cppjieba/Unicode.hpp @@ -31,6 +31,9 @@ typedef limonp::LocalVector RuneStrArray; struct WordRange { RuneStrArray::const_iterator left; RuneStrArray::const_iterator right; + WordRange(RuneStrArray::const_iterator l, RuneStrArray::const_iterator r) + : left(l), right(r) { + } size_t Length() const { return right - left + 1; } @@ -44,12 +47,6 @@ struct WordRange { } }; // struct WordRange -//struct RuneWordStr { -// Unicode word; -// const char* str; -// size_t len; -//}; // struct RuneWordStr - struct RuneStrLite { uint32_t rune; uint32_t len;