static void tryElimination( a_state *state, a_word *reduce_set ) { a_reduce_action *raction; a_pro *pro; if( IsDead( state ) ) { return; } if( IsAmbiguous( state ) ) { return; } // iterate over all reductions in state for( pro = state->redun->pro; pro != NULL; ) { for( raction = state->redun; (pro = raction->pro) != NULL; ++raction ) { if( pro->unit ) { if( multiUnitReduce( state, raction, pro, reduce_set ) ) { /* state->redun could have changed */ break; } if( immediateShift( state, raction, pro ) ) { /* state->redun could have changed */ break; } } } } }
void RuleScope::EvaluateInIsolation(const Phrase &source , const TargetPhrase &targetPhrase , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedFutureScore) const { // adjacent non-term count as 1 ammbiguity, rather than 2 as in rule scope // source can't be empty, right? float score = 0; int count = 0; for (size_t i = 0; i < source.GetSize() - 0; ++i) { const Word &word = source.GetWord(i); bool ambiguous = IsAmbiguous(word, m_sourceSyntax); if (ambiguous) { ++count; } else { if (count > 0) { score += count; } count = -1; } } // 1st & last always adjacent to ambiguity ++count; if (count > 0) { score += count; } scoreBreakdown.PlusEquals(this, score); }
static a_sym *onlyOneReduction( a_state *state ) { a_reduce_action *raction; a_shift_action *saction; a_pro *pro; a_pro *save_pro; a_sym *shift_sym; /* We shouldn't kill ambiguous states because a user that has to deal with a crazy language (like C++) might want to keep the state around. This check has the dual benefit of eliminating a lot of checking and solving part of the ambiguous state problem. */ if( state->kersize != 1 ) { return( NULL ); } if( IsAmbiguous( state ) ) { /* catch all of the ambiguous states */ return( NULL ); } /* iterate over all shifts in the state */ saction = state->trans; shift_sym = saction->sym; if( shift_sym != NULL ) { /* state contains at least one shift */ return( NULL ); } // iterate over all reductions in state save_pro = NULL; for( raction = state->redun; (pro = raction->pro) != NULL; ++raction ) { if( save_pro != NULL ) { /* state contains at least two reductions */ return( NULL ); } if( ! pro->unit ) { /* state contains at least one reduction by a non-unit production */ return( NULL ); } save_pro = pro; } if( save_pro == NULL ) { /* should never execute this but just in case... */ return( NULL ); } return( save_pro->sym ); }