summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 01:08:50 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-11 01:08:50 +0000
commit991969850eede6eca5c8724484175b1f3c0ddeff (patch)
tree2fcc0c46448c9dd0277465a4254da044255f9354
parent916944c8f234cbd4bdc06e5079f678f1835df426 (diff)
cout<<TRule
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@506 ec762483-ff6d-05da-a07a-a48fb63a330f
-rwxr-xr-xdecoder/cfg.cc7
-rw-r--r--decoder/trule.cc10
-rw-r--r--decoder/trule.h2
3 files changed, 13 insertions, 6 deletions
diff --git a/decoder/cfg.cc b/decoder/cfg.cc
index 281e9a00..c43ff9d0 100755
--- a/decoder/cfg.cc
+++ b/decoder/cfg.cc
@@ -36,8 +36,6 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus
Hypergraph::Edge const& e=hg.edges_[i];
TRule const& er=*e.rule_; vector<WordID> const& rule_rhs=target_side?er.e():er.f();
RHS &rhs=cfgr.rhs;
- int nr=rule_rhs.size();
- rhs.resize(nr);
prob_t &crp=cfgr.p;
crp=e.edge_prob_;
cfgr.lhs=e.head_node_;
@@ -46,6 +44,8 @@ void CFG::Init(Hypergraph const& hg,bool target_side,bool copy_features,bool pus
#endif
if (copy_features) cfgr.f=e.feature_values_;
if (push_weights) crp /=np[e.head_node_];
+ int nr=rule_rhs.size();
+ rhs.resize(nr);
for (int j=0;j<nr;++j) {
WordID w=rule_rhs[j];
if (w>0)
@@ -71,6 +71,9 @@ void CFG::PrintRule(std::ostream &o,RuleHandle rulei,CFGFormat const& f) const {
f.print_lhs(o,*this,r.lhs);
f.print_rhs(o,*this,r.rhs.begin(),r.rhs.end());
f.print_features(o,r.p,r.f);
+#if CFG_DEBUG
+ o<<f.partsep<<*r.rule;
+#endif
}
void CFG::Print(std::ostream &o,CFGFormat const& f) const {
diff --git a/decoder/trule.cc b/decoder/trule.cc
index f43fbb58..b9494951 100644
--- a/decoder/trule.cc
+++ b/decoder/trule.cc
@@ -9,6 +9,10 @@
using namespace std;
+ostream &operator<<(ostream &o,TRule const& r) {
+ o<<r.AsString(true);
+}
+
bool TRule::IsGoal() const {
static const int kGOAL(TD::Convert("Goal") * -1); // this will happen once, and after static init of trule.cc static dict.
return GetLHS() == kGOAL;
@@ -65,7 +69,7 @@ static WordID ConvertLHS(const string& w) {
}
}
-TRule* TRule::CreateRuleSynchronous(const std::string& rule) {
+TRule* TRule::CreateRuleSynchronous(const string& rule) {
TRule* res = new TRule;
if (res->ReadFromString(rule, true, false)) return res;
cerr << "[ERROR] Failed to creating rule from: " << rule << endl;
@@ -106,7 +110,7 @@ void assign_trule(const TRulePtr& new_rule, const unsigned int ctf_level, const
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";
+ cerr<<"\nWARNING: building rule from multi-line string "<<line<<".\n";
// backed off of this: it's failing to parse TRulePtr glue(new TRule("[" + goal_nt + "] ||| [" + goal_nt + ",1] ["+ default_nt + ",2] ||| [1] [2] ||| Glue=1")); thinks [1] is the features!
if (false && !(mono||strict)) {
// use lexer
@@ -114,7 +118,7 @@ bool TRule::ReadFromString(const string& line, bool strict, bool mono) {
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";
+ cerr<<"\nWARNING: more than one rule parsed from multi-line string; kept last: "<<line<<".\n";
return n_assigned;
}
diff --git a/decoder/trule.h b/decoder/trule.h
index 04058a41..e73fd0fe 100644
--- a/decoder/trule.h
+++ b/decoder/trule.h
@@ -104,7 +104,7 @@ class TRule {
bool Initialized() const { return e_.size(); }
std::string AsString(bool verbose = true) const;
-
+ friend std::ostream &operator<<(std::ostream &o,TRule const& r);
static TRule DummyRule() {
TRule res;
res.e_.resize(1, 0);