diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 02:29:56 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 02:29:56 +0000 |
commit | 52c656a62d05135cf6ffd80249d5a44a07a40816 (patch) | |
tree | 7f9c7b0862dc02f2a0b3fbe2c6d6d4c3da9322f7 /decoder/trule.cc | |
parent | 4f99f17541c1fe104afbcf04e3d8d04ad9f1227a (diff) |
parse trule(string) using lexer - needs testing, affects earley_composer
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@497 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/trule.cc')
-rw-r--r-- | decoder/trule.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/decoder/trule.cc b/decoder/trule.cc index 170e3a95..330db67f 100644 --- a/decoder/trule.cc +++ b/decoder/trule.cc @@ -4,6 +4,8 @@ #include "stringlib.h" #include "tdict.h" +#include "rule_lexer.h" +#include "threadlocal.h" using namespace std; @@ -91,7 +93,29 @@ TRule* TRule::CreateRuleMonolingual(const string& rule) { return new TRule(rule, false, true); } +namespace { +// callback for lexer +THREADLOCAL int n_assigned=0; +void assign_trule(const TRulePtr& new_rule, const unsigned int ctf_level, const TRulePtr& coarse_rule, void* extra) { + TRule *assignto=(TRule *)extra; + *assignto=*new_rule; +} + +} + bool TRule::ReadFromString(const string& line, bool strict, bool mono) { + if (!is_single_line_stripped(line)) + std::cerr<<"\nWARNING: building rule from multi-line string "<<line<<".\n"; + if (!(mono||strict)) { + // use lexer + istringstream il(line); + n_assigned=0; + RuleLexer::ReadRules(&il,assign_trule,this); + if (n_assigned>1) + std::cerr<<"\nWARNING: more than one rule parsed from multi-line string; kept last: "<<line<<".\n"; + return n_assigned; + } + e_.clear(); f_.clear(); scores_.clear(); |