src/PredFinder/macros/RelationParameter.cpp
/**
 * Reads the relation parameter in some operator
 * context from the specified S-expression.
 *
 * @param sexp The read S-expression.
 * @param shortcuts A map storing parameters/operators
 * by shortcut name; used to look up predicate/role
 * shortcuts which can be used in this parameter.
 *
 * @author nward@bbn.com
 * @date 2010.10.06
 **/
Reads the relation parameter in some operator
context from the specified S-expression.

@param sexp The read S-expression.
@param shortcuts A map storing parameters/operators
by shortcut name; used to look up predicate/role
shortcuts which can be used in this parameter.


Reads the relation parameter in some operator context from the specified S - expression . @param sexp The read S - expression . @param shortcuts A map storing parameters / operators by shortcut name ; used to look up predicate / role shortcuts which can be used in this parameter .
RelationParameter::RelationParameter(Sexp* sexp, ReadingMacroExpressionShortcutMap shortcuts) : ReadingMacroParameter(sexp) {
	std::stringstream error;
	if (sexp->getNumChildren() <  3) {
		error << "Ill-formed relation parameter: need at least 3 top-level nodes; got " << sexp->getNumChildren();
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("RelationParameter::RelationParameter(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
	if (sexp->getFirstChild()->isList() || sexp->getFirstChild()->getValue() !=  ReadingMacroParameter::RELATION_SYM) {
		error << "Ill-formed relation parameter: need relation expression; got ";
		error << " " << sexp->getFirstChild()->to_debug_string();
		throw UnexpectedInputException("RelationParameter::RelationParameter(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
	int child = 1;
	if (_shortcut_name != Symbol())
		child++;
	if (sexp->getNthChild(child)->isAtom()) {
		ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::PREDICATE_SYM);
		_predicate = boost::static_pointer_cast<PredicateParameter>(expression);
	} else {
		_predicate = boost::make_shared<PredicateParameter>(sexp->getNthChild(child));
	}
	for (child++; child < sexp->getNumChildren(); child++) {
		if (sexp->getNthChild(child)->isAtom()) {
			ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::ROLE_SYM);
			_roles.insert(boost::static_pointer_cast<RoleParameter>(expression));
		} else {
			_roles.insert(boost::make_shared<RoleParameter>(sexp->getNthChild(child)));
		}
	}
	if (_roles.size() < 1) {
		error << "Ill-formed relation parameter: need at least 1 role subexpression; got ";
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("RelationParameter::RelationParameter(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
}
RelationParameter :: RelationParameter ( Sexp * sexp , ReadingMacroExpressionShortcutMap shortcuts ) : ReadingMacroParameter ( sexp ) { std :: stringstream error ; if ( sexp -> getNumChildren ( ) < 3 ) { error << " " << sexp -> getNumChildren ( ) ; error << " " << sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } if ( sexp -> getFirstChild ( ) -> isList ( ) || sexp -> getFirstChild ( ) -> getValue ( ) != ReadingMacroParameter :: RELATION_SYM ) { error << " " ; error << " " << sexp -> getFirstChild ( ) -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } int child = 1 ; if ( _shortcut_name != Symbol ( ) ) child ++ ; if ( sexp -> getNthChild ( child ) -> isAtom ( ) ) { ReadingMacroExpression_ptr expression = ReadingMacroExpression :: from_shortcut ( shortcuts , sexp , sexp -> getNthChild ( child ) -> getValue ( ) , ReadingMacroParameter :: PREDICATE_SYM ) ; _predicate = boost :: static_pointer_cast < PredicateParameter > ( expression ) ; } else { _predicate = boost :: make_shared < PredicateParameter > ( sexp -> getNthChild ( child ) ) ; } for ( child ++ ; child < sexp -> getNumChildren ( ) ; child ++ ) { if ( sexp -> getNthChild ( child ) -> isAtom ( ) ) { ReadingMacroExpression_ptr expression = ReadingMacroExpression :: from_shortcut ( shortcuts , sexp , sexp -> getNthChild ( child ) -> getValue ( ) , ReadingMacroParameter :: ROLE_SYM ) ; _roles . insert ( boost :: static_pointer_cast < RoleParameter > ( expression ) ) ; } else { _roles . insert ( boost :: make_shared < RoleParameter > ( sexp -> getNthChild ( child ) ) ) ; } } if ( _roles . size ( ) < 1 ) { error << " " ; error << " " << sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } }
Reads the relation parameter in some operator
 context from the specified S-expression.
Reads the relation parameter in some operator context from the specified S - expression .
// Local error messages
 // Make sure we have an S-expression worth reading
 // Make sure this is a relation expression
 // Check if we need to start reading subexpressions after a shortcut expression
 // Get the required predicate subexpression
 // Get the referenced predicate shortcut
 // Read the predicate expression
 // Read the role subexpressions (at least one, probably not more than two)
 // Get the referenced predicate shortcut
 // Read the role expression
 // Make sure we had at least one role
