src/PredFinder/common/ElfMultiDoc.cpp
/**
 * Given a type string and best name string, looks up
 * the name in the loaded argument map (string replacement) table and returns
 * a replacement string if one exists. Replacement string will be 
 * a bound URI (ontology URI) if available, otherwise an XDoc ID if available,
 * otherwise an empty string.
 *
 * @param type_string The ontology type of the named individual.
 * @param best_name The best name string of the individual.
 * @param doc_theory The current document containing the individual.
 * @param entity The entity associated with the individual, if any.
 * @return The replaced bound URI, or XDoc ID, or empty string.
 * 
 * @author nward@bbn.com
 * @date 2010.07.13
 **/
Given a type string and best name string, looks up
the name in the loaded argument map (string replacement) table and returns
a replacement string if one exists. Replacement string will be
a bound URI (ontology URI) if available, otherwise an XDoc ID if available,
otherwise an empty string.

@param type_string The ontology type of the named individual.
@param best_name The best name string of the individual.
@param doc_theory The current document containing the individual.
@param entity The entity associated with the individual, if any.
@return The replaced bound URI, or XDoc ID, or empty string.


Given a type string and best name string looks up the name in the loaded argument map ( string replacement ) table and returns a replacement string if one exists . Replacement string will be a bound URI ( ontology URI ) if available otherwise an XDoc ID if available otherwise an empty string . @param type_string The ontology type of the named individual . @param best_name The best name string of the individual . @param doc_theory The current document containing the individual . @param entity The entity associated with the individual if any . @return The replaced bound URI or XDoc ID or empty string .
std::wstring ElfMultiDoc::get_mapped_arg(const std::wstring & best_name, const std::wstring & type_string, 
											const DocTheory* doc_theory, const Entity* entity, 
											std::wstring & bound_uri_out, XDocIdType & xdoc_id_out) {
	bound_uri_out = L"";
	xdoc_id_out = XDocIdType(); 
	std::wstring out_string;
	if (get_mapped_arg_from_doc_level_uri_assignment(best_name, type_string, doc_theory, entity, bound_uri_out, xdoc_id_out)) {
		return best_uri_from_bound_uri_and_xdoc_id(bound_uri_out, xdoc_id_out);
	}
	boost::wregex spaces_re(L"\\s+");
	std::wstring cleaned_best_name = boost::regex_replace(best_name, spaces_re, L" ");
	std::wstring docid;
	if (doc_theory) {
		docid = std::wstring(doc_theory->getDocument()->getName().to_string());
	}
	Symbol entity_type = Symbol(L"NONE");
	if (entity) {
		entity_type = entity->getType().getName();
	}
	std::vector<std::wstring> other_names = get_other_names(entity_type, cleaned_best_name);
	other_names.insert(other_names.begin(), cleaned_best_name);
	DocIdAndTypeToSRMMap::iterator map_i = ElfMultiDoc::_docid_type_to_srm.find(DocIdAndTypeToSRMMap::key_type(docid, type_string));
	if (map_i != _docid_type_to_srm.end()) {
		BOOST_FOREACH(std::wstring other_name, other_names) {
			StringReplacementMap::iterator replace_i = map_i->second.find(other_name);
			if (replace_i != map_i->second.end()) {
				bound_uri_out = replace_i->second;
				return bound_uri_out;
			}
		}
	}
	TypeToSRMMap::iterator map_all_i = ElfMultiDoc::_type_to_srm.find(TypeToSRMMap::key_type(type_string));
	if (map_all_i != _type_to_srm.end()) {
		BOOST_FOREACH(std::wstring other_name, other_names) {
			StringReplacementMap::iterator replace_i = map_all_i->second.find(other_name);
			if (replace_i != map_all_i->second.end()) {
				bound_uri_out = replace_i->second;
				return bound_uri_out;
			}
		}
	}
	return get_mapped_arg_when_no_srm_entry_found(best_name, type_string, doc_theory, entity, xdoc_id_out);
}
std :: wstring ElfMultiDoc :: get_mapped_arg ( const std :: wstring & best_name , const std :: wstring & type_string , const DocTheory * doc_theory , const Entity * entity , std :: wstring & bound_uri_out , XDocIdType & xdoc_id_out ) { bound_uri_out = L" " ; xdoc_id_out = XDocIdType ( ) ; std :: wstring out_string ; if ( get_mapped_arg_from_doc_level_uri_assignment ( best_name , type_string , doc_theory , entity , bound_uri_out , xdoc_id_out ) ) { return best_uri_from_bound_uri_and_xdoc_id ( bound_uri_out , xdoc_id_out ) ; } boost :: wregex spaces_re ( L" \\ " ) ; std :: wstring cleaned_best_name = boost :: regex_replace ( best_name , spaces_re , L" " ) ; std :: wstring docid ; if ( doc_theory ) { docid = std :: wstring ( doc_theory -> getDocument ( ) -> getName ( ) . to_string ( ) ) ; } Symbol entity_type = Symbol ( L" " ) ; if ( entity ) { entity_type = entity -> getType ( ) . getName ( ) ; } std :: vector < std :: wstring > other_names = get_other_names ( entity_type , cleaned_best_name ) ; other_names . insert ( other_names . begin ( ) , cleaned_best_name ) ; DocIdAndTypeToSRMMap :: iterator map_i = ElfMultiDoc :: _docid_type_to_srm . find ( DocIdAndTypeToSRMMap :: key_type ( docid , type_string ) ) ; if ( map_i != _docid_type_to_srm . end ( ) ) { BOOST_FOREACH ( std :: wstring other_name , other_names ) { StringReplacementMap :: iterator replace_i = map_i -> second . find ( other_name ) ; if ( replace_i != map_i -> second . end ( ) ) { bound_uri_out = replace_i -> second ; return bound_uri_out ; } } } TypeToSRMMap :: iterator map_all_i = ElfMultiDoc :: _type_to_srm . find ( TypeToSRMMap :: key_type ( type_string ) ) ; if ( map_all_i != _type_to_srm . end ( ) ) { BOOST_FOREACH ( std :: wstring other_name , other_names ) { StringReplacementMap :: iterator replace_i = map_all_i -> second . find ( other_name ) ; if ( replace_i != map_all_i -> second . end ( ) ) { bound_uri_out = replace_i -> second ; return bound_uri_out ; } } } return get_mapped_arg_when_no_srm_entry_found ( best_name , type_string , doc_theory , entity , xdoc_id_out ) ; }
Given a type string and best name string, looks up
 the name in the loaded argument map (string replacement) table and returns
 a replacement string if one exists.
Given a type string and best name string looks up the name in the loaded argument map ( string replacement ) table and returns a replacement string if one exists .
// INVALID_XDOC_ID;
 // The argument map collapses whitespace to avoid row-breaking, so we need to search names similarly
 // Get the document ID for lookups
 // Use cross-doc to get other names for the associated entity, if any
 //mrf: XDoc removes punctuation, but the training map does not necessarily.  
 //     Add 'cleaned best name' to other_names to try to help
 //     Also: all else being equal, you'd prefer the id of this instance, so add it to the beginning
 //Note: currently, other_names may contain duplicate strings.
 // Check whether the document ID, type, and best name indicate we need to do a replacement
 //   These argument URIs are used to align with annotation; they supersede all other mapped arguments
 // Convert the best name using the matching argument map
 //SessionLogger::info("LEARNIT") << "Performing docid-specific conversion of <" << other_name << "> "
 //	<< "to <" << replace_i->second << ">" << std::endl;
 // Check whether the type and best name indicate we need to do a replacement across all docs
 // Sample output: "Performing conversion of <Patriots> to <nfl:NewEnglandPatriots>"
 // Convert the best name using the matching argument map
 //SessionLogger::info("LEARNIT") << "Performing conversion of <" << other_name << "> "
 //	<< "to <" << replace_i->second << ">" << std::endl;
