Пример #1
0
/// Perform an action.
/// Given an action, update the state by replacing the children
/// items in the action by the yielded item.
/// \todo Should add to ::_path
/// \todo Where is this called from?
void State::perform(const Production& p) {
	boost::shared_ptr<const State> initial = _initial_state;
	if (this->is_initial()) {
		assert(!initial);
		initial = boost::shared_ptr<const State>(new const State(*this));
	}

	ItemTokens newfrontier;

	ItemTokens::const_iterator i;
	ItemTokens::const_iterator childi = this->locate(p.action().children());
	for(i = _frontier.begin(); i != childi; i++) {
		newfrontier.push_back(*i);
	}
	newfrontier.push_back(p.itemtoken());
	i += p.action().children().size();
	for(; i != _frontier.end(); i++) {
		newfrontier.push_back(*i);
	}
	assert(_frontier.size() == newfrontier.size() + p.action().children().size() - 1);
	Debug::log(5) << "Old state: " << _frontier.to_string() << "\n";
	Debug::log(5) << "New state: " << newfrontier.to_string() << "\n";
	_frontier = newfrontier;
	_path.add(p);

	_initial_state = initial;
	assert(this->initial_state().is_initial());
}
Пример #2
0
/// Make a consistent parse decision from a parse path.
/// \param state The state in which the parse decision should be made.
/// \param path The parse path that gives us the order of the actions.
/// \sideeffect The action performed is popped from path.
void Parser::make_consistent_decision(ParseState& state, Path& path) {
	assert(parameter::treebank_has_parse_paths());

	// Just use the first production from the parse path.
	Production p = path.pop();
	Action a = p.action();
//	assert(m_parser->ItemToken_from_action(a) == p.itemtoken());
	Debug::log(5) << "Performing: " << a.to_string() << "\n";
	state.perform(a);

	stats::total_actions_add(1);

	// FIXME: Don't necessarily use _parse_span_chart.
	_parse_span_chart.subtract(SpanItem(a), _parse_prc, _parse_rcl, _parse_cbs);
}