summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu, Ke <wuke@cs.umd.edu>2014-12-06 16:30:44 -0500
committerWu, Ke <wuke@cs.umd.edu>2014-12-06 16:30:44 -0500
commitb13b975a383fc2fb6c6200dd227cf6866d1cd7fb (patch)
treefd463c3c2ec29947fb45912aefd44a18060465cc
parent61ef7bfd7ee82f173715d391e9f297ad258d315b (diff)
Remove unnecessary state from SoftSynFeature
-rw-r--r--decoder/ff_soft_syn.cc51
1 files 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<double>* features,
- const vector<const void*>& ant_states, void* state) {
- vector<uint16_t> vec_pos;
+ SparseVector<double>* features) {
if (parsed_tree_ == NULL) return;
- uint16_t* remnant = reinterpret_cast<uint16_t*>(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<const uint16_t*>(ant_states[i]);
- vec_pos.push_back(astate[0]);
- vec_pos.push_back(astate[1]);
- }
-
// soft feature for the whole span
const vector<string> 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<const void*>& ant_states, SparseVector<double>* features,
- SparseVector<double>* /*estimated_features*/, void* state) const {
- pimpl_->SetSoftSynFeature(edge, features, ant_states, state);
+ const SentenceMetadata& /*smeta*/, const Hypergraph::Edge& edge,
+ const vector<const void*>& /*ant_states*/, SparseVector<double>* features,
+ SparseVector<double>* /*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<double>* features,
- const vector<const void*>& ant_states,
- void* state) {
- vector<uint16_t> vec_pos;
+ SparseVector<double>* features) {
if (vec_parsed_tree_.size() == 0) return;
- uint16_t* remnant = reinterpret_cast<uint16_t*>(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<const uint16_t*>(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<const void*>& ant_states, SparseVector<double>* features,
- SparseVector<double>* /*estimated_features*/, void* state) const {
- pimpl_->SetSoftKBestSynFeature(edge, features, ant_states, state);
+ const vector<const void*>& /*ant_states*/, SparseVector<double>* features,
+ SparseVector<double>* /*estimated_features*/, void* /*state*/) const {
+ pimpl_->SetSoftKBestSynFeature(edge, features);
}
string SoftKBestSynFeature::usage(bool /*param*/, bool /*verbose*/) {