src/PredFinder/common/ElfMultiDoc.cpp
/**
 * Given a Mention, determine its type string, offsets, and
 * best text. Derived from SlotFiller::_findBestEntityName
 * but specialized for an ElfRelationArg context. Only used
 * when constructing an ElfRelationArg from a Mention.
 *
 * @param doc_theory The DocTheory containing the extracted
 * Mention, used for determining offsets.
 * @param mention The Mention being extracted.
 * @param type_string Return by reference: a type string
 * derived from Mention::getMentionType().
 * @param start_offset Return by reference: integer start
 * offset of the mention.
 * @param end_offset Return by reference: integer end
 * offset of the mention.
 * @return The best text contents of the mention; a name or description
 * where relevant and available.
 *
 * @author nward@bbn.com
 * @date 2010.06.15
 **/
Given a Mention, determine its type string, offsets, and
best text.

@param doc_theory The DocTheory containing the extracted
Mention, used for determining offsets.
@param mention The Mention being extracted.
@param type_string Return by reference: a type string
derived from Mention::getMentionType().
@param start_offset Return by reference: integer start
offset of the mention.
@param end_offset Return by reference: integer end
offset of the mention.
@return The best text contents of the mention; a name or description
where relevant and available.


Given a Mention determine its type string offsets and best text . @param doc_theory The DocTheory containing the extracted Mention used for determining offsets . @param mention The Mention being extracted . @param type_string Return by reference : a type string derived from Mention :: getMentionType () . @param start_offset Return by reference : integer start offset of the mention . @param end_offset Return by reference : integer end offset of the mention . @return The best text contents of the mention ; a name or description where relevant and available .
std::wstring ElfMultiDoc::find_best_text_for_mention(const DocTheory* doc_theory, const Mention* mention, 
											std::wstring& type_string, EDTOffset& start_offset, EDTOffset& end_offset) {
	const SynNode* mention_node = mention->getNode();
	const SynNode* mention_head = mention->getHead();
	Mention::Type mention_type = mention->getMentionType();
	std::wstring text = L"NO_NAME";
	if (mention_node) {
		SentenceTheory* sent_theory = doc_theory->getSentenceTheory(mention->getSentenceNumber());
		if (sent_theory) {
			TokenSequence* token_sequence = sent_theory->getTokenSequence();
			if (token_sequence) {
				switch (mention_type) {
				case Mention::NAME:
					if (mention_head) {
						start_offset = token_sequence->getToken(mention_head->getStartToken())->getStartEDTOffset();
						end_offset = token_sequence->getToken(mention_head->getEndToken())->getEndEDTOffset();
					}
					break;
				case Mention::APPO:
					if (mention_head && mention_head->hasMention()) {
						const MentionSet* mention_set = sent_theory->getMentionSet();
						Mention* m = mention_set->getMention(mention_head->getMentionIndex());
						mention_type = m->getMentionType();
						start_offset = token_sequence->getToken(mention_head->getStartToken())->getStartEDTOffset();
						end_offset = token_sequence->getToken(mention_head->getEndToken())->getEndEDTOffset();
					}
					break;
				default:
					start_offset = token_sequence->getToken(mention_node->getStartToken())->getStartEDTOffset();
					end_offset = token_sequence->getToken(mention_node->getEndToken())->getEndEDTOffset();
					break;
				}
				LocatedString* located_text = MainUtilities::substringFromEdtOffsets(
					doc_theory->getDocument()->getOriginalText(), start_offset, end_offset);
				text = std::wstring(located_text->toString());
				delete located_text;
			}
		}
	}
	std::wstring entity_type = std::wstring(mention->getEntityType().getName().to_string());
	std::wstring entity_subtype = std::wstring(mention->getEntitySubtype().getName().to_string());
	if (entity_subtype == L"UNDET")
		type_string = std::wstring(L"ace:") + entity_type;
	else
		type_string = std::wstring(L"ace:") + entity_type + std::wstring(L".") + entity_subtype;
	return text;
}
std :: wstring ElfMultiDoc :: find_best_text_for_mention ( const DocTheory * doc_theory , const Mention * mention , std :: wstring & type_string , EDTOffset & start_offset , EDTOffset & end_offset ) { const SynNode * mention_node = mention -> getNode ( ) ; const SynNode * mention_head = mention -> getHead ( ) ; Mention :: Type mention_type = mention -> getMentionType ( ) ; std :: wstring text = L" " ; if ( mention_node ) { SentenceTheory * sent_theory = doc_theory -> getSentenceTheory ( mention -> getSentenceNumber ( ) ) ; if ( sent_theory ) { TokenSequence * token_sequence = sent_theory -> getTokenSequence ( ) ; if ( token_sequence ) { switch ( mention_type ) { case Mention :: NAME : if ( mention_head ) { start_offset = token_sequence -> getToken ( mention_head -> getStartToken ( ) ) -> getStartEDTOffset ( ) ; end_offset = token_sequence -> getToken ( mention_head -> getEndToken ( ) ) -> getEndEDTOffset ( ) ; } break ; case Mention :: APPO : if ( mention_head && mention_head -> hasMention ( ) ) { const MentionSet * mention_set = sent_theory -> getMentionSet ( ) ; Mention * m = mention_set -> getMention ( mention_head -> getMentionIndex ( ) ) ; mention_type = m -> getMentionType ( ) ; start_offset = token_sequence -> getToken ( mention_head -> getStartToken ( ) ) -> getStartEDTOffset ( ) ; end_offset = token_sequence -> getToken ( mention_head -> getEndToken ( ) ) -> getEndEDTOffset ( ) ; } break ; default : start_offset = token_sequence -> getToken ( mention_node -> getStartToken ( ) ) -> getStartEDTOffset ( ) ; end_offset = token_sequence -> getToken ( mention_node -> getEndToken ( ) ) -> getEndEDTOffset ( ) ; break ; } LocatedString * located_text = MainUtilities :: substringFromEdtOffsets ( doc_theory -> getDocument ( ) -> getOriginalText ( ) , start_offset , end_offset ) ; text = std :: wstring ( located_text -> toString ( ) ) ; delete located_text ; } } } std :: wstring entity_type = std :: wstring ( mention -> getEntityType ( ) . getName ( ) . to_string ( ) ) ; std :: wstring entity_subtype = std :: wstring ( mention -> getEntitySubtype ( ) . getName ( ) . to_string ( ) ) ; if ( entity_subtype == L" " ) type_string = std :: wstring ( L" " ) + entity_type ; else type_string = std :: wstring ( L" " ) + entity_type + std :: wstring ( L" " ) + entity_subtype ; return text ; }
Given a Mention, determine its type string, offsets, and
 best text.
Given a Mention determine its type string offsets and best text .
// Safely determine the start and end offsets
 // Check the mention type for special handling
 // Get the text for the offsets of the mention or the mention head
 // Construct the complete type string for this mention
 // Done
