src/PredFinder/elf/ElfDocument.cpp
/**
 * For a specified type, collects all of the individuals
 * that have that type, collects all of the relations
 * relevant to those individuals, and then clusters
 * individuals together, but only within a sentence.
 *
 * @param doc_info The Serif document contents and metadata.
 * @param domain_prefix The domain we're in, used to determine
 * clustering strategy.
 * @param coreferent_types A list of individuals that should be
 * candidates for clustering.
 *
 * @author nward@bbn.com
 * @date 2011.01.06
 **/
For a specified type, collects all of the individuals
that have that type, collects all of the relations
relevant to those individuals, and then clusters
individuals together, but only within a sentence.

@param doc_info The Serif document contents and metadata.
@param domain_prefix The domain we're in, used to determine
clustering strategy.
@param coreferent_types A list of individuals that should be
candidates for clustering.


For a specified type collects all of the individuals that have that type collects all of the relations relevant to those individuals and then clusters individuals together but only within a sentence . @param doc_info The Serif document contents and metadata . @param domain_prefix The domain we ' re in used to determine clustering strategy . @param coreferent_types A list of individuals that should be candidates for clustering .
void ElfDocument::do_sentence_level_individual_coreference(const DocTheory* doc_theory, 
														   const std::wstring& domain_prefix, 
														   const std::vector<std::wstring> & coreferent_types) {
	std::vector<ElfIndividualSet> individuals_to_coref_by_sentence;
	individuals_to_coref_by_sentence.resize(doc_theory->getNSentences());
	if (coreferent_types.size() > 0) {
		BOOST_FOREACH(std::wstring coreferent_type, coreferent_types) {
			if (coreferent_type != L"") {
				std::vector<ElfIndividualSet> typed_individuals_to_coref_by_sentence = get_individuals_by_type_and_sentence(doc_theory, coreferent_type);
				for (int i = 0; i < doc_theory->getNSentences(); i++) {
					BOOST_FOREACH(ElfIndividual_ptr typed_individual, typed_individuals_to_coref_by_sentence[i]) {
						individuals_to_coref_by_sentence[i].insert(typed_individual);
					}
				}
			}
		}
	}
	ElfIndividualUriMap clustered_individual_uri_map;
	BOOST_FOREACH(ElfIndividualSet individuals_to_coref, individuals_to_coref_by_sentence) {
		ElfIndividualCoreference_ptr coref_engine = boost::make_shared<ElfIndividualCoreference>(domain_prefix, true);
		BOOST_FOREACH(ElfIndividual_ptr individual, individuals_to_coref) {
			ElfRelationMap relations_for_individual = get_relations_by_individual(individual);
			coref_engine->add_cluster_member(individual, relations_for_individual);
		}
		coref_engine->combine_clusters();
		ElfIndividualUriMap sentence_clustered_individual_uri_map = coref_engine->get_individual_to_cluster_uri_map(_id);
		BOOST_FOREACH(ElfIndividualUriMap::value_type individual_uri_pair, sentence_clustered_individual_uri_map) {
			if (clustered_individual_uri_map.find(individual_uri_pair.first) == clustered_individual_uri_map.end()) {
				clustered_individual_uri_map.insert(individual_uri_pair);
			} else {
				SessionLogger::info("LEARNIT") << "individual " << individual_uri_pair.first << " already mapped, ignoring" << std::endl;
			}
		}
	}
	replace_individual_uris(clustered_individual_uri_map);
}
void ElfDocument :: do_sentence_level_individual_coreference ( const DocTheory * doc_theory , const std :: wstring & domain_prefix , const std :: vector < std :: wstring > & coreferent_types ) { std :: vector < ElfIndividualSet > individuals_to_coref_by_sentence ; individuals_to_coref_by_sentence . resize ( doc_theory -> getNSentences ( ) ) ; if ( coreferent_types . size ( ) > 0 ) { BOOST_FOREACH ( std :: wstring coreferent_type , coreferent_types ) { if ( coreferent_type != L" " ) { std :: vector < ElfIndividualSet > typed_individuals_to_coref_by_sentence = get_individuals_by_type_and_sentence ( doc_theory , coreferent_type ) ; for ( int i = 0 ; i < doc_theory -> getNSentences ( ) ; i ++ ) { BOOST_FOREACH ( ElfIndividual_ptr typed_individual , typed_individuals_to_coref_by_sentence [ i ] ) { individuals_to_coref_by_sentence [ i ] . insert ( typed_individual ) ; } } } } } ElfIndividualUriMap clustered_individual_uri_map ; BOOST_FOREACH ( ElfIndividualSet individuals_to_coref , individuals_to_coref_by_sentence ) { ElfIndividualCoreference_ptr coref_engine = boost :: make_shared < ElfIndividualCoreference > ( domain_prefix , true ) ; BOOST_FOREACH ( ElfIndividual_ptr individual , individuals_to_coref ) { ElfRelationMap relations_for_individual = get_relations_by_individual ( individual ) ; coref_engine -> add_cluster_member ( individual , relations_for_individual ) ; } coref_engine -> combine_clusters ( ) ; ElfIndividualUriMap sentence_clustered_individual_uri_map = coref_engine -> get_individual_to_cluster_uri_map ( _id ) ; BOOST_FOREACH ( ElfIndividualUriMap :: value_type individual_uri_pair , sentence_clustered_individual_uri_map ) { if ( clustered_individual_uri_map . find ( individual_uri_pair . first ) == clustered_individual_uri_map . end ( ) ) { clustered_individual_uri_map . insert ( individual_uri_pair ) ; } else { SessionLogger :: info ( " " ) << " " << individual_uri_pair . first << " " << std :: endl ; } } } replace_individual_uris ( clustered_individual_uri_map ) ; }
For a specified type, collects all of the individuals
 that have that type, collects all of the relations
 relevant to those individuals, and then clusters
 individuals together, but only within a sentence.
For a specified type collects all of the individuals that have that type collects all of the relations relevant to those individuals and then clusters individuals together but only within a sentence .
// Get all of the individuals that have the specified types in each sentence (or all individuals if none)
 // Do coreference sentence by sentence
 // Initialize the individual coreference engine in sentence mode
 // For each individual, collect all of its relevant relations
 //SessionLogger::info("LEARNIT") << "individuals: " << individuals_to_coref.size() << std::endl;
 // Get the relations for this individual (recursive)
 //SessionLogger::info("LEARNIT") << individual->get_best_uri() << " relation predicates: " << relations_for_individual.size() << std::endl;
 // Create a new cluster member and add it
 // Do the meat of the coreference
 // Get the map of old individual IDs to new individuals (reflecting cluster membership)
 // and add them to the document map
 // Make sure we haven't assigned a mapping for this individual already
 //SessionLogger::info("LEARNIT") << "Clustered " << clustered_individual_uri_map.size() << " Individuals" << std::endl;
 //BOOST_FOREACH(ElfIndividualUriMap::value_type individual_pair, clustered_individual_uri_map) {
 //	SessionLogger::info("LEARNIT") << individual_pair.first << " -> " << individual_pair.second << std::endl;
 //}
 // Update all of the changed individual URIs
