From 36b0eac74f5d8f8674659826a72276b47d687bd6 Mon Sep 17 00:00:00 2001 From: redpony Date: Fri, 2 Jul 2010 19:23:08 +0000 Subject: filter and score in a single file git-svn-id: https://ws10smt.googlecode.com/svn/trunk@118 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/sparse_vector.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'decoder/sparse_vector.h') diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index 66c9b10d..896e8c43 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -187,17 +187,26 @@ public: return result /= x; } - std::ostream &operator<<(std::ostream &out) const { + std::ostream &operator<<(std::ostream& out) const { + Write(true, &out); + return out; + } + + void Write(const bool with_semi, std::ostream* os) const { bool first = true; for (typename MapType::const_iterator it = values_.begin(); it != values_.end(); ++it) { // by definition feature id 0 is a dummy value if (it->first == 0) continue; - out << (first ? "" : ";") - << FD::Convert(it->first) << '=' << it->second; + if (with_semi) { + (*os) << (first ? "" : ";") + << FD::Convert(it->first) << '=' << it->second; + } else { + (*os) << (first ? "" : " ") + << FD::Convert(it->first) << '=' << it->second; + } first = false; } - return out; } bool operator<(const SparseVector &other) const { -- cgit v1.2.3