From b7568a8dad2720d5ea0418171e9b85229adbbcc5 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 31 Jul 2011 19:24:02 +0200 Subject: bugfixing, begin refactoring --- dtrain/dcommon.cc | 79 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 30 deletions(-) (limited to 'dtrain/dcommon.cc') diff --git a/dtrain/dcommon.cc b/dtrain/dcommon.cc index a6bdc92c..6657bed6 100644 --- a/dtrain/dcommon.cc +++ b/dtrain/dcommon.cc @@ -2,7 +2,11 @@ -/* + +/****************************************************************************** + * NGRAMS + * + * * make_ngrams * */ @@ -23,9 +27,6 @@ make_ngrams( vector& s, size_t N ) } - - - /* * ngram_matches * @@ -50,7 +51,12 @@ make_ngram_counts( vector hyp, vector ref, size_t N ) } -/* + + +/****************************************************************************** + * SCORES + * + * * brevity_penaly * */ @@ -156,7 +162,12 @@ approx_bleu( NgramCounts& counts, const size_t hyp_len, const size_t ref_len, } -/* + + +/****************************************************************************** + * UTILS + * + * * register_and_convert * */ @@ -170,11 +181,39 @@ register_and_convert(const vector& strs, vector& ids) } +/* + * approx_equal + * + */ +double +approx_equal( double x, double y ) +{ + const double EPSILON = 1E-5; + if ( x == 0 ) return fabs( y ) <= EPSILON; + if ( y == 0 ) return fabs( x ) <= EPSILON; + return fabs( x - y ) / max( fabs(x), fabs(y) ) <= EPSILON; +} /* + * print_FD + * + */ +void +print_FD() +{ + for ( size_t i = 0; i < FD::NumFeats(); i++ ) cout << FD::Convert(i)<< endl; +} + + + + +/****************************************************************************** + * TESTS * * + * test_ngrams + * */ void test_ngrams() @@ -207,21 +246,7 @@ test_ngrams() /* - * - * - */ -double -approx_equal( double x, double y ) -{ - const double EPSILON = 1E-5; - if ( x == 0 ) return fabs( y ) <= EPSILON; - if ( y == 0 ) return fabs( x ) <= EPSILON; - return fabs( x - y ) / max( fabs(x), fabs(y) ) <= EPSILON; -} - - -/* - * + * test_metrics * */ void @@ -263,8 +288,9 @@ test_metrics() cout << endl; } + /* - * + * test_SetWeights * */ void @@ -287,7 +313,7 @@ test_SetWeights() /* - * + * run_tests * */ void @@ -302,10 +328,3 @@ run_tests() exit(0); } - -void -print_FD() -{ - for ( size_t i = 0; i < FD::NumFeats(); i++ ) cout << FD::Convert(i)<< endl; -} - -- cgit v1.2.3