src/PredFinder/elf/ElfRelationFactory.cpp
/**
 * Given an arg_vec, produce a relation, and if output_relations does not already contain it, add it.
 *
 * @param arg_vec A vector of the args from which the relation will be constructed.
 * @param pattern_set_name Name of the pattern set (for filling in the src attribute).
 * @param top_level_id Top-level pattern ID (for filling in the src attribute); blank for LearnIt.
 * @param output_relations Passed by reference; may contain zero or more relations when passed in;
 * when returned, will contain one additional relation (if it does not match any in the original multiset).
 *
 * @author afrankel@bbn.com
 * @date 2011.07.06
 **/
Given an arg_vec, produce a relation, and if output_relations does not already contain it, add it.

@param arg_vec A vector of the args from which the relation will be constructed.
@param pattern_set_name Name of the pattern set (for filling in the src attribute).
@param top_level_id Top-level pattern ID (for filling in the src attribute); blank for LearnIt.
@param output_relations Passed by reference; may contain zero or more relations when passed in;
when returned, will contain one additional relation (if it does not match any in the original multiset).


Given an arg_vec produce a relation and if output_relations does not already contain it add it . @param arg_vec A vector of the args from which the relation will be constructed . @param pattern_set_name Name of the pattern set ( for filling in the src attribute ) . @param top_level_id Top - level pattern ID ( for filling in the src attribute ) ; blank for LearnIt . @param output_relations Passed by reference ; may contain zero or more relations when passed in ; when returned will contain one additional relation ( if it does not match any in the original multiset ) .
void ElfRelationFactory::add_relation_from_arg_vec(const std::vector<ElfRelationArg_ptr> & arg_vec, 
												   const std::wstring & pattern_set_name,
												   const std::wstring & top_level_id,
												   ElfRelationMultisetSortedByName & output_relations) {
	typedef ElfRelationMultisetSortedByName::const_iterator RMSConstIter;
	typedef pair<RMSConstIter, RMSConstIter> RMSConstIterPair;
	static ElfRelation_name_less_than comp_obj;
	if (arg_vec.size() <= 1) { 
		return;
	}
	ElfRelation_ptr relation = boost::make_shared<ElfRelation> (pattern_set_name, arg_vec, L"", 
		EDTOffset(), EDTOffset(), Pattern::UNSPECIFIED_SCORE, Pattern::UNSPECIFIED_SCORE_GROUP);
	bool found_match(false);
	RMSConstIterPair p = equal_range(output_relations.begin(),	output_relations.end(), 
		relation, comp_obj);
	for (RMSConstIter iter = p.first; iter != p.second; ++iter) {
		if ((*iter)->offsetless_equals(relation)) {
			found_match = true;
			break;
		}
	}
	if (!found_match) {
		std::wstring src(L"bbn:checker-");
		src += pattern_set_name;
        src += L"-";
        src += top_level_id;
		relation->set_source(src);
		output_relations.insert(relation);
	}
}
void ElfRelationFactory :: add_relation_from_arg_vec ( const std :: vector < ElfRelationArg_ptr > & arg_vec , const std :: wstring & pattern_set_name , const std :: wstring & top_level_id , ElfRelationMultisetSortedByName & output_relations ) { typedef ElfRelationMultisetSortedByName :: const_iterator RMSConstIter ; typedef pair < RMSConstIter , RMSConstIter > RMSConstIterPair ; static ElfRelation_name_less_than comp_obj ; if ( arg_vec . size ( ) <= 1 ) { return ; } ElfRelation_ptr relation = boost :: make_shared < ElfRelation > ( pattern_set_name , arg_vec , L" " , EDTOffset ( ) , EDTOffset ( ) , Pattern :: UNSPECIFIED_SCORE , Pattern :: UNSPECIFIED_SCORE_GROUP ) ; bool found_match ( false ) ; RMSConstIterPair p = equal_range ( output_relations . begin ( ) , output_relations . end ( ) , relation , comp_obj ) ; for ( RMSConstIter iter = p . first ; iter != p . second ; ++ iter ) { if ( ( * iter ) -> offsetless_equals ( relation ) ) { found_match = true ; break ; } } if ( ! found_match ) { std :: wstring src ( L" " ) ; src += pattern_set_name ; src += L" " ; src += top_level_id ; relation -> set_source ( src ) ; output_relations . insert ( relation ) ; } }
Given an arg_vec, produce a relation, and if output_relations does not already contain it, add it.
Given an arg_vec produce a relation and if output_relations does not already contain it add it .
// if arg_vec.size == 1, we have an individual, not a relation
 // If the relation is not already contained in *output_relations, copy it over.
 // If equal_range() produces a nonempty range, we found a match in terms of relation name, 
 // but we still perform offsetless_equals to look for a full match. This is quicker
 // than using offsetless_equals to do the sorting and matching in the first place.
