summaryrefslogtreecommitdiff
path: root/decoder/trule.cc
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/trule.cc')
-rw-r--r--decoder/trule.cc24
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();