src/Chinese/edt/ch_DescLinkFunctions.cpp
// Note: should probably store the words for each entity (and mention?), so we don't have to keep
// recalculating.  Also should add stop words.

should probably store the words for each entity (and mention?), so we don't have to keep
recalculating.  Also should add stop words.
should probably store the words for each entity ( and mention? ) so we don ' t have to keep recalculating . Also should add stop words .
Symbol ChineseDescLinkFunctions::_getUniqueHanziRatio(Mention *ment, Entity *entity, EntitySet *entitySet) {
	SymbolHash entityHanzi(150);
	int n_ent_hanzi = 0;
	int unique = 0;
	int total = 0;
	wchar_t str[2];
	str[1] = '\0';
	Symbol entityMentWords[20];
	for (int i = 0; i < entity->getNMentions(); i++) {
		Mention *entityMent = entitySet->getMention(entity->getMention(i));
		int n_words = entityMent->getNode()->getTerminalSymbols(entityMentWords, 20);
		for (int j = 0; j < n_words; j++) {
			const wchar_t *ent_word = entityMentWords[j].to_string();
			int len = static_cast<int>(wcslen(ent_word));
			for (int k = 0; k < len; k++) {
				str[0] = *(ent_word + k);
				Symbol hanzi(str);
				if (! entityHanzi.lookup(hanzi)) {
					entityHanzi.add(hanzi);
					n_ent_hanzi++;
				}
			}
		}
	}
	Symbol mentionWords[20];
	int n_ment_words = ment->getNode()->getTerminalSymbols(mentionWords, 20);
	if (n_ment_words == 0)
		return Symbol(L"uh[0.0]");
	if (n_ent_hanzi == 0)
		return Symbol(L"uh[1.0]");
	for (int k = 0; k < n_ment_words; k++) {
		const wchar_t *ment_word = mentionWords[k].to_string();
		int len = static_cast<int>(wcslen(ment_word));
		for (int l = 0; l < len; l++) {
			str[0] = *(ment_word + l);
			Symbol hanzi(str);
			if (! entityHanzi.lookup(hanzi))
				unique++;
			total++;
		}
	}
	double ratio = (double)unique/(double)total;
	if (ratio == 0.0)
		return Symbol(L"uh[0.0]");
	else if (ratio < 0.25)
		return Symbol(L"uh[<.25]");
	else if (ratio < 0.5)
		return Symbol(L"uh[<.5]");
	else if (ratio < 0.75)
		return Symbol(L"uh[<.75]");
	else if (ratio < 1.0)
		return Symbol(L"uh[<1.0]");
	else
		return Symbol(L"uh[1.0]");
}
Symbol ChineseDescLinkFunctions :: _getUniqueHanziRatio ( Mention * ment , Entity * entity , EntitySet * entitySet ) { SymbolHash entityHanzi ( 150 ) ; int n_ent_hanzi = 0 ; int unique = 0 ; int total = 0 ; wchar_t str [ 2 ] ; str [ 1 ] = ' \0 ' ; Symbol entityMentWords [ 20 ] ; for ( int i = 0 ; i < entity -> getNMentions ( ) ; i ++ ) { Mention * entityMent = entitySet -> getMention ( entity -> getMention ( i ) ) ; int n_words = entityMent -> getNode ( ) -> getTerminalSymbols ( entityMentWords , 20 ) ; for ( int j = 0 ; j < n_words ; j ++ ) { const wchar_t * ent_word = entityMentWords [ j ] . to_string ( ) ; int len = static_cast < int > ( wcslen ( ent_word ) ) ; for ( int k = 0 ; k < len ; k ++ ) { str [ 0 ] = * ( ent_word + k ) ; Symbol hanzi ( str ) ; if ( ! entityHanzi . lookup ( hanzi ) ) { entityHanzi . add ( hanzi ) ; n_ent_hanzi ++ ; } } } } Symbol mentionWords [ 20 ] ; int n_ment_words = ment -> getNode ( ) -> getTerminalSymbols ( mentionWords , 20 ) ; if ( n_ment_words == 0 ) return Symbol ( L" " ) ; if ( n_ent_hanzi == 0 ) return Symbol ( L" " ) ; for ( int k = 0 ; k < n_ment_words ; k ++ ) { const wchar_t * ment_word = mentionWords [ k ] . to_string ( ) ; int len = static_cast < int > ( wcslen ( ment_word ) ) ; for ( int l = 0 ; l < len ; l ++ ) { str [ 0 ] = * ( ment_word + l ) ; Symbol hanzi ( str ) ; if ( ! entityHanzi . lookup ( hanzi ) ) unique ++ ; total ++ ; } } double ratio = ( double ) unique / ( double ) total ; if ( ratio == 0.0 ) return Symbol ( L" " ) ; else if ( ratio < 0.25 ) return Symbol ( L" " ) ; else if ( ratio < 0.5 ) return Symbol ( L" " ) ; else if ( ratio < 0.75 ) return Symbol ( L" " ) ; else if ( ratio < 1.0 ) return Symbol ( L" " ) ; else return Symbol ( L" " ) ; }
Note: should probably store the words for each entity (and mention?
Note : should probably store the words for each entity ( and mention?
// collect Entity hanzi
 // collect Mention words
