src/PredFinder/macros/GenerateIndividualOperator.cpp
GenerateIndividualOperator::GenerateIndividualOperator(Sexp* sexp, ReadingMacroExpressionShortcutMap shortcuts) : ReadingMacroOperator(sexp) {
	// Local error messages
	std::stringstream error;

	// Make sure we have an S-expression worth reading
	if (sexp->getNumChildren() < 4) {
		error << "Ill-formed generate-individual operator: need at least 4 top-level nodes; got " << sexp->getNumChildren();
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}

	// Make sure this is a generate individual expression
	if (sexp->getFirstChild()->isList() || sexp->getFirstChild()->getValue() !=  ReadingMacroOperator::GENERATE_INDIVIDUAL_SYM) {
		error << "Ill-formed generate-individual operator: need generate-individual expression; got ";
		error << " " << sexp->getFirstChild()->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}

	// Check if we need to start reading subexpressions after a shortcut expression
	int child = 1;
	if (_shortcut_name != Symbol())
		child++;

	// Get the required predicate subexpression
	if (sexp->getNthChild(child)->isAtom()) {
		// Get the referenced predicate shortcut
		ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::PREDICATE_SYM);
		_predicate = boost::static_pointer_cast<PredicateParameter>(expression);
	} else {
		// Read the predicate expression
		_predicate = boost::make_shared<PredicateParameter>(sexp->getNthChild(child));
	}

	// Get the required individual subexpression
	child++;
	if (sexp->getNthChild(child)->isAtom()) {
		// Get the referenced individual shortcut
		ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::INDIVIDUAL_SYM);
		_individual = boost::static_pointer_cast<IndividualParameter>(expression);
	} else {
		// Read the individual expression
		_individual = boost::make_shared<IndividualParameter>(sexp->getNthChild(child));
	}

	// Read the relation subexpressions (at least one, probably not more than two)
	for (child++; child < sexp->getNumChildren(); child++) {
		if (sexp->getNthChild(child)->isAtom()) {
			// Get the referenced relation shortcut
			ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::RELATION_SYM);
			_relations.insert(boost::static_pointer_cast<RelationParameter>(expression));
		} else {
			// Read the relation expression
			_relations.insert(boost::make_shared<RelationParameter>(sexp->getNthChild(child), shortcuts));
		}
	}

	// Make sure we had at least one relation
	if (_relations.size() < 1) {
		error << "Ill-formed generate-individual operator: need at least 1 relation subexpression; got ";
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
}
/**
 * Reads the generate-individual operator in some macro
 * 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/individual/relation
 * shortcuts which can be used in this operator.
 *
 * @author nward@bbn.com
 * @date 2010.10.07
 **/
Reads the generate-individual operator in some macro
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/individual/relation
shortcuts which can be used in this operator.


Reads the generate - individual operator in some macro 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 / individual / relation shortcuts which can be used in this operator .
GenerateIndividualOperator::GenerateIndividualOperator(Sexp* sexp, ReadingMacroExpressionShortcutMap shortcuts) : ReadingMacroOperator(sexp) {
	std::stringstream error;
	if (sexp->getNumChildren() < 4) {
		error << "Ill-formed generate-individual operator: need at least 4 top-level nodes; got " << sexp->getNumChildren();
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
	if (sexp->getFirstChild()->isList() || sexp->getFirstChild()->getValue() !=  ReadingMacroOperator::GENERATE_INDIVIDUAL_SYM) {
		error << "Ill-formed generate-individual operator: need generate-individual expression; got ";
		error << " " << sexp->getFirstChild()->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(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));
	}
	child++;
	if (sexp->getNthChild(child)->isAtom()) {
		ReadingMacroExpression_ptr expression = ReadingMacroExpression::from_shortcut(shortcuts, sexp, sexp->getNthChild(child)->getValue(), ReadingMacroParameter::INDIVIDUAL_SYM);
		_individual = boost::static_pointer_cast<IndividualParameter>(expression);
	} else {
		_individual = boost::make_shared<IndividualParameter>(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::RELATION_SYM);
			_relations.insert(boost::static_pointer_cast<RelationParameter>(expression));
		} else {
			_relations.insert(boost::make_shared<RelationParameter>(sexp->getNthChild(child), shortcuts));
		}
	}
	if (_relations.size() < 1) {
		error << "Ill-formed generate-individual operator: need at least 1 relation subexpression; got ";
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("GenerateIndividualOperator::GenerateIndividualOperator(Sexp*,ReadingMacroExpressionShortcutMap)", error.str().c_str());
	}
}
GenerateIndividualOperator :: GenerateIndividualOperator ( Sexp * sexp , ReadingMacroExpressionShortcutMap shortcuts ) : ReadingMacroOperator ( sexp ) { std :: stringstream error ; if ( sexp -> getNumChildren ( ) < 4 ) { error << " " << sexp -> getNumChildren ( ) ; error << " " << sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } if ( sexp -> getFirstChild ( ) -> isList ( ) || sexp -> getFirstChild ( ) -> getValue ( ) != ReadingMacroOperator :: GENERATE_INDIVIDUAL_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 ) ) ; } child ++ ; if ( sexp -> getNthChild ( child ) -> isAtom ( ) ) { ReadingMacroExpression_ptr expression = ReadingMacroExpression :: from_shortcut ( shortcuts , sexp , sexp -> getNthChild ( child ) -> getValue ( ) , ReadingMacroParameter :: INDIVIDUAL_SYM ) ; _individual = boost :: static_pointer_cast < IndividualParameter > ( expression ) ; } else { _individual = boost :: make_shared < IndividualParameter > ( 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 :: RELATION_SYM ) ; _relations . insert ( boost :: static_pointer_cast < RelationParameter > ( expression ) ) ; } else { _relations . insert ( boost :: make_shared < RelationParameter > ( sexp -> getNthChild ( child ) , shortcuts ) ) ; } } if ( _relations . size ( ) < 1 ) { error << " " ; error << " " << sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } }
Reads the generate-individual operator in some macro
 context from the specified S-expression.
Reads the generate - individual operator in some macro context from the specified S - expression .
// Local error messages
 // Make sure we have an S-expression worth reading
 // Make sure this is a generate individual 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
 // Get the required individual subexpression
 // Get the referenced individual shortcut
 // Read the individual expression
 // Read the relation subexpressions (at least one, probably not more than two)
 // Get the referenced relation shortcut
 // Read the relation expression
 // Make sure we had at least one relation
