diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-07 00:31:04 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-07 00:31:04 +0000 |
commit | f9d54fd08e217c7bca19f7c821a64d8ae9d81a2a (patch) | |
tree | e53c6b108452a41737d602f7d7c3ebc8ce5d9ed1 /decoder | |
parent | fad32b56bde2052212bbbc6e9ab89f7edc0d4869 (diff) |
usage for FSA features
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@485 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/cdec.cc | 4 | ||||
-rw-r--r-- | decoder/cdec_ff.cc | 2 | ||||
-rw-r--r-- | decoder/ff_factory.cc | 17 | ||||
-rw-r--r-- | decoder/ff_factory.h | 4 |
4 files changed, 24 insertions, 3 deletions
diff --git a/decoder/cdec.cc b/decoder/cdec.cc index e896a484..a7c99307 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -200,14 +200,14 @@ void InitCommandLine(int argc, char** argv, OracleBleu &ob, po::variables_map* c if (conf.count("list_feature_functions")) { cerr << "Available feature functions (specify with -F; describe with -u FeatureName):\n"; ff_registry.DisplayList(); - cerr << "Available feature functions (specify with --fsa_feature_function):\n"; + cerr << "Available FSA feature functions (specify with --fsa_feature_function):\n"; fsa_ff_registry.DisplayList(); cerr << endl; exit(1); } if (conf.count("usage")) { - cout<<ff_registry.usage(str("usage",conf),true,true)<<endl; + ff_usage(str("usage",conf)); exit(0); } if (conf.count("help")) { diff --git a/decoder/cdec_ff.cc b/decoder/cdec_ff.cc index 39f018e1..6edac126 100644 --- a/decoder/cdec_ff.cc +++ b/decoder/cdec_ff.cc @@ -23,7 +23,7 @@ void register_feature_functions() { //TODO: worthless example target FSA ffs. remove later ff_registry.Register(new FFFactory<WordPenaltyFromFsa>); // same as WordPenalty, but implemented using ff_fsa - ff_registry.Register(new FFFactory<FeatureFunctionFromFsa<SameFirstLetter> >); + RegisterFsaImpl<SameFirstLetter>(true,false); ff_registry.Register(new FFFactory<FeatureFunctionFromFsa<LongerThanPrev> >); ff_registry.Register(new FFFactory<FeatureFunctionFromFsa<ShorterThanPrev> >); diff --git a/decoder/ff_factory.cc b/decoder/ff_factory.cc index b3aeeac1..767cc675 100644 --- a/decoder/ff_factory.cc +++ b/decoder/ff_factory.cc @@ -2,6 +2,7 @@ #include "ff.h" #include "stringlib.h" +#include <stdexcept> using boost::shared_ptr; using namespace std; @@ -27,6 +28,10 @@ bool UntypedFactoryRegistry::parse_debug(std::string & param) { return debug; } +bool UntypedFactoryRegistry::have(std::string const& ffname) { + return reg_.find(ffname)!=reg_.end(); +} + void UntypedFactoryRegistry::DisplayList() const { for (Factmap::const_iterator it = reg_.begin(); it != reg_.end(); ++it) { @@ -75,3 +80,15 @@ struct null_deleter boost::shared_ptr<FsaFFRegistry> global_fsa_ff_registry(&fsa_ff_registry,null_deleter()); boost::shared_ptr<FFRegistry> global_ff_registry(&ff_registry,null_deleter()); */ + +void ff_usage(std::string const& n,std::ostream &out) +{ + bool have=ff_registry.have(n); + if (have) + cout<<"FF "<<ff_registry.usage(n,true,true)<<endl; + if (fsa_ff_registry.have(n)) + cout<<"Fsa FF "<<fsa_ff_registry.usage(n,true,true)<<endl; + else if (!have) + throw std::runtime_error("Unknown feature "+n); +} + diff --git a/decoder/ff_factory.h b/decoder/ff_factory.h index e5821d44..102e709c 100644 --- a/decoder/ff_factory.h +++ b/decoder/ff_factory.h @@ -63,6 +63,7 @@ struct FsaFactory : public FactoryBase<FsaFeatureFunction> { struct UntypedFactoryRegistry { std::string usage(std::string const& ffname,bool params=true,bool verbose=true) const; + bool have(std::string const& ffname); void DisplayList() const; void Register(const std::string& ffname, UntypedFactory* factory); void Register(UntypedFactory* factory); @@ -106,6 +107,9 @@ extern FsaFFRegistry fsa_ff_registry; inline FsaFFRegistry & global_fsa_ff_registry() { return fsa_ff_registry; } extern FFRegistry ff_registry; inline FFRegistry & global_ff_registry() { return ff_registry; } + +void ff_usage(std::string const& name,std::ostream &out=std::cout); + /* extern boost::shared_ptr<FsaFFRegistry> global_fsa_ff_registry; extern boost::shared_ptr<FFRegistry> global_ff_registry; |