src/PredFinder/elf/ElfIndividual.cpp
/**
 * Determines heuristically the best ID to use for this individual,
 * a decision generally based on types, and converts non-string IDs
 * to string URIs where necessary.
 *
 * @param docid Optional. When specified, guarantees that the returned
 * URI is globally unique. Usually only specified when serializing
 * documents; for most other comparisons the "local" URI is sufficient.
 * @return The best, most general URI for this individual, depending on
 * its types. In most cases, this is the broadest (that is, most likely to
 * be merged across sentences and documents) URI. Throws an exception if
 * no valid URI can be generated from this individual's set of IDs. If a
 * docid is specified, this is guaranteed to be globally unique; if not, it
 * may be globally unique if this individual contains an xdoc cluster ID or
 * a bound URI, but it is only guaranteed to be document unique in that case.
 *
 * @author nward@bbn.com
 * @date 2011.06.08
 **/
Determines heuristically the best ID to use for this individual,
a decision generally based on types, and converts non-string IDs
to string URIs where necessary.

@param docid Optional. When specified, guarantees that the returned
URI is globally unique. Usually only specified when serializing
documents; for most other comparisons the "local" URI is sufficient.
@return The best, most general URI for this individual, depending on
its types. In most cases, this is the broadest (that is, most likely to
be merged across sentences and documents) URI. Throws an exception if
no valid URI can be generated from this individual's set of IDs. If a
docid is specified, this is guaranteed to be globally unique; if not, it
may be globally unique if this individual contains an xdoc cluster ID or
a bound URI, but it is only guaranteed to be document unique in that case.


