forked from GitHub/gf-core
pgf_expr_prob is now compatible with the parse model
This commit is contained in:
@@ -1149,23 +1149,30 @@ exit:
|
||||
PgfExpr PgfExprProbEstimator::eabs(PgfBindType bind_type, PgfText *name, PgfExpr body)
|
||||
{
|
||||
m->match_expr(this, body);
|
||||
cat_prob = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PgfExpr PgfExprProbEstimator::eapp(PgfExpr fun, PgfExpr arg)
|
||||
{
|
||||
m->match_expr(this, fun);
|
||||
prob_t tmp = cat_prob_total;
|
||||
cat_prob_total = 0;
|
||||
m->match_expr(this, arg);
|
||||
cat_prob_total = tmp + cat_prob;
|
||||
m->match_expr(this, fun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PgfExpr PgfExprProbEstimator::elit(PgfLiteral lit)
|
||||
{
|
||||
cat_prob = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PgfExpr PgfExprProbEstimator::emeta(PgfMetaId meta_id)
|
||||
{
|
||||
prob += cat_prob_total;
|
||||
cat_prob = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1173,16 +1180,25 @@ PgfExpr PgfExprProbEstimator::efun(PgfText *name)
|
||||
{
|
||||
ref<PgfAbsFun> absfun =
|
||||
namespace_lookup(pgf->abstract.funs, name);
|
||||
if (absfun == 0)
|
||||
if (absfun == 0) {
|
||||
prob = INFINITY;
|
||||
else
|
||||
cat_prob = INFINITY;
|
||||
} else {
|
||||
prob += absfun->prob;
|
||||
|
||||
ref<PgfAbsCat> abscat =
|
||||
namespace_lookup(pgf->abstract.cats, &absfun->type->name);
|
||||
if (abscat == 0)
|
||||
cat_prob = INFINITY;
|
||||
else
|
||||
cat_prob = abscat->prob;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PgfExpr PgfExprProbEstimator::evar(int index)
|
||||
{
|
||||
cat_prob = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,12 +198,16 @@ class PGF_INTERNAL_DECL PgfExprProbEstimator : public PgfUnmarshaller {
|
||||
PgfPGF *pgf;
|
||||
PgfMarshaller *m;
|
||||
prob_t prob;
|
||||
prob_t cat_prob;
|
||||
prob_t cat_prob_total;
|
||||
|
||||
public:
|
||||
PgfExprProbEstimator(PgfPGF *pgf, PgfMarshaller *marshaller) {
|
||||
this->pgf = pgf;
|
||||
this->m = marshaller;
|
||||
this->prob = 0;
|
||||
this->prob = 0;
|
||||
this->cat_prob = 0;
|
||||
this->cat_prob_total = 0;
|
||||
}
|
||||
|
||||
virtual PgfExpr eabs(PgfBindType bind_type, PgfText *name, PgfExpr body);
|
||||
|
||||
Reference in New Issue
Block a user