From 46ab067d01dae71f149c912f5ea99af34b08fa4c Mon Sep 17 00:00:00 2001 From: Oneplus Date: Thu, 13 Nov 2014 11:12:04 +0800 Subject: [PATCH] [add] decode context class to solve multi-threaded error --- src/segmentor/decode_context.h | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/segmentor/decode_context.h diff --git a/src/segmentor/decode_context.h b/src/segmentor/decode_context.h new file mode 100644 index 000000000..e5ce3047b --- /dev/null +++ b/src/segmentor/decode_context.h @@ -0,0 +1,47 @@ +#ifndef __LTP_SEGMENTOR_DECODE_CONTEXT_H__ +#define __LTP_SEGMENTOR_DECODE_CONTEXT_H__ + +namespace ltp { +namespace segmentor { + +class DecodeContext { +public: + //! the gold features. + math::SparseVec correct_features; + //! the predicted features. + math::SparseVec predicted_features; + //! + math::SparseVec updated_features; + + //! The feature cache. + math::Mat< math::FeatureVector *> uni_features; + + DecodeContext() {} + ~DecodeContext() {} + + void clear() { + if (uni_features.total_size() > 0) { + int d1 = uni_features.nrows(); + int d2 = uni_features.ncols(); + for (int i = 0; i < d1; ++ i) { + if (uni_features[i][0]) { + uni_features[i][0]->clear(); + } + for (int j = 0; j < d2; ++ j) { + if (uni_features[i][j]) { + delete uni_features[i][j]; + } + } + } + } + + uni_features.dealloc(); + correct_features.zero(); + predicted_features.zero(); + } +}; + +} // end for namespace segmentor +} // end for namespace ltp + +#endif // end for __LTP_SEGMENTOR_DECODE_CONTEXT_H__