src/PredFinder/macros/RelationParameter.cpp
/**
 * Using the roles defined in this parameter, extract
 * (and possibly rename) the matching roles in the
 * reference relation, generating a new relation
 * with deep copies of the matching arguments. Any roles
 * referring to the individual will get a deep copy of the
 * generated individual. If necessary, generates skolem
 * arguments.
 *
 * @param docid The ID of the document that will contain
 * this generated relation.
 * @param reference_relation The input relation from
 * which arguments are filtered.
 * @param individual_parameter Empty in a split context,
 * or the generated individual/value in a generate-individual
 * context.
 * @return A new relation containing the copied and
 * generated arguments.
 *
 * @author nward@bbn.com
 * @date 2010.11.01
 **/
Using the roles defined in this parameter, extract
(and possibly rename) the matching roles in the
reference relation, generating a new relation
with deep copies of the matching arguments. Any roles
referring to the individual will get a deep copy of the
generated individual. If necessary, generates skolem
arguments.

@param docid The ID of the document that will contain
this generated relation.
@param reference_relation The input relation from
which arguments are filtered.
@param individual_parameter Empty in a split context,
or the generated individual/value in a generate-individual
context.
@return A new relation containing the copied and
generated arguments.


Using the roles defined in this parameter extract ( and possibly rename ) the matching roles in the reference relation generating a new relation with deep copies of the matching arguments . Any roles referring to the individual will get a deep copy of the generated individual . If necessary generates skolem arguments . @param docid The ID of the document that will contain this generated relation . @param reference_relation The input relation from which arguments are filtered . @param individual_parameter Empty in a split context or the generated individual / value in a generate - individual context . @return A new relation containing the copied and generated arguments .
ElfRelation_ptr RelationParameter::to_elf_relation(ElfDocument_ptr document, ElfRelation_ptr reference_relation, IndividualParameter_ptr individual_parameter) {
	boost::hash<ElfRelation_ptr> relation_hasher;
	size_t relation_hash = relation_hasher(reference_relation);
	std::vector<ElfRelationArg_ptr> output_args;
	BOOST_FOREACH(RoleParameter_ptr role, _roles) {
		if (role->get_input_name() == L"individual") {
			if (individual_parameter.get() != NULL) {
				ElfRelationArg_ptr output_arg;
				if (individual_parameter->get_value() == L"") {
					ElfIndividual_ptr generated_individual = individual_parameter->to_elf_individual(document, reference_relation);
					output_arg = boost::make_shared<ElfRelationArg>(role->get_output_name(), generated_individual);
				} else {
					output_arg = boost::make_shared<ElfRelationArg>(role->get_output_name(), individual_parameter->get_type(), individual_parameter->get_value(), reference_relation->get_text(), reference_relation->get_start(), reference_relation->get_end());
				}
				output_args.push_back(output_arg);
			} else {
				throw UnexpectedInputException("RelationParameter::to_elf_relation(ElfDocument_ptr, ElfRelation_ptr, IndividualParameter_ptr)", "Input role 'individual' used without individual parameter");
			}
		} else if (!role->is_delete()) { 
			ElfRelationArg_ptr input_arg = reference_relation->get_arg(role->get_input_name());
			if (input_arg.get() != NULL) {
				ElfRelationArg_ptr output_arg = boost::make_shared<ElfRelationArg>(input_arg);
				output_arg->set_role(role->get_output_name());
				output_args.push_back(output_arg);
			} else if (role->get_skolem_type() != L"") {
				std::wstringstream value;
				value << document->replace_uri_prefix(role->get_skolem_type()) << "-" << document->get_id() << "-" << relation_hash;
				ElfRelationArg_ptr skolem_arg = boost::make_shared<ElfRelationArg>(role->get_output_name(), role->get_skolem_type(), value.str());
				output_args.push_back(skolem_arg);
			}
		}
	}
	ElfRelation_ptr relation = boost::make_shared<ElfRelation>(_predicate->get_name(), output_args, reference_relation->get_text(), reference_relation->get_start(), reference_relation->get_end(), reference_relation->get_confidence(), reference_relation->get_score_group());
	relation->set_source(reference_relation->get_source());
	return relation;
}
ElfRelation_ptr RelationParameter :: to_elf_relation ( ElfDocument_ptr document , ElfRelation_ptr reference_relation , IndividualParameter_ptr individual_parameter ) { boost :: hash < ElfRelation_ptr > relation_hasher ; size_t relation_hash = relation_hasher ( reference_relation ) ; std :: vector < ElfRelationArg_ptr > output_args ; BOOST_FOREACH ( RoleParameter_ptr role , _roles ) { if ( role -> get_input_name ( ) == L" " ) { if ( individual_parameter . get ( ) != NULL ) { ElfRelationArg_ptr output_arg ; if ( individual_parameter -> get_value ( ) == L" " ) { ElfIndividual_ptr generated_individual = individual_parameter -> to_elf_individual ( document , reference_relation ) ; output_arg = boost :: make_shared < ElfRelationArg > ( role -> get_output_name ( ) , generated_individual ) ; } else { output_arg = boost :: make_shared < ElfRelationArg > ( role -> get_output_name ( ) , individual_parameter -> get_type ( ) , individual_parameter -> get_value ( ) , reference_relation -> get_text ( ) , reference_relation -> get_start ( ) , reference_relation -> get_end ( ) ) ; } output_args . push_back ( output_arg ) ; } else { throw UnexpectedInputException ( " " , " " ) ; } } else if ( ! role -> is_delete ( ) ) { ElfRelationArg_ptr input_arg = reference_relation -> get_arg ( role -> get_input_name ( ) ) ; if ( input_arg . get ( ) != NULL ) { ElfRelationArg_ptr output_arg = boost :: make_shared < ElfRelationArg > ( input_arg ) ; output_arg -> set_role ( role -> get_output_name ( ) ) ; output_args . push_back ( output_arg ) ; } else if ( role -> get_skolem_type ( ) != L" " ) { std :: wstringstream value ; value << document -> replace_uri_prefix ( role -> get_skolem_type ( ) ) << " " << document -> get_id ( ) << " " << relation_hash ; ElfRelationArg_ptr skolem_arg = boost :: make_shared < ElfRelationArg > ( role -> get_output_name ( ) , role -> get_skolem_type ( ) , value . str ( ) ) ; output_args . push_back ( skolem_arg ) ; } } } ElfRelation_ptr relation = boost :: make_shared < ElfRelation > ( _predicate -> get_name ( ) , output_args , reference_relation -> get_text ( ) , reference_relation -> get_start ( ) , reference_relation -> get_end ( ) , reference_relation -> get_confidence ( ) , reference_relation -> get_score_group ( ) ) ; relation -> set_source ( reference_relation -> get_source ( ) ) ; return relation ; }
Using the roles defined in this parameter, extract
 (and possibly rename) the matching roles in the
 reference relation, generating a new relation
 with deep copies of the matching arguments.
Using the roles defined in this parameter extract ( and possibly rename ) the matching roles in the reference relation generating a new relation with deep copies of the matching arguments .
// Generate a hash value for the reference relation (used by skolems)
 // Loop over this relation parameter's role parameters, copying each one
 // Check if this role refers to a generated individual
 // Generated individual or specified value?
 // Generate an individual that will bridge this matching relation
 // Generate an arg with the specified type and value
 // Shouldn't happen
 // If the role contained a "(delete)" atom, don't pass it through.
 // Get the arg for this role, if any
 // Deep copy the argument and rename it
 // Generate a skolem argument type and value for this role
 //   Wasn't present in the reference relation, and the
 //   role parameter defines a skolem type
 // Return a new relation containing the mapped arguments
