diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-07 19:58:44 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-05-07 19:58:44 +0400 |
commit | 355f8714571cfd337d5b18bafa977642cbb64e5d (patch) | |
tree | 89db0e6de5c321b4ba6218fe33e3147419065e96 /scripts/ems | |
parent | 31c4bf3371e8eef947d80de741c2d44504082c5b (diff) |
Add const to member functions.
Replace define macros with enum.
Diffstat (limited to 'scripts/ems')
-rw-r--r-- | scripts/ems/biconcor/Alignment.cpp | 2 | ||||
-rw-r--r-- | scripts/ems/biconcor/Alignment.h | 28 | ||||
-rw-r--r-- | scripts/ems/biconcor/Mismatch.cpp | 14 | ||||
-rw-r--r-- | scripts/ems/biconcor/Mismatch.h | 2 | ||||
-rw-r--r-- | scripts/ems/biconcor/PhrasePair.cpp | 12 | ||||
-rw-r--r-- | scripts/ems/biconcor/PhrasePair.h | 8 | ||||
-rw-r--r-- | scripts/ems/biconcor/PhrasePairCollection.cpp | 18 | ||||
-rw-r--r-- | scripts/ems/biconcor/PhrasePairCollection.h | 8 | ||||
-rw-r--r-- | scripts/ems/biconcor/SuffixArray.cpp | 2 | ||||
-rw-r--r-- | scripts/ems/biconcor/SuffixArray.h | 14 | ||||
-rw-r--r-- | scripts/ems/biconcor/TargetCorpus.cpp | 8 | ||||
-rw-r--r-- | scripts/ems/biconcor/TargetCorpus.h | 8 | ||||
-rw-r--r-- | scripts/ems/biconcor/Vocabulary.cpp | 8 | ||||
-rw-r--r-- | scripts/ems/biconcor/Vocabulary.h | 4 |
14 files changed, 69 insertions, 67 deletions
diff --git a/scripts/ems/biconcor/Alignment.cpp b/scripts/ems/biconcor/Alignment.cpp index 89696c036..255ad197e 100644 --- a/scripts/ems/biconcor/Alignment.cpp +++ b/scripts/ems/biconcor/Alignment.cpp @@ -183,7 +183,7 @@ bool Alignment::PhraseAlignment( INDEX sentence, char target_length, return true; } -void Alignment::Save(const string& fileName ) +void Alignment::Save(const string& fileName ) const { FILE *pFile = fopen ( (fileName + ".align").c_str() , "w" ); if (pFile == NULL) { diff --git a/scripts/ems/biconcor/Alignment.h b/scripts/ems/biconcor/Alignment.h index d757acab9..f6e448047 100644 --- a/scripts/ems/biconcor/Alignment.h +++ b/scripts/ems/biconcor/Alignment.h @@ -24,20 +24,20 @@ public: char &target_start, char &target_end, char &pre_null, char &post_null ); void Load(const std::string& fileName ); - void Save(const std::string& fileName ); + void Save(const std::string& fileName ) const; std::vector<std::string> Tokenize( const char input[] ); - INDEX GetSentenceStart( INDEX sentence ) { - if (sentence == 0) return 0; - return m_sentenceEnd[ sentence-1 ] + 2; - } - INDEX GetNumberOfAlignmentPoints( INDEX sentence ) { - return ( m_sentenceEnd[ sentence ] - GetSentenceStart( sentence ) ) / 2; - } - char GetSourceWord( INDEX sentence, INDEX alignment_point ) { - return m_array[ GetSentenceStart( sentence ) + alignment_point*2 ]; - } - char GetTargetWord( INDEX sentence, INDEX alignment_point ) { - return m_array[ GetSentenceStart( sentence ) + alignment_point*2 + 1 ]; - } + INDEX GetSentenceStart( INDEX sentence ) const { + if (sentence == 0) return 0; + return m_sentenceEnd[ sentence-1 ] + 2; + } + INDEX GetNumberOfAlignmentPoints( INDEX sentence ) const { + return ( m_sentenceEnd[ sentence ] - GetSentenceStart( sentence ) ) / 2; + } + char GetSourceWord( INDEX sentence, INDEX alignment_point ) const { + return m_array[ GetSentenceStart( sentence ) + alignment_point*2 ]; + } + char GetTargetWord( INDEX sentence, INDEX alignment_point ) const { + return m_array[ GetSentenceStart( sentence ) + alignment_point*2 + 1 ]; + } }; diff --git a/scripts/ems/biconcor/Mismatch.cpp b/scripts/ems/biconcor/Mismatch.cpp index 573e82521..6de8fb55b 100644 --- a/scripts/ems/biconcor/Mismatch.cpp +++ b/scripts/ems/biconcor/Mismatch.cpp @@ -13,12 +13,14 @@ using namespace std; -#define UNANNOTATED 0 -#define PRE_ALIGNED 1 -#define POST_ALIGNED 2 -#define UNALIGNED 3 -#define MISALIGNED 4 -#define ALIGNED 5 +enum { + UNANNOTATED = 0, + PRE_ALIGNED = 1, + POST_ALIGNED = 2, + UNALIGNED = 3, + MISALIGNED = 4, + ALIGNED = 5 +}; Mismatch::Mismatch( SuffixArray *sa, TargetCorpus *tc, Alignment *a, INDEX sentence_id, INDEX position, char source_length, char target_length, char source_start, char source_end ) :m_suffixArray(sa) diff --git a/scripts/ems/biconcor/Mismatch.h b/scripts/ems/biconcor/Mismatch.h index 46dc67a1f..4a54a6342 100644 --- a/scripts/ems/biconcor/Mismatch.h +++ b/scripts/ems/biconcor/Mismatch.h @@ -30,7 +30,7 @@ public: Mismatch( SuffixArray *sa, TargetCorpus *tc, Alignment *a, INDEX sentence_id, INDEX position, char source_length, char target_length, char source_start, char source_end ); ~Mismatch(); - bool Unaligned() { return m_unaligned; } + bool Unaligned() const { return m_unaligned; } void PrintClippedHTML(std::ostream* out, int width ); void LabelSourceMatches( char *source_annotation, char *target_annotation, char source_id, char label ); }; diff --git a/scripts/ems/biconcor/PhrasePair.cpp b/scripts/ems/biconcor/PhrasePair.cpp index 9273101bd..e66044ff5 100644 --- a/scripts/ems/biconcor/PhrasePair.cpp +++ b/scripts/ems/biconcor/PhrasePair.cpp @@ -8,9 +8,9 @@ using namespace std; -void PhrasePair::Print( ostream* out, int width ) +void PhrasePair::Print( ostream* out, int width ) const { - vector< WORD_ID >::iterator t; + vector< WORD_ID >::const_iterator t; // source int sentence_start = m_source_position - m_source_start; @@ -76,7 +76,7 @@ void PhrasePair::Print( ostream* out, int width ) << target_post.substr( 0, target_post_width ) << endl; } -void PhrasePair::PrintTarget( ostream* out ) +void PhrasePair::PrintTarget( ostream* out ) const { for( char i=m_target_start; i<=m_target_end; i++ ) { if (i>m_target_start) *out << " "; @@ -84,7 +84,7 @@ void PhrasePair::PrintTarget( ostream* out ) } } -void PhrasePair::PrintHTML( ostream* out ) +void PhrasePair::PrintHTML( ostream* out ) const { // source int sentence_start = m_source_position - m_source_start; @@ -125,9 +125,9 @@ void PhrasePair::PrintHTML( ostream* out ) *out << "</td></tr>\n"; } -void PhrasePair::PrintClippedHTML( ostream* out, int width ) +void PhrasePair::PrintClippedHTML( ostream* out, int width ) const { - vector< WORD_ID >::iterator t; + vector< WORD_ID >::const_iterator t; // source int sentence_start = m_source_position - m_source_start; diff --git a/scripts/ems/biconcor/PhrasePair.h b/scripts/ems/biconcor/PhrasePair.h index 23b811078..f8a7881a0 100644 --- a/scripts/ems/biconcor/PhrasePair.h +++ b/scripts/ems/biconcor/PhrasePair.h @@ -42,8 +42,8 @@ public: {} ~PhrasePair () {} - void PrintTarget( std::ostream* out ); - void Print( std::ostream* out, int width ); - void PrintHTML( std::ostream* out ); - void PrintClippedHTML( std::ostream* out, int width ); + void PrintTarget( std::ostream* out ) const; + void Print( std::ostream* out, int width ) const; + void PrintHTML( std::ostream* out ) const; + void PrintClippedHTML( std::ostream* out, int width ) const; }; diff --git a/scripts/ems/biconcor/PhrasePairCollection.cpp b/scripts/ems/biconcor/PhrasePairCollection.cpp index 76f84dbb3..8b1138796 100644 --- a/scripts/ems/biconcor/PhrasePairCollection.cpp +++ b/scripts/ems/biconcor/PhrasePairCollection.cpp @@ -26,7 +26,7 @@ PhrasePairCollection::PhrasePairCollection( SuffixArray *sa, TargetCorpus *tc, A PhrasePairCollection::~PhrasePairCollection() {} -bool PhrasePairCollection::GetCollection( const vector< string > sourceString ) +bool PhrasePairCollection::GetCollection( const vector< string >& sourceString ) { INDEX first_match, last_match; if (! m_suffixArray->FindMatches( sourceString, first_match, last_match )) { @@ -97,33 +97,33 @@ bool PhrasePairCollection::GetCollection( const vector< string > sourceString ) return true; } -void PhrasePairCollection::Print() +void PhrasePairCollection::Print() const { - vector< vector<PhrasePair*> >::iterator ppWithSameTarget; + vector< vector<PhrasePair*> >::const_iterator ppWithSameTarget; for( ppWithSameTarget = m_collection.begin(); ppWithSameTarget != m_collection.end(); ppWithSameTarget++ ) { (*(ppWithSameTarget->begin()))->PrintTarget( &cout ); int count = ppWithSameTarget->size(); cout << "(" << count << ")" << endl; - vector< PhrasePair* >::iterator p; + vector< PhrasePair* >::const_iterator p; for(p = ppWithSameTarget->begin(); p != ppWithSameTarget->end(); p++ ) { (*p)->Print( &cout, 100 ); } } } -void PhrasePairCollection::PrintHTML() +void PhrasePairCollection::PrintHTML() const { int pp_target = 0; bool singleton = false; // loop over all translations - vector< vector<PhrasePair*> >::iterator ppWithSameTarget; + vector< vector<PhrasePair*> >::const_iterator ppWithSameTarget; for( ppWithSameTarget = m_collection.begin(); ppWithSameTarget != m_collection.end() && pp_target<m_max_pp_target; ppWithSameTarget++, pp_target++ ) { int count = ppWithSameTarget->size(); if (!singleton) { if (count == 1) { singleton = true; - cout << "<p class=\"pp_singleton_header\">singleton" + cout << "<p class=\"pp_singleton_header\">singleton" << (m_collection.end() - ppWithSameTarget==1?"":"s") << " (" << (m_collection.end() - ppWithSameTarget) << "/" << m_size << ")</p>"; @@ -136,8 +136,8 @@ void PhrasePairCollection::PrintHTML() } cout << "<table align=\"center\">"; } - - vector< PhrasePair* >::iterator p; + + vector< PhrasePair* >::const_iterator p; // loop over all sentences where translation occurs int pp=0; int i=0; diff --git a/scripts/ems/biconcor/PhrasePairCollection.h b/scripts/ems/biconcor/PhrasePairCollection.h index 2b2b8e633..2708d4c93 100644 --- a/scripts/ems/biconcor/PhrasePairCollection.h +++ b/scripts/ems/biconcor/PhrasePairCollection.h @@ -29,14 +29,14 @@ public: PhrasePairCollection ( SuffixArray *, TargetCorpus *, Alignment * ); ~PhrasePairCollection (); - bool GetCollection( const std::vector<std::string > sourceString ); - void Print(); - void PrintHTML(); + bool GetCollection( const std::vector<std::string >& sourceString ); + void Print() const; + void PrintHTML() const; }; // sorting helper struct CompareBySize { - bool operator()(const std::vector<PhrasePair*> a, const std::vector<PhrasePair*> b ) const { + bool operator()(const std::vector<PhrasePair*>& a, const std::vector<PhrasePair*>& b ) const { return a.size() > b.size(); } }; diff --git a/scripts/ems/biconcor/SuffixArray.cpp b/scripts/ems/biconcor/SuffixArray.cpp index 140060734..4e8685f6e 100644 --- a/scripts/ems/biconcor/SuffixArray.cpp +++ b/scripts/ems/biconcor/SuffixArray.cpp @@ -257,7 +257,7 @@ void SuffixArray::List(INDEX start, INDEX end) } } -void SuffixArray::Save(const string& fileName ) +void SuffixArray::Save(const string& fileName ) const { FILE *pFile = fopen ( fileName.c_str() , "w" ); if (pFile == NULL) { diff --git a/scripts/ems/biconcor/SuffixArray.h b/scripts/ems/biconcor/SuffixArray.h index 5986da82b..0bf064796 100644 --- a/scripts/ems/biconcor/SuffixArray.h +++ b/scripts/ems/biconcor/SuffixArray.h @@ -35,24 +35,24 @@ public: INDEX FindLast( const std::vector< WORD > &phrase, INDEX start, INDEX end, int direction ); int Match( const std::vector< WORD > &phrase, INDEX index ); void List( INDEX start, INDEX end ); - inline INDEX GetPosition( INDEX index ) { + inline INDEX GetPosition( INDEX index ) const { return m_index[ index ]; } - inline INDEX GetSentence( INDEX position ) { + inline INDEX GetSentence( INDEX position ) const { return m_sentence[position]; } - inline char GetWordInSentence( INDEX position ) { + inline char GetWordInSentence( INDEX position ) const { return m_wordInSentence[position]; } - inline char GetSentenceLength( INDEX sentenceId ) { + inline char GetSentenceLength( INDEX sentenceId ) const { return m_sentenceLength[sentenceId]; } - inline INDEX GetSize() { + inline INDEX GetSize() const { return m_size; } - inline WORD GetWord( INDEX position ) { + inline WORD GetWord( INDEX position ) const { return m_vcb.GetWord( m_array[position] ); } - void Save(const std::string& fileName ); + void Save(const std::string& fileName ) const; void Load(const std::string& fileName ); }; diff --git a/scripts/ems/biconcor/TargetCorpus.cpp b/scripts/ems/biconcor/TargetCorpus.cpp index 75de789e9..fa09be3bd 100644 --- a/scripts/ems/biconcor/TargetCorpus.cpp +++ b/scripts/ems/biconcor/TargetCorpus.cpp @@ -80,12 +80,12 @@ WORD TargetCorpus::GetWordFromId( const WORD_ID id ) const return m_vcb.GetWord( id ); } -WORD TargetCorpus::GetWord( INDEX sentence, char word ) +WORD TargetCorpus::GetWord( INDEX sentence, char word ) const { return m_vcb.GetWord( GetWordId( sentence, word ) ); } -WORD_ID TargetCorpus::GetWordId( INDEX sentence, char word ) +WORD_ID TargetCorpus::GetWordId( INDEX sentence, char word ) const { if (sentence == 0) { return m_array[ word ]; @@ -93,7 +93,7 @@ WORD_ID TargetCorpus::GetWordId( INDEX sentence, char word ) return m_array[ m_sentenceEnd[ sentence-1 ] + 1 + word ] ; } -char TargetCorpus::GetSentenceLength( INDEX sentence ) +char TargetCorpus::GetSentenceLength( INDEX sentence ) const { if (sentence == 0) { return (char) m_sentenceEnd[ 0 ]+1; @@ -101,7 +101,7 @@ char TargetCorpus::GetSentenceLength( INDEX sentence ) return (char) ( m_sentenceEnd[ sentence ] - m_sentenceEnd[ sentence-1 ] ); } -void TargetCorpus::Save(const string& fileName ) +void TargetCorpus::Save(const string& fileName ) const { FILE *pFile = fopen ( (fileName + ".tgt").c_str() , "w" ); if (pFile == NULL) { diff --git a/scripts/ems/biconcor/TargetCorpus.h b/scripts/ems/biconcor/TargetCorpus.h index 99555fd97..ea3e6363f 100644 --- a/scripts/ems/biconcor/TargetCorpus.h +++ b/scripts/ems/biconcor/TargetCorpus.h @@ -19,9 +19,9 @@ public: void Create(const std::string& fileName ); WORD GetWordFromId( const WORD_ID id ) const; - WORD GetWord( INDEX sentence, char word ); - WORD_ID GetWordId( INDEX sentence, char word ); - char GetSentenceLength( INDEX sentence ); + WORD GetWord( INDEX sentence, char word ) const; + WORD_ID GetWordId( INDEX sentence, char word ) const; + char GetSentenceLength( INDEX sentence ) const; void Load(const std::string& fileName ); - void Save(const std::string& fileName ); + void Save(const std::string& fileName ) const; }; diff --git a/scripts/ems/biconcor/Vocabulary.cpp b/scripts/ems/biconcor/Vocabulary.cpp index 43d7cdfcd..9c35b3feb 100644 --- a/scripts/ems/biconcor/Vocabulary.cpp +++ b/scripts/ems/biconcor/Vocabulary.cpp @@ -46,16 +46,16 @@ WORD_ID Vocabulary::StoreIfNew( const WORD& word ) return id;
}
-WORD_ID Vocabulary::GetWordID( const WORD &word )
+WORD_ID Vocabulary::GetWordID( const WORD &word ) const
{
- map<WORD, WORD_ID>::iterator i = lookup.find( word );
+ map<WORD, WORD_ID>::const_iterator i = lookup.find( word );
if( i == lookup.end() )
return 0;
WORD_ID w= (WORD_ID) i->second;
return w;
}
-void Vocabulary::Save(const string& fileName )
+void Vocabulary::Save(const string& fileName ) const
{
ofstream vcbFile;
vcbFile.open( fileName.c_str(), ios::out | ios::ate | ios::trunc);
@@ -65,7 +65,7 @@ void Vocabulary::Save(const string& fileName ) exit(1);
}
- vector< WORD >::iterator i;
+ vector< WORD >::const_iterator i;
for(i = vocab.begin(); i != vocab.end(); i++) {
const string &word = *i;
vcbFile << word << endl;
diff --git a/scripts/ems/biconcor/Vocabulary.h b/scripts/ems/biconcor/Vocabulary.h index 3a8399e07..674912006 100644 --- a/scripts/ems/biconcor/Vocabulary.h +++ b/scripts/ems/biconcor/Vocabulary.h @@ -28,12 +28,12 @@ public: std::map<WORD, WORD_ID> lookup; std::vector< WORD > vocab; WORD_ID StoreIfNew( const WORD& ); - WORD_ID GetWordID( const WORD& ); + WORD_ID GetWordID( const WORD& ) const; std::vector<WORD_ID> Tokenize( const char[] ); inline WORD &GetWord( WORD_ID id ) const { WORD &i = (WORD&) vocab[ id ]; return i; } - void Save(const std::string& fileName ); + void Save(const std::string& fileName ) const; void Load(const std::string& fileName ); }; |