src/PredFinder/inference/EIUtils.cpp
/** 
 * This function attempts to determine whether a Nation-State is the predominant ("focus") location for a given article.
 *
 * Approach: Find the most common Nation in the document. Consider it the focus location IF
 *   -- It occurs in the first N sentences of the document
 *   -- No other Nation is mentioned in the first N sentences of the document.
 *
 * The most reasonable value for N appears to be 3, except when those first three sentences are very short,
 *   meaning that they are probably a deeply split-up dateline.
 *
 */
This function attempts to determine whether a Nation-State is the predominant ("focus") location for a given article.

Find the most common Nation in the document. Consider it the focus location IF
It occurs in the first N sentences of the document
No other Nation is mentioned in the first N sentences of the document.

The most reasonable value for N appears to be 3, except when those first three sentences are very short,
meaning that they are probably a deeply split-up dateline.
This function attempts to determine whether a Nation - State is the predominant ( " focus " ) location for a given article . Find the most common Nation in the document . Consider it the focus location IF It occurs in the first N sentences of the document No other Nation is mentioned in the first N sentences of the document . The most reasonable value for N appears to be 3 except when those first three sentences are very short meaning that they are probably a deeply split - up dateline .
const Mention * EIUtils::identifyFocusNationState(EIDocData_ptr docData, bool ic) {
	const DocTheory *docTheory = docData->getDocTheory();
	EntitySubtype nationSubtype;
	try {
		nationSubtype = EntitySubtype(Symbol(L"GPE.Nation"));
	} catch ( ... ) {
		return 0;
	}
	const Entity* most_common_entity = 0;
	ElfIndividual_ptr most_common_individual = ElfIndividual_ptr();
	int max_mentions = 0;
	ElfIndividualSet nationaStateIndividuals = ic?
		docData->get_individuals_by_type(L"ic:NationState")
		:docData->get_individuals_by_type();
	BOOST_FOREACH(ElfIndividual_ptr individual, nationaStateIndividuals) {
		if (!individual->has_entity_id())
			continue;
		Entity *ent = docData->getEntity(individual->get_entity_id());
		if (ent == 0 || ent->guessEntitySubtype(docTheory) != nationSubtype)
			continue;
		if (ent->getNMentions() > max_mentions) {
			most_common_entity = ent;
			most_common_individual = individual;
			max_mentions = ent->getNMentions();
		}
	}
	if (most_common_entity == 0)
		return 0;
	std::set<Entity *> earlyNations;
	const Mention *earlyMCEMention = 0;
	int tokens_so_far = 0;
	for (int sentno = 0; sentno < docTheory->getNSentences(); sentno++) {
		MentionSet *ms = docTheory->getSentenceTheory(sentno)->getMentionSet();
		for (int m = 0; m < ms->getNMentions(); m++) {
			const Mention *ment = ms->getMention(m);
			Entity *ent = docTheory->getEntitySet()->getEntityByMention(ment->getUID());
			if (ent != 0 && ent->guessEntitySubtype(docTheory) == nationSubtype)
				earlyNations.insert(ent);
			if (earlyMCEMention == 0 && ent == most_common_entity && ment->getMentionType() == Mention::NAME)
				earlyMCEMention = ment;
		}
		tokens_so_far += docTheory->getSentenceTheory(sentno)->getTokenSequence()->getNTokens();
		if (tokens_so_far > 50)
			break;
		if (sentno >= 4)
			break;
		if (sentno >= 3 && tokens_so_far >= 20)
			break;
	}
	if (earlyNations.size() > 1 || earlyMCEMention == 0)
		return 0;
	return earlyMCEMention;
}
const Mention * EIUtils :: identifyFocusNationState ( EIDocData_ptr docData , bool ic ) { const DocTheory * docTheory = docData -> getDocTheory ( ) ; EntitySubtype nationSubtype ; try { nationSubtype = EntitySubtype ( Symbol ( L" " ) ) ; } catch ( ... ) { return 0 ; } const Entity * most_common_entity = 0 ; ElfIndividual_ptr most_common_individual = ElfIndividual_ptr ( ) ; int max_mentions = 0 ; ElfIndividualSet nationaStateIndividuals = ic ? docData -> get_individuals_by_type ( L" " ) : docData -> get_individuals_by_type ( ) ; BOOST_FOREACH ( ElfIndividual_ptr individual , nationaStateIndividuals ) { if ( ! individual -> has_entity_id ( ) ) continue ; Entity * ent = docData -> getEntity ( individual -> get_entity_id ( ) ) ; if ( ent == 0 || ent -> guessEntitySubtype ( docTheory ) != nationSubtype ) continue ; if ( ent -> getNMentions ( ) > max_mentions ) { most_common_entity = ent ; most_common_individual = individual ; max_mentions = ent -> getNMentions ( ) ; } } if ( most_common_entity == 0 ) return 0 ; std :: set < Entity * > earlyNations ; const Mention * earlyMCEMention = 0 ; int tokens_so_far = 0 ; for ( int sentno = 0 ; sentno < docTheory -> getNSentences ( ) ; sentno ++ ) { MentionSet * ms = docTheory -> getSentenceTheory ( sentno ) -> getMentionSet ( ) ; for ( int m = 0 ; m < ms -> getNMentions ( ) ; m ++ ) { const Mention * ment = ms -> getMention ( m ) ; Entity * ent = docTheory -> getEntitySet ( ) -> getEntityByMention ( ment -> getUID ( ) ) ; if ( ent != 0 && ent -> guessEntitySubtype ( docTheory ) == nationSubtype ) earlyNations . insert ( ent ) ; if ( earlyMCEMention == 0 && ent == most_common_entity && ment -> getMentionType ( ) == Mention :: NAME ) earlyMCEMention = ment ; } tokens_so_far += docTheory -> getSentenceTheory ( sentno ) -> getTokenSequence ( ) -> getNTokens ( ) ; if ( tokens_so_far > 50 ) break ; if ( sentno >= 4 ) break ; if ( sentno >= 3 && tokens_so_far >= 20 ) break ; } if ( earlyNations . size ( ) > 1 || earlyMCEMention == 0 ) return 0 ; return earlyMCEMention ; }
This function attempts to determine whether a Nation-State is the predominant ("focus") location for a given article.
This function attempts to determine whether a Nation - State is the predominant ( " focus " ) location for a given article .
// You MUST check this; the constructor will throw if Nation is not a valid subtype
 // Find the most common entity in the document
 // Look at the first few sentences of the document to find the first name mention of 
 //   our most_common_entity. Keep track of all nations seen.
 // We want to look at the first few sentences, until we either hit 50 tokens, 4 sentences,
 //   or 3 sentences with 20 tokens seen. This last condition allows for us to see a fourth
 //   sentence iff the first few sentences are very short, e.g. a heavily split dateline.
 // If we saw more than one nation in the first few sentences, return 0.
 // If we did not see a name mention of our most_common_entity in the first few sentences, return 0.