Determines heuristically the best ID to use for this individual a decision generally based on types and converts non - string IDs to string URIs where necessary . @param docid Optional . When specified guarantees that the returned URI is globally unique . Usually only specified when serializing documents ; for most other comparisons the " local " URI is sufficient . @return The best most general URI for this individual depending on its types . In most cases this is the broadest ( that is most likely to be merged across sentences and documents ) URI . Throws an exception if no valid URI can be generated from this individual ' s set of IDs . If a docid is specified this is guaranteed to be globally unique ; if not it may be globally unique if this individual contains an xdoc cluster ID or a bound URI but it is only guaranteed to be document unique in that case .
std::wstring ElfIndividual::get_best_uri(const std::wstring & docid) const {
	std::wstring best_uri = L"";
	if (has_partner_uri())
		best_uri = _partner_uri;
	if (has_generated_uri())
		best_uri = _generated_uri;
	if (has_mention_uid()) {
		std::wstringstream mention_uri;
		mention_uri << L"bbn:ace-mention-";
		if (docid != L"")
			mention_uri << docid << L"-";
		mention_uri << _mention_uid;
		best_uri = mention_uri.str();
	} else if (has_value_mention_id()) {
		std::wstringstream value_mention_uri;
		value_mention_uri << L"bbn:ace-value-mention-";
		if (docid != L"")
			value_mention_uri << docid << L"-";
		value_mention_uri << get_value_mention_id();
		best_uri = value_mention_uri.str();
	} else if (has_event_id()) {
		std::wstringstream event_uri;
		event_uri << L"bbn:ace-event-";
		if (docid != L"")
			event_uri << docid << L"-";
		event_uri << _event_id;
		best_uri = event_uri.str();
	}
	if (has_type(L"kbp:GPE-spec")) {
		if (best_uri == L"")
			throw std::runtime_error("ElfIndividual::get_best_uri(): Could not determine best URI for GPE-spec.");
		return best_uri;
	}
	if (has_type(L"ic:Position") || has_type(L"kbp:Title") ||
		has_type(L"kbp:HeadOfCompanyTitle") || has_type(L"kbp:HeadOfNationStateTitle") ||
		has_type(L"kbp:HeadOfCityTownOrVillageTitle") || has_type(L"kbp:MinisterTitle")) 
	{
		if (has_bound_uri())
			best_uri = _bound_uri;
		if (has_coref_uri())
			best_uri = _coref_uri;
		if (best_uri == L"")
			throw std::runtime_error("ElfIndividual::get_best_uri(): Could not determine best URI for Title/Position.");
		return best_uri;
	}
	if (has_entity_id()) {
		std::wstringstream entity_uri;
		entity_uri << L"bbn:ace-entity-";
		if (docid != L"")
			entity_uri << docid << L"-";
		entity_uri << _entity_id;
		best_uri = entity_uri.str();
	}
	if (has_xdoc_cluster_id()) {
		std::wstringstream xdoc_cluster_uri;
		xdoc_cluster_uri << L"bbn:xdoc-" << _xdoc_cluster_id;
		best_uri = xdoc_cluster_uri.str();
	}
	if (has_coref_uri())
		best_uri = _coref_uri;
	if (has_bound_uri())
		best_uri = _bound_uri;
	if (best_uri == L"")
		throw std::runtime_error("ElfIndividual::get_best_uri(): Could not determine best URI.");
	return best_uri;
}
std :: wstring ElfIndividual :: get_best_uri ( const std :: wstring & docid ) const { std :: wstring best_uri = L" " ; if ( has_partner_uri ( ) ) best_uri = _partner_uri ; if ( has_generated_uri ( ) ) best_uri = _generated_uri ; if ( has_mention_uid ( ) ) { std :: wstringstream mention_uri ; mention_uri << L" " ; if ( docid != L" " ) mention_uri << docid << L" " ; mention_uri << _mention_uid ; best_uri = mention_uri . str ( ) ; } else if ( has_value_mention_id ( ) ) { std :: wstringstream value_mention_uri ; value_mention_uri << L" " ; if ( docid != L" " ) value_mention_uri << docid << L" " ; value_mention_uri << get_value_mention_id ( ) ; best_uri = value_mention_uri . str ( ) ; } else if ( has_event_id ( ) ) { std :: wstringstream event_uri ; event_uri << L" " ; if ( docid != L" " ) event_uri << docid << L" " ; event_uri << _event_id ; best_uri = event_uri . str ( ) ; } if ( has_type ( L" " ) ) { if ( best_uri == L" " ) throw std :: runtime_error ( " " ) ; return best_uri ; } if ( has_type ( L" " ) || has_type ( L" " ) || has_type ( L" " ) || has_type ( L" " ) || has_type ( L" " ) || has_type ( L" " ) ) { if ( has_bound_uri ( ) ) best_uri = _bound_uri ; if ( has_coref_uri ( ) ) best_uri = _coref_uri ; if ( best_uri == L" " ) throw std :: runtime_error ( " " ) ; return best_uri ; } if ( has_entity_id ( ) ) { std :: wstringstream entity_uri ; entity_uri << L" " ; if ( docid != L" " ) entity_uri << docid << L" " ; entity_uri << _entity_id ; best_uri = entity_uri . str ( ) ; } if ( has_xdoc_cluster_id ( ) ) { std :: wstringstream xdoc_cluster_uri ; xdoc_cluster_uri << L" " << _xdoc_cluster_id ; best_uri = xdoc_cluster_uri . str ( ) ; } if ( has_coref_uri ( ) ) best_uri = _coref_uri ; if ( has_bound_uri ( ) ) best_uri = _bound_uri ; if ( best_uri == L" " ) throw std :: runtime_error ( " " ) ; return best_uri ; }
Determines heuristically the best ID to use for this individual,
 a decision generally based on types, and converts non-string IDs
 to string URIs where necessary.
Determines heuristically the best ID to use for this individual a decision generally based on types and converts non - string IDs to string URIs where necessary .
// Start with nothing (indicates logic error)
 // If we have one, start with a partner site original URI, which will probably be overwritten
 // If we don't have additional Serif-based information, just use the generated URI,
 // which is probably based on offsets or a hash
 // Check which kind of underlying Serif ID we have
 // Generate a URI containing the mention UID
 // Generate a URI containing the value mention ID
 // Generate a URI containing the event ID
 // For GPE-specs, we don't want to merge past the mention level,
 // because we're also asserting a bunch of gazetteer relations.
 // For certain individual types, we don't want to merge past the mention
 // level, because they're linked by Serif to PER entities, and we want
 // them to have a distinct URI... *unless* we matched a bound URI.
 // For most mentions, if we have a document-level entity, use that instead
 //   Note that a merged individual could have an entity ID without a
 //   mention UID, if it was merged across mentions.
 // Generate a URI containing the entity ID
 // For most entities, if we have a cross-document cluster ID, use that instead
 //   Note that a merged individual could have a cluster ID without an
 //   entity ID, if it was merged across entities somehow.
 // Generate a URI containing the xdoc cluster ID
 // For some individuals, we have our own coreference that we want to use
 // in place of whatever Serif might have done.
 // Always use a bound URI if available
 // Done
