diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-05-29 21:16:15 +0400 |
commit | 6249432407af8730c10bccc7894c0725fcaf5e47 (patch) | |
tree | 3ac1f094b9fdc199b04bc5ef209ce00e3596e37d /biconcor/PhrasePair.cpp | |
parent | 59bd7deb4b6b9c4f7b3b7dbb055783528fbc31ca (diff) |
beautify
Diffstat (limited to 'biconcor/PhrasePair.cpp')
-rw-r--r-- | biconcor/PhrasePair.cpp | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/biconcor/PhrasePair.cpp b/biconcor/PhrasePair.cpp index 038fa3a31..b6409258b 100644 --- a/biconcor/PhrasePair.cpp +++ b/biconcor/PhrasePair.cpp @@ -37,7 +37,7 @@ void PhrasePair::Print( ostream* out ) const INDEX ap_points = m_alignment->GetNumberOfAlignmentPoints( m_sentence_id ); for( INDEX i=0; i<ap_points; i++) { *out << " " << m_alignment->GetSourceWord( m_sentence_id, i ) - << "-" << m_alignment->GetTargetWord( m_sentence_id, i ); + << "-" << m_alignment->GetTargetWord( m_sentence_id, i ); } *out << endl; @@ -185,27 +185,27 @@ void PhrasePair::PrintClippedHTML( ostream* out, int width ) const size_t source_pre_width = (source_width-source.size())/2; size_t source_post_width = (source_width-source.size()+1)/2; - // if phrase is too long, don't show any context + // if phrase is too long, don't show any context if (source.size() > (size_t)width) { source_pre_width = 0; source_post_width = 0; } - // too long -> truncate and add "..." + // too long -> truncate and add "..." if (source_pre.size() > source_pre_width) { - // first skip up to a space - while(source_pre_width>0 && - source_pre.substr(source_pre.size()-source_pre_width,1) != " ") { - source_pre_width--; - } + // first skip up to a space + while(source_pre_width>0 && + source_pre.substr(source_pre.size()-source_pre_width,1) != " ") { + source_pre_width--; + } source_pre = "..." + source_pre.substr( source_pre.size()-source_pre_width, source_pre_width ); - } + } if (source_post.size() > source_post_width) { - while(source_post_width>0 && - source_post.substr(source_post_width-1,1) != " ") { - source_post_width--; - } + while(source_post_width>0 && + source_post.substr(source_post_width-1,1) != " ") { + source_post_width--; + } source_post = source_post.substr( 0, source_post_width ) + "..."; - } + } *out << "<tr><td class=\"pp_source_left\">" << source_pre @@ -220,13 +220,13 @@ void PhrasePair::PrintClippedHTML( ostream* out, int width ) const string target_pre = ""; string target = ""; string target_post = ""; - size_t target_pre_null_width = 0; - size_t target_post_null_width = 0; + size_t target_pre_null_width = 0; + size_t target_post_null_width = 0; for( char i=0; i<m_target_start; i++ ) { - WORD word = m_targetCorpus->GetWord( m_sentence_id, i); + WORD word = m_targetCorpus->GetWord( m_sentence_id, i); target_pre += " " + word; - if (i >= m_target_start-m_pre_null) - target_pre_null_width += word.size() + 1; + if (i >= m_target_start-m_pre_null) + target_pre_null_width += word.size() + 1; } for( char i=m_target_start; i<=m_target_end; i++ ) { if (i>m_target_start) target += " "; @@ -234,11 +234,11 @@ void PhrasePair::PrintClippedHTML( ostream* out, int width ) const } for( char i=m_target_end+1; i<m_target_length; i++ ) { if (i>m_target_end+1) target_post += " "; - WORD word = m_targetCorpus->GetWord( m_sentence_id, i); + WORD word = m_targetCorpus->GetWord( m_sentence_id, i); target_post += word; - if (i-(m_target_end+1) < m_post_null) { - target_post_null_width += word.size() + 1; - } + if (i-(m_target_end+1) < m_post_null) { + target_post_null_width += word.size() + 1; + } } size_t target_pre_width = (target_width-target.size())/2; @@ -249,46 +249,45 @@ void PhrasePair::PrintClippedHTML( ostream* out, int width ) const target_post_width = 0; } - if (target_pre.size() < target_pre_width) - target_pre_width = target_pre.size(); - else { - while(target_pre_width>0 && - target_pre.substr(target_pre.size()-target_pre_width,1) != " ") { - target_pre_width--; - } + if (target_pre.size() < target_pre_width) + target_pre_width = target_pre.size(); + else { + while(target_pre_width>0 && + target_pre.substr(target_pre.size()-target_pre_width,1) != " ") { + target_pre_width--; + } target_pre = "..." + target_pre.substr( target_pre.size()-target_pre_width, target_pre_width ); - } - - if (target_post.size() < target_post_width) { - target_post_width = target_post.size(); - } - else { - while(target_post_width>0 && - target_post.substr(target_post_width-1,1) != " ") { - target_post_width--; - } - target_post = target_post.substr( 0, target_post_width ) + "..."; - } - - if (m_pre_null) { - //cerr << endl << "target_pre_width=" << target_pre_width << ", target_pre_null_width=" << target_pre_null_width << ", target_pre.size()=" << target_pre.size() << endl; - if (target_pre_width < target_pre.size()) - target_pre_null_width -= target_pre.size()-target_pre_width; - target_pre = target_pre.substr(0,target_pre_width-target_pre_null_width) - + "<span class=\"null_aligned\">" - + target_pre.substr(target_pre_width-target_pre_null_width) - + "</span>"; - } - if (m_post_null) { - //cerr << endl << "target_post_width=" << target_post_width << ", target_post_null_width=" << target_post_null_width << ", target_post.size()=" << target_post.size() << endl; - if (target_post_null_width > target_post.size()) { - target_post_null_width = target_post.size(); - } - target_post = "<span class=\"null_aligned\">" - + target_post.substr(0,target_post_null_width) - + "</span>" - + target_post.substr(target_post_null_width); - } + } + + if (target_post.size() < target_post_width) { + target_post_width = target_post.size(); + } else { + while(target_post_width>0 && + target_post.substr(target_post_width-1,1) != " ") { + target_post_width--; + } + target_post = target_post.substr( 0, target_post_width ) + "..."; + } + + if (m_pre_null) { + //cerr << endl << "target_pre_width=" << target_pre_width << ", target_pre_null_width=" << target_pre_null_width << ", target_pre.size()=" << target_pre.size() << endl; + if (target_pre_width < target_pre.size()) + target_pre_null_width -= target_pre.size()-target_pre_width; + target_pre = target_pre.substr(0,target_pre_width-target_pre_null_width) + + "<span class=\"null_aligned\">" + + target_pre.substr(target_pre_width-target_pre_null_width) + + "</span>"; + } + if (m_post_null) { + //cerr << endl << "target_post_width=" << target_post_width << ", target_post_null_width=" << target_post_null_width << ", target_post.size()=" << target_post.size() << endl; + if (target_post_null_width > target_post.size()) { + target_post_null_width = target_post.size(); + } + target_post = "<span class=\"null_aligned\">" + + target_post.substr(0,target_post_null_width) + + "</span>" + + target_post.substr(target_post_null_width); + } *out << "<td class=\"pp_target_left\">" << target_pre |