src/PredFinder/macros/ReadingMacroSet.cpp
/**
 * Sequentially tries applying all of the macros in
 * the specified set for the stage to the specified
 * document, generating an output document.
 *
 * If the input ELF document does not have the correct
 * contents for the specified stage of macro application,
 * throws an error.
 *
 * @param stage_name The stage for which rules should
 * be applied.
 * @param macro_sets All of the active macro sets.
 * @param document The document to transform.
 * @return The transformed document after running
 * through this stage.
 *
 * @author nward@bbn.com
 * @date 2010.10.08
 **/
Sequentially tries applying all of the macros in
the specified set for the stage to the specified
document, generating an output document.

If the input ELF document does not have the correct
contents for the specified stage of macro application,
throws an error.

@param stage_name The stage for which rules should
be applied.
@param macro_sets All of the active macro sets.
@param document The document to transform.
@return The transformed document after running
through this stage.


Sequentially tries applying all of the macros in the specified set for the stage to the specified document generating an output document . If the input ELF document does not have the correct contents for the specified stage of macro application throws an error . @param stage_name The stage for which rules should be applied . @param macro_sets All of the active macro sets . @param document The document to transform . @return The transformed document after running through this stage .
ElfDocument_ptr ReadingMacroSet::apply_macros(Symbol stage_name, ReadingMacroSetSortedSet macro_sets, 
											  const ElfDocument_ptr input_document) {
	std::stringstream error;
	ElfDocument_ptr document = boost::make_shared<ElfDocument>(input_document);
	if (stage_name == ReadingMacro::STAGE_BBN_SYM) {
		if (document->get_contents() == L"P-ELF") {
			document->set_contents(L"S-ELF");
		} else {
			error << "ELF contents '" << document->get_contents() << "' not valid input for stage '";
			error << stage_name << "', expected 'P-ELF'";
			throw UnexpectedInputException("ReadingMacroSet::apply(Symbol,ElfDocument_ptr)", error.str().c_str());
		}
	} else if (stage_name == ReadingMacro::STAGE_ERUDITE_SYM) {
		if (document->get_contents() == L"S-ELF") {
			document->set_contents(L"R-ELF");
		} else {
			error << "ELF contents '" << document->get_contents() << "' not valid input for stage '";
			error << stage_name << "', expected 'S-ELF'";
			throw UnexpectedInputException("ReadingMacroSet::apply(Symbol,ElfDocument_ptr)", error.str().c_str());
		}
	} else {
		error << "Cannot apply macro set: bad stage name '" << stage_name << "'";
		throw UnexpectedInputException("ReadingMacroSet::apply(Symbol,ElfDocument_ptr)", error.str().c_str());
	}
	if (stage_name == ReadingMacro::STAGE_BBN_SYM)
		document->split_duplicate_role_relations();
	BOOST_FOREACH(ReadingMacroSet_ptr macro_set, macro_sets) {
		macro_set->apply(stage_name, document);
	}
	if (stage_name == ReadingMacro::STAGE_ERUDITE_SYM && ReadingMacroSet::domain_prefix == L"ic") {
		std::vector<std::wstring> date_individuals;
		date_individuals.push_back(L"ic:Date");
		document->do_document_level_individual_coreference(ReadingMacroSet::domain_prefix, date_individuals);
		std::vector<std::wstring> count_individuals;
		count_individuals.push_back(L"ic:Count");
		document->do_document_level_individual_coreference(ReadingMacroSet::domain_prefix, count_individuals);
	}
	if (stage_name == ReadingMacro::STAGE_ERUDITE_SYM)
		document->convert_individuals_to_relations(ReadingMacroSet::domain_prefix);
	return document;
}
ElfDocument_ptr ReadingMacroSet :: apply_macros ( Symbol stage_name , ReadingMacroSetSortedSet macro_sets , const ElfDocument_ptr input_document ) { std :: stringstream error ; ElfDocument_ptr document = boost :: make_shared < ElfDocument > ( input_document ) ; if ( stage_name == ReadingMacro :: STAGE_BBN_SYM ) { if ( document -> get_contents ( ) == L" " ) { document -> set_contents ( L" " ) ; } else { error << " " << document -> get_contents ( ) << " " ; error << stage_name << " " ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } } else if ( stage_name == ReadingMacro :: STAGE_ERUDITE_SYM ) { if ( document -> get_contents ( ) == L" " ) { document -> set_contents ( L" " ) ; } else { error << " " << document -> get_contents ( ) << " " ; error << stage_name << " " ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } } else { error << " " << stage_name << " " ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } if ( stage_name == ReadingMacro :: STAGE_BBN_SYM ) document -> split_duplicate_role_relations ( ) ; BOOST_FOREACH ( ReadingMacroSet_ptr macro_set , macro_sets ) { macro_set -> apply ( stage_name , document ) ; } if ( stage_name == ReadingMacro :: STAGE_ERUDITE_SYM && ReadingMacroSet :: domain_prefix == L" " ) { std :: vector < std :: wstring > date_individuals ; date_individuals . push_back ( L" " ) ; document -> do_document_level_individual_coreference ( ReadingMacroSet :: domain_prefix , date_individuals ) ; std :: vector < std :: wstring > count_individuals ; count_individuals . push_back ( L" " ) ; document -> do_document_level_individual_coreference ( ReadingMacroSet :: domain_prefix , count_individuals ) ; } if ( stage_name == ReadingMacro :: STAGE_ERUDITE_SYM ) document -> convert_individuals_to_relations ( ReadingMacroSet :: domain_prefix ) ; return document ; }
Sequentially tries applying all of the macros in
 the specified set for the stage to the specified
 document, generating an output document.
Sequentially tries applying all of the macros in the specified set for the stage to the specified document generating an output document .
// Local error messages
 // Deep copy the input document so we don't overwrite anything unintentionally
 // Make sure the stage name is valid
 // This is a P-ELF -> S-ELF transformation
 // This is a S-ELF -> R-ELF transformation
 // If we're generating S-ELF, split relations that contain multiple args with the same role
 //   This is done before macro processing, in case duplicate roles interfere with macro matching
 // Try invoking each macro for this stage on this document and collect the results
 // Apply this macro set to the copy in-place
 // For some domains, cluster macro-generated individuals
 // Running the clustering engine is the easiest way to merge these as opposed to trying
 // to generate the individual's URI based on a predicate-specific value role
 // If we're generating R-ELF, convert individuals to relations
 // Return the converted document
