src/Generic/edt/discmodel/DTCorefTrainer.cpp
// Sort entities by the last mention id
// add several non-ACE entities if needed
// For name linking it enables filtering non name level entities.

Sort entities by the last mention id
add several non-ACE entities if needed
For name linking it enables filtering non name level entities.
Sort entities by the last mention id add several non - ACE entities if needed For name linking it enables filtering non name level entities .
void DTCorefTrainer::sortEntities(const GrowableArray <Entity *> &allEntities,
								  const GrowableArray <Entity *> &entitiesByType,
								  const Mention *ment,
								  int entityID,
								  const EntitySet *entitySet,
								  int nCandidates,
								  GrowableArray <Entity *>& sortedEnts,
								  int max_non_ace_candidates)
{
	for (int i = 0; i < nCandidates; i++) {
		Entity *ent;
		if (TARGET_MENTION_TYPE == Mention::PRON)
			ent = allEntities[i];
		else if (_filter_by_entity_type || _filter_by_entity_subtype) 
			ent = entitiesByType[i];
		else 
			ent = allEntities[i];
		if (_filter_by_entity_subtype && !CorefUtils::subtypeMatch(entitySet, ent, ment))
			continue;
		if (!ent->getType().isRecognized())
			continue;
		if (_considerWithinSentenceLinksOnly || _considerOutsideSentenceLinksOnly) {
			MentionUID last_id = CorefUtils::getLatestMention(entitySet, ent, ment);
			if (last_id.isValid()) {
				Mention *lastMention = entitySet->getMention(last_id);
				if (ment->getSentenceNumber() == lastMention->getSentenceNumber()) {
					if (_considerOutsideSentenceLinksOnly)
						continue;
				} 
				else {
					if (_considerWithinSentenceLinksOnly)
						continue;
				}
			}
		}
		if (TARGET_MENTION_TYPE==Mention::NAME && _limit_to_names 
			&& (MODE == TRAIN || ent->getID()!=entityID) 
			&& (CorefUtils::getEntityMentionLevel(entitySet,ent)!=Mention::NAME))
				continue;
		CorefUtils::insertEntityIntoSortedArray(sortedEnts, entitySet, ent, ment, ENTITY_LINK_MAX);
	}
	if (_use_non_ace_entities_as_no_links) {
		GrowableArray<Entity *> non_ACE_ents;
		for (int i = 0; i < allEntities.length(); i++) {
			Entity *ent = allEntities[i];
			if (!ent->getType().isRecognized())
				CorefUtils::insertEntityIntoSortedArray(non_ACE_ents, entitySet, ent, ment, ENTITY_LINK_MAX);
		}
		int max_non_ACE_used = (non_ACE_ents.length() > max_non_ace_candidates) ? max_non_ace_candidates : non_ACE_ents.length();
		for (int i=non_ACE_ents.length()-1; i>=non_ACE_ents.length()-max_non_ACE_used&& i>=0; i--) {
			CorefUtils::insertEntityIntoSortedArray(sortedEnts, entitySet, non_ACE_ents[i], ment, ENTITY_LINK_MAX);
		}
	}
}
void DTCorefTrainer :: sortEntities ( const GrowableArray < Entity * > & allEntities , const GrowableArray < Entity * > & entitiesByType , const Mention * ment , int entityID , const EntitySet * entitySet , int nCandidates , GrowableArray < Entity * > & sortedEnts , int max_non_ace_candidates ) { for ( int i = 0 ; i < nCandidates ; i ++ ) { Entity * ent ; if ( TARGET_MENTION_TYPE == Mention :: PRON ) ent = allEntities [ i ] ; else if ( _filter_by_entity_type || _filter_by_entity_subtype ) ent = entitiesByType [ i ] ; else ent = allEntities [ i ] ; if ( _filter_by_entity_subtype && ! CorefUtils :: subtypeMatch ( entitySet , ent , ment ) ) continue ; if ( ! ent -> getType ( ) . isRecognized ( ) ) continue ; if ( _considerWithinSentenceLinksOnly || _considerOutsideSentenceLinksOnly ) { MentionUID last_id = CorefUtils :: getLatestMention ( entitySet , ent , ment ) ; if ( last_id . isValid ( ) ) { Mention * lastMention = entitySet -> getMention ( last_id ) ; if ( ment -> getSentenceNumber ( ) == lastMention -> getSentenceNumber ( ) ) { if ( _considerOutsideSentenceLinksOnly ) continue ; } else { if ( _considerWithinSentenceLinksOnly ) continue ; } } } if ( TARGET_MENTION_TYPE == Mention :: NAME && _limit_to_names && ( MODE == TRAIN || ent -> getID ( ) != entityID ) && ( CorefUtils :: getEntityMentionLevel ( entitySet , ent ) != Mention :: NAME ) ) continue ; CorefUtils :: insertEntityIntoSortedArray ( sortedEnts , entitySet , ent , ment , ENTITY_LINK_MAX ) ; } if ( _use_non_ace_entities_as_no_links ) { GrowableArray < Entity * > non_ACE_ents ; for ( int i = 0 ; i < allEntities . length ( ) ; i ++ ) { Entity * ent = allEntities [ i ] ; if ( ! ent -> getType ( ) . isRecognized ( ) ) CorefUtils :: insertEntityIntoSortedArray ( non_ACE_ents , entitySet , ent , ment , ENTITY_LINK_MAX ) ; } int max_non_ACE_used = ( non_ACE_ents . length ( ) > max_non_ace_candidates ) ? max_non_ace_candidates : non_ACE_ents . length ( ) ; for ( int i = non_ACE_ents . length ( ) - 1 ; i >= non_ACE_ents . length ( ) - max_non_ACE_used && i >= 0 ; i -- ) { CorefUtils :: insertEntityIntoSortedArray ( sortedEnts , entitySet , non_ACE_ents [ i ] , ment , ENTITY_LINK_MAX ) ; } } }
Sort entities by the last mention id
add several non-ACE entities if needed
For name linking it enables filtering non name level entities.
Sort entities by the last mention id add several non - ACE entities if needed For name linking it enables filtering non name level entities .
// brute force method of sorting
 // again, this is a bit hackish due to the nature of GrowableArrays
 // note that we set nCandidates earlier in this function!
 //not filtering by type
 // throw out ent if filtering by subtype and subtype doesn't match
 // insert only ACE entities
 // check to see whether the candidate antecedent is in the same sentence 
 // or a previous sentence
 // this is a bit biased as we are enabling to link to the correct ID in devtest
 // while in real run we will not enable it. However the bias is very small.
 // We include the correct entity in order to decide whther there was an error or not.
 // sort the non-ACE entities and insert some of them
 //for
 //use non-ACE entities
