From b13b975a383fc2fb6c6200dd227cf6866d1cd7fb Mon Sep 17 00:00:00 2001 From: "Wu, Ke" Date: Sat, 6 Dec 2014 16:30:44 -0500 Subject: Remove unnecessary state from SoftSynFeature --- decoder/ff_soft_syn.cc | 51 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/decoder/ff_soft_syn.cc b/decoder/ff_soft_syn.cc index 50c2365e..c108e58c 100644 --- a/decoder/ff_soft_syn.cc +++ b/decoder/ff_soft_syn.cc @@ -45,8 +45,6 @@ struct SoftSynFeatureImpl { ~SoftSynFeatureImpl() { FreeSentenceVariables(); } - static int ReserveStateSize() { return 2 * sizeof(uint16_t); } - void InitializeInputSentence(const std::string& parse_file, const std::string& index_map_file) { FreeSentenceVariables(); @@ -210,25 +208,12 @@ struct SoftSynFeatureImpl { } void SetSoftSynFeature(const Hypergraph::Edge& edge, - SparseVector* features, - const vector& ant_states, void* state) { - vector vec_pos; + SparseVector* features) { if (parsed_tree_ == NULL) return; - uint16_t* remnant = reinterpret_cast(state); - short int mapped_begin, mapped_end; MapIndex(edge.i_, edge.j_ - 1, mapped_begin, mapped_end); - remnant[0] = mapped_begin; - remnant[1] = mapped_end; - - for (size_t i = 0; i < edge.tail_nodes_.size(); i++) { - const uint16_t* astate = reinterpret_cast(ant_states[i]); - vec_pos.push_back(astate[0]); - vec_pos.push_back(astate[1]); - } - // soft feature for the whole span const vector vecFeature = GenerateSoftFeature(mapped_begin, mapped_end, map_features_); @@ -300,7 +285,6 @@ struct SoftSynFeatureImpl { SoftSynFeature::SoftSynFeature(std::string param) { pimpl_ = new SoftSynFeatureImpl(param); - SetStateSize(SoftSynFeatureImpl::ReserveStateSize()); name_ = "SoftSynFeature"; } @@ -316,10 +300,10 @@ void SoftSynFeature::PrepareForInput(const SentenceMetadata& smeta) { } void SoftSynFeature::TraversalFeaturesImpl( - const SentenceMetadata& /* smeta */, const Hypergraph::Edge& edge, - const vector& ant_states, SparseVector* features, - SparseVector* /*estimated_features*/, void* state) const { - pimpl_->SetSoftSynFeature(edge, features, ant_states, state); + const SentenceMetadata& /*smeta*/, const Hypergraph::Edge& edge, + const vector& /*ant_states*/, SparseVector* features, + SparseVector* /*estimated_features*/, void* /*state*/) const { + pimpl_->SetSoftSynFeature(edge, features); } string SoftSynFeature::usage(bool /*param*/, bool /*verbose*/) { @@ -369,8 +353,6 @@ struct SoftKBestSynFeatureImpl { ~SoftKBestSynFeatureImpl() { FreeSentenceVariables(); } - static int ReserveStateSize() { return 2 * sizeof(uint16_t); } - void InitializeInputSentence(const std::string& parse_file, const std::string& index_map_file) { FreeSentenceVariables(); @@ -384,26 +366,12 @@ struct SoftKBestSynFeatureImpl { } void SetSoftKBestSynFeature(const Hypergraph::Edge& edge, - SparseVector* features, - const vector& ant_states, - void* state) { - vector vec_pos; + SparseVector* features) { if (vec_parsed_tree_.size() == 0) return; - uint16_t* remnant = reinterpret_cast(state); - short int mapped_begin, mapped_end; MapIndex(edge.i_, edge.j_ - 1, mapped_begin, mapped_end); - remnant[0] = mapped_begin; - remnant[1] = mapped_end; - - for (size_t i = 0; i < edge.tail_nodes_.size(); i++) { - const uint16_t* astate = reinterpret_cast(ant_states[i]); - vec_pos.push_back(astate[0]); - vec_pos.push_back(astate[1]); - } - // soft feature for the whole span const MapDouble* pMapFeature = GenerateSoftFeature(mapped_begin, mapped_end, map_features_); @@ -646,7 +614,6 @@ struct SoftKBestSynFeatureImpl { SoftKBestSynFeature::SoftKBestSynFeature(std::string param) { pimpl_ = new SoftKBestSynFeatureImpl(param); - SetStateSize(SoftKBestSynFeatureImpl::ReserveStateSize()); name_ = "SoftKBestSynFeature"; } @@ -663,9 +630,9 @@ void SoftKBestSynFeature::PrepareForInput(const SentenceMetadata& smeta) { void SoftKBestSynFeature::TraversalFeaturesImpl( const SentenceMetadata& /* smeta */, const Hypergraph::Edge& edge, - const vector& ant_states, SparseVector* features, - SparseVector* /*estimated_features*/, void* state) const { - pimpl_->SetSoftKBestSynFeature(edge, features, ant_states, state); + const vector& /*ant_states*/, SparseVector* features, + SparseVector* /*estimated_features*/, void* /*state*/) const { + pimpl_->SetSoftKBestSynFeature(edge, features); } string SoftKBestSynFeature::usage(bool /*param*/, bool /*verbose*/) { -- cgit v1.2.3