src/PredFinder/common/ElfMultiDoc.cpp
/**
 * Use date to determine whether it's more likely that "Bush" refers to Papa Bush or Baby Bush.
 **/
Use date to determine whether it's more likely that "Bush" refers to Papa Bush or Baby Bush.
Use date to determine whether it ' s more likely that " Bush " refers to Papa Bush or Baby Bush .
std::wstring ElfMultiDoc::get_best_name_for_bush(const std::wstring & best_name, const Entity* entity, const DocTheory* doc_theory,
												 std::wstring & bound_uri_out, XDocIdType & xdoc_id_out) {
	bound_uri_out = L"";
	xdoc_id_out = XDocIdType();
	std::wstring normalized_name_str = UnicodeUtil::normalizeTextString(best_name);
	if(entity == 0)
		return L"";
	if(doc_theory == 0)
		return L"";
	if(normalized_name_str.find(L"bush") == std::wstring::npos)
		return L"";
	std::wstring docid = doc_theory->getDocument()->getName().to_string();
	std::wstring doc_date;
	std::wstring doc_additional_time;
	bool before_2000 = false;
	ElfMultiDoc::temporal_normalizer->normalizeDocumentDate(doc_theory, doc_date, doc_additional_time);
	if(doc_date.size() > 2){
		std::wstring begin = doc_date.substr(0,2);
		if(begin == L"19")
			before_2000 = true;
	}
	XDocIdType w_xid = get_xdoc_id(Symbol(L"PER"), L"george w bush");
	XDocIdType hw_xid = get_xdoc_id(Symbol(L"PER"), L"george h w bush");
	if(!hw_xid.is_valid())
		hw_xid = get_xdoc_id(Symbol(L"PER"), L"george hw bush");
	std::wstring w_bound = find_bound_uri_from_name_w_or_wo_docid(L"george w bush", docid);
	std::wstring hw_bound = find_bound_uri_from_name_w_or_wo_docid(L"george h w bush", docid);
	if(hw_bound == L"")
		hw_bound = find_bound_uri_from_name_w_or_wo_docid(L"george hw bush", docid);
	else{
		return L"";
	}
	bool match_only_bush = false;
	bool match_hw = false;
	bool match_w = false;
	bool match_george = false;
	bool match_unknown = false;
	const EntitySet* entity_set = doc_theory->getEntitySet();
	if(entity != 0){
		for(int i = 0; i < entity->getNMentions(); i++){
			const Mention* mention = entity_set->getMention(entity->getMention(i));
			if(mention->getMentionType() == Mention::NAME && mention->getHead() != 0){
				const SynNode* head = mention->getAtomicHead();
				if(!head)
					continue;
				std::wstring name_str =  head->toTextString();
				name_str = UnicodeUtil::normalizeTextString(name_str);
				if(name_str == L"bush"){
					match_only_bush = true;
					continue;
				}
				if(name_str.find(L"george") != std::wstring::npos){
					match_george = true;
				}
				else{
					match_unknown = true;
				}
				if(name_str.find(L"h w") != std::wstring::npos || name_str.find(L"hw") != std::wstring::npos){
					match_hw = true;
				} 
				else if(name_str.find(L"herbert walker") != std::wstring::npos){
					match_hw = true;
				}
				else if(name_str.find(L" w ") != std::wstring::npos){
					match_w = true;
				}
			}
		}
	}
	else{
		std::wstring name_str = UnicodeUtil::normalizeTextString(best_name);
		if(name_str == L"bush"){
			match_only_bush = true;
		}
		else if(name_str.find(L"george") != std::wstring::npos){
			match_george = true;
		}
		else{
			match_unknown = true;
		}
		if(name_str == L"w"){
			match_w = true;
		}
		else if(name_str.find(L"h w") != std::wstring::npos || name_str.find(L"hw") != std::wstring::npos){
			match_hw = true;
		}
		else if(name_str.find(L"w") != std::wstring::npos){
			match_w = true;
		}	
	}
	if(match_hw){
		bound_uri_out = hw_bound;
		xdoc_id_out = hw_xid;
	} else if(match_w){
		bound_uri_out = w_bound;
		xdoc_id_out = w_xid;
	} else if(match_only_bush && ( match_george || !match_unknown)){
		if(before_2000){
			bound_uri_out = hw_bound;
			xdoc_id_out = hw_xid;
		}
		else{
			bound_uri_out = w_bound;
			xdoc_id_out = w_xid;
		}
	}
	return best_uri_from_bound_uri_and_xdoc_id(bound_uri_out, xdoc_id_out);
}
std :: wstring ElfMultiDoc :: get_best_name_for_bush ( const std :: wstring & best_name , const Entity * entity , const DocTheory * doc_theory , std :: wstring & bound_uri_out , XDocIdType & xdoc_id_out ) { bound_uri_out = L" " ; xdoc_id_out = XDocIdType ( ) ; std :: wstring normalized_name_str = UnicodeUtil :: normalizeTextString ( best_name ) ; if ( entity == 0 ) return L" " ; if ( doc_theory == 0 ) return L" " ; if ( normalized_name_str . find ( L" " ) == std :: wstring :: npos ) return L" " ; std :: wstring docid = doc_theory -> getDocument ( ) -> getName ( ) . to_string ( ) ; std :: wstring doc_date ; std :: wstring doc_additional_time ; bool before_2000 = false ; ElfMultiDoc :: temporal_normalizer -> normalizeDocumentDate ( doc_theory , doc_date , doc_additional_time ) ; if ( doc_date . size ( ) > 2 ) { std :: wstring begin = doc_date . substr ( 0 , 2 ) ; if ( begin == L" " ) before_2000 = true ; } XDocIdType w_xid = get_xdoc_id ( Symbol ( L" " ) , L" " ) ; XDocIdType hw_xid = get_xdoc_id ( Symbol ( L" " ) , L" " ) ; if ( ! hw_xid . is_valid ( ) ) hw_xid = get_xdoc_id ( Symbol ( L" " ) , L" " ) ; std :: wstring w_bound = find_bound_uri_from_name_w_or_wo_docid ( L" " , docid ) ; std :: wstring hw_bound = find_bound_uri_from_name_w_or_wo_docid ( L" " , docid ) ; if ( hw_bound == L" " ) hw_bound = find_bound_uri_from_name_w_or_wo_docid ( L" " , docid ) ; else { return L" " ; } bool match_only_bush = false ; bool match_hw = false ; bool match_w = false ; bool match_george = false ; bool match_unknown = false ; const EntitySet * entity_set = doc_theory -> getEntitySet ( ) ; if ( entity != 0 ) { for ( int i = 0 ; i < entity -> getNMentions ( ) ; i ++ ) { const Mention * mention = entity_set -> getMention ( entity -> getMention ( i ) ) ; if ( mention -> getMentionType ( ) == Mention :: NAME && mention -> getHead ( ) != 0 ) { const SynNode * head = mention -> getAtomicHead ( ) ; if ( ! head ) continue ; std :: wstring name_str = head -> toTextString ( ) ; name_str = UnicodeUtil :: normalizeTextString ( name_str ) ; if ( name_str == L" " ) { match_only_bush = true ; continue ; } if ( name_str . find ( L" " ) != std :: wstring :: npos ) { match_george = true ; } else { match_unknown = true ; } if ( name_str . find ( L" " ) != std :: wstring :: npos || name_str . find ( L" " ) != std :: wstring :: npos ) { match_hw = true ; } else if ( name_str . find ( L" " ) != std :: wstring :: npos ) { match_hw = true ; } else if ( name_str . find ( L" " ) != std :: wstring :: npos ) { match_w = true ; } } } } else { std :: wstring name_str = UnicodeUtil :: normalizeTextString ( best_name ) ; if ( name_str == L" " ) { match_only_bush = true ; } else if ( name_str . find ( L" " ) != std :: wstring :: npos ) { match_george = true ; } else { match_unknown = true ; } if ( name_str == L" " ) { match_w = true ; } else if ( name_str . find ( L" " ) != std :: wstring :: npos || name_str . find ( L" " ) != std :: wstring :: npos ) { match_hw = true ; } else if ( name_str . find ( L" " ) != std :: wstring :: npos ) { match_w = true ; } } if ( match_hw ) { bound_uri_out = hw_bound ; xdoc_id_out = hw_xid ; } else if ( match_w ) { bound_uri_out = w_bound ; xdoc_id_out = w_xid ; } else if ( match_only_bush && ( match_george || ! match_unknown ) ) { if ( before_2000 ) { bound_uri_out = hw_bound ; xdoc_id_out = hw_xid ; } else { bound_uri_out = w_bound ; xdoc_id_out = w_xid ; } } return best_uri_from_bound_uri_and_xdoc_id ( bound_uri_out , xdoc_id_out ) ; }
Use date to determine whether it's more likely that "Bush" refers to Papa Bush or Baby Bush.
Use date to determine whether it ' s more likely that " Bush " refers to Papa Bush or Baby Bush .
//if(hw_bound != L"" || w_bound != L"" || (w_xid != L"" && hw_xid != L"")){
 //	SessionLogger::info("LEARNIT")<<"Conflicting George Bushes: "<< "HW: "<<hw_bound<<", "
 //		<<hw_xid<<" W: "<<w_bound<<", "<<w_xid<<" Date: "<<doc_date
 //		<<" "<<normalized_name_str<<std::endl;
 //}
