src/Generic/theories/MentionConfidence.cpp
/* true if mention is a PRON or DESC and 
*  mention is the SUBJ of a prop in sentence N and
*  mention shares an entity with a named mention in sentence N-1 and 
*  the named mention is the SUBJ of a prop in sentence N-1.
*  and there is no other named SUBJ mention of the same entity type 
*     between these two mentions nor earlier on sentence N
*     that is not tied to the same entity
*/
true if mention is a PRON or DESC and
mention is the SUBJ of a prop in sentence N and
mention shares an entity with a named mention in sentence N-1 and
the named mention is the SUBJ of a prop in sentence N-1.
and there is no other named SUBJ mention of the same entity type
between these two mentions nor earlier on sentence N
that is not tied to the same entity
true if mention is a PRON or DESC and mention is the SUBJ of a prop in sentence N and mention shares an entity with a named mention in sentence N - 1 and the named mention is the SUBJ of a prop in sentence N - 1 . and there is no other named SUBJ mention of the same entity type between these two mentions nor earlier on sentence N that is not tied to the same entity
bool MentionConfidence::isMentPrevSentDoubleSubj(const Mention *ment, const Entity *ent, const EntitySet *entitySet, const DocTheory *docTheory){
	bool verbose = false;
	int ment_sent_no = ment->getSentenceNumber();
	if (ment_sent_no < 1) 
		return false;
	int prev_sent_no = ment_sent_no - 1;
	const Mention::Type mentType = ment->getMentionType();
	const SentenceTheory *prevSentTheory = docTheory->getSentenceTheory(prev_sent_no);
	const SentenceTheory *mentSentTheory = docTheory->getSentenceTheory(ment_sent_no);
	EntityType entType = ent->getType();
	if (mentType!= Mention::PRON && mentType != Mention::DESC)
		return false;
	int ment_token = ment->getNode()->getStartToken();
	std::string mentStr = getDebugTextFromMention(docTheory, ment);
	if (verbose){
		std::cerr << "\nMentPrevSentDouble called for ment =>"<< mentStr << "<= in sentence " << ment_sent_no <<std::endl;
		std::cerr << getDebugSentenceString(docTheory, ment_sent_no-1) << std::endl;
		std::cerr << getDebugSentenceString(docTheory, ment_sent_no) << std::endl;
	}
	if (mentStr == "who" || mentStr == "which"){
		if (verbose)
			std::cerr << "mentPrevSentDouble failed because ment was WH pronoun" << std::endl;
		return false;
	}
	bool ment_is_subject = isMentInSentWithArgRole(ment, docTheory, Argument::SUB_ROLE, ment_sent_no);	
	if (!ment_is_subject){
		if (verbose) 
			std::cerr << "mentPrevSentDouble failed because ment is not SUBJ" << std::endl;
		return false;
	}
	std::vector<const Mention *> prev_sentence_names = mentionsMTypeEType(docTheory, Mention::NAME, entType, prev_sent_no);
	if (prev_sentence_names.size() == 0){
		if (verbose)
			std::cerr << "mentPrevSentDouble failed for lack of names in previous sentence" << std::endl;
		return false;
	}
	std::vector<const Mention *> same_ent_prev_sent_name_ments;
	std::vector<const Mention *> wrong_ent_names;
	BOOST_FOREACH(const Mention *prev_name, prev_sentence_names) {
		if (entitySet->getEntityByMention(prev_name->getUID()) == ent)
			same_ent_prev_sent_name_ments.push_back(prev_name);
		else 
			wrong_ent_names.push_back(prev_name);
	}
	int early_name_token = ment_token;  
	int late_name_token = -1;  
	int first_name_token = ment_token; 
	bool name_is_subject = false;
	const Mention *same_ent_prev_sent_name_ment = 0;
	BOOST_FOREACH(const Mention *prev_ent_name, same_ent_prev_sent_name_ments) {
		if (isMentInSentWithArgRole(prev_ent_name, docTheory, Argument::SUB_ROLE, prev_sent_no)){
			name_is_subject = true;
			same_ent_prev_sent_name_ment = prev_ent_name;
			int nt = prev_ent_name->getNode()->getStartToken();
			if (nt < early_name_token)
				early_name_token = nt;
			if (nt > late_name_token)
				late_name_token = nt;
		}
	}
	const Mention *bad_subject = 0;
	const Mention *early_subject = 0;
	const Mention *intruding_subject = 0;
	std::vector<const Mention *> ment_sent_names = mentionsMTypeEType(docTheory, Mention::NAME, entType, ment_sent_no);
	BOOST_FOREACH(const Mention *ment_sent_name, ment_sent_names) {
		if (isMentInSentWithArgRole(ment_sent_name, docTheory, Argument::SUB_ROLE, ment_sent_no)){
			int nt = ment_sent_name->getNode()->getStartToken();
			if (nt < ment_token && entitySet->getEntityByMention(ment_sent_name->getUID()) != ent){
				first_name_token = nt;
				intruding_subject = ment_sent_name;
			}
		}
	}
	if (!name_is_subject){
		if (verbose)
			std::cerr << "\nbasic MentPrevSentDouble loses since name is not  SUBJ " <<std::endl;
		return false;
	}
	if (verbose){
		std::string entStr = getDebugTextFromMention(docTheory, same_ent_prev_sent_name_ment);
		std::cerr << "basic MentPrevSentDouble wins linking " << mentStr << " to name " << entStr << std::endl;
	}
	BOOST_FOREACH(const Mention *wrong_name, wrong_ent_names) {
		if (isMentInSentWithArgRole(wrong_name, docTheory, Argument::SUB_ROLE, prev_sent_no)){
			int nt = wrong_name->getNode()->getStartToken();
			if (nt < early_name_token)
				early_subject = wrong_name;
			else if (nt > late_name_token)
				bad_subject = wrong_name;
		}
	}
	if (bad_subject != 0){
		if (verbose){
			std::string badMentStr = getDebugTextFromMention(docTheory, bad_subject);
			std::cerr << "***********MentPrevSentDouble loses for bad_subj_name " << badMentStr << std::endl;
		}
		return false;
	}
	if (early_subject != 0){
		if (verbose){
			std::string earlyMentStr = getDebugTextFromMention(docTheory, early_subject);
			std::cerr << "***********MentPrevSentDouble loses for earlier subj in prev sentence " << earlyMentStr << std::endl;
		}
		return false;
	}
	if (intruding_subject != 0){
		if (verbose){
			std::string intruderMentStr = getDebugTextFromMention(docTheory, intruding_subject);
			std::cerr << "***********MentPrevSentDouble loses for same sent early subj_name " << intruderMentStr << std::endl;
		}
		return false;
	}
	return true;
}
bool MentionConfidence :: isMentPrevSentDoubleSubj ( const Mention * ment , const Entity * ent , const EntitySet * entitySet , const DocTheory * docTheory ) { bool verbose = false ; int ment_sent_no = ment -> getSentenceNumber ( ) ; if ( ment_sent_no < 1 ) return false ; int prev_sent_no = ment_sent_no - 1 ; const Mention :: Type mentType = ment -> getMentionType ( ) ; const SentenceTheory * prevSentTheory = docTheory -> getSentenceTheory ( prev_sent_no ) ; const SentenceTheory * mentSentTheory = docTheory -> getSentenceTheory ( ment_sent_no ) ; EntityType entType = ent -> getType ( ) ; if ( mentType != Mention :: PRON && mentType != Mention :: DESC ) return false ; int ment_token = ment -> getNode ( ) -> getStartToken ( ) ; std :: string mentStr = getDebugTextFromMention ( docTheory , ment ) ; if ( verbose ) { std :: cerr << " \n " << mentStr << " " << ment_sent_no << std :: endl ; std :: cerr << getDebugSentenceString ( docTheory , ment_sent_no - 1 ) << std :: endl ; std :: cerr << getDebugSentenceString ( docTheory , ment_sent_no ) << std :: endl ; } if ( mentStr == " " || mentStr == " " ) { if ( verbose ) std :: cerr << " " << std :: endl ; return false ; } bool ment_is_subject = isMentInSentWithArgRole ( ment , docTheory , Argument :: SUB_ROLE , ment_sent_no ) ; if ( ! ment_is_subject ) { if ( verbose ) std :: cerr << " " << std :: endl ; return false ; } std :: vector < const Mention * > prev_sentence_names = mentionsMTypeEType ( docTheory , Mention :: NAME , entType , prev_sent_no ) ; if ( prev_sentence_names . size ( ) == 0 ) { if ( verbose ) std :: cerr << " " << std :: endl ; return false ; } std :: vector < const Mention * > same_ent_prev_sent_name_ments ; std :: vector < const Mention * > wrong_ent_names ; BOOST_FOREACH ( const Mention * prev_name , prev_sentence_names ) { if ( entitySet -> getEntityByMention ( prev_name -> getUID ( ) ) == ent ) same_ent_prev_sent_name_ments . push_back ( prev_name ) ; else wrong_ent_names . push_back ( prev_name ) ; } int early_name_token = ment_token ; int late_name_token = -1 ; int first_name_token = ment_token ; bool name_is_subject = false ; const Mention * same_ent_prev_sent_name_ment = 0 ; BOOST_FOREACH ( const Mention * prev_ent_name , same_ent_prev_sent_name_ments ) { if ( isMentInSentWithArgRole ( prev_ent_name , docTheory , Argument :: SUB_ROLE , prev_sent_no ) ) { name_is_subject = true ; same_ent_prev_sent_name_ment = prev_ent_name ; int nt = prev_ent_name -> getNode ( ) -> getStartToken ( ) ; if ( nt < early_name_token ) early_name_token = nt ; if ( nt > late_name_token ) late_name_token = nt ; } } const Mention * bad_subject = 0 ; const Mention * early_subject = 0 ; const Mention * intruding_subject = 0 ; std :: vector < const Mention * > ment_sent_names = mentionsMTypeEType ( docTheory , Mention :: NAME , entType , ment_sent_no ) ; BOOST_FOREACH ( const Mention * ment_sent_name , ment_sent_names ) { if ( isMentInSentWithArgRole ( ment_sent_name , docTheory , Argument :: SUB_ROLE , ment_sent_no ) ) { int nt = ment_sent_name -> getNode ( ) -> getStartToken ( ) ; if ( nt < ment_token && entitySet -> getEntityByMention ( ment_sent_name -> getUID ( ) ) != ent ) { first_name_token = nt ; intruding_subject = ment_sent_name ; } } } if ( ! name_is_subject ) { if ( verbose ) std :: cerr << " \n " << std :: endl ; return false ; } if ( verbose ) { std :: string entStr = getDebugTextFromMention ( docTheory , same_ent_prev_sent_name_ment ) ; std :: cerr << " " << mentStr << " " << entStr << std :: endl ; } BOOST_FOREACH ( const Mention * wrong_name , wrong_ent_names ) { if ( isMentInSentWithArgRole ( wrong_name , docTheory , Argument :: SUB_ROLE , prev_sent_no ) ) { int nt = wrong_name -> getNode ( ) -> getStartToken ( ) ; if ( nt < early_name_token ) early_subject = wrong_name ; else if ( nt > late_name_token ) bad_subject = wrong_name ; } } if ( bad_subject != 0 ) { if ( verbose ) { std :: string badMentStr = getDebugTextFromMention ( docTheory , bad_subject ) ; std :: cerr << " " << badMentStr << std :: endl ; } return false ; } if ( early_subject != 0 ) { if ( verbose ) { std :: string earlyMentStr = getDebugTextFromMention ( docTheory , early_subject ) ; std :: cerr << " " << earlyMentStr << std :: endl ; } return false ; } if ( intruding_subject != 0 ) { if ( verbose ) { std :: string intruderMentStr = getDebugTextFromMention ( docTheory , intruding_subject ) ; std :: cerr << " " << intruderMentStr << std :: endl ; } return false ; } return true ; }
true if mention is a PRON or DESC and
mention is the SUBJ of a prop in sentence N and
mention shares an entity with a named mention in sentence N-1 and
the named mention is the SUBJ of a prop in sentence N-1.
true if mention is a PRON or DESC and mention is the SUBJ of a prop in sentence N and mention shares an entity with a named mention in sentence N - 1 and the named mention is the SUBJ of a prop in sentence N - 1 .
// initially set to an untrue upper limit
 // initially set to an untrue lower limit
 //intially set to untrue upper limit
 //std::cerr << "checking ment sentence for preceding subj NAME contenders" <<std::endl;
 //std::cerr << getDebugSentenceString(docTheory, ment_sent_no-1) << std::endl;
 //std::cerr << getDebugSentenceString(docTheory, ment_sent_no) << std::endl;
