private void initializeBeamSearchChart ( List < Object > terminals , BeamSearchCfgParseChart chart , long [ ] treeEncodingOffsets ) { Variable terminalListValue = terminalVar . getOnlyVariable ( ) ; // Adding this to a tree key indicates that the tree is a terminal. long terminalSignal = ( ( long ) chart . chartSize ( ) ) * ( treeEncodingOffsets [ 3 ] + treeEncodingOffsets [ 2 ] ) ; for ( int i = 0 ; i < terminals . size ( ) ; i ++ ) { for ( int j = i ; j < terminals . size ( ) ; j ++ ) { if ( terminalListValue . canTakeValue ( terminals . subList ( i , j + 1 ) ) ) { Assignment assignment = terminalVar . outcomeArrayToAssignment ( terminals . subList ( i , j + 1 ) ) ; Iterator < Outcome > iterator = terminalDistribution . outcomePrefixIterator ( assignment ) ; while ( iterator . hasNext ( ) ) { Outcome bestOutcome = iterator . next ( ) ; int root = nonterminalVariableType . getValueIndex ( bestOutcome . getAssignment ( ) . getValue ( parentVar . getOnlyVariableNum ( ) ) ) ; int ruleType = ruleVariableType . getValueIndex ( bestOutcome . getAssignment ( ) . getValue ( ruleTypeVar . getOnlyVariableNum ( ) ) ) ; long partialKeyNum = ( root * treeEncodingOffsets [ 4 ] ) + ( ruleType * treeEncodingOffsets [ 5 ] ) ; chart . addParseTreeKeyForSpan ( i , j , terminalSignal + partialKeyNum , bestOutcome . getProbability ( ) ) ; } // System.out.println(i + "." + j + ": " + assignment + " : " + // chart.getParseTreesForSpan(i, j)); } } } }
Initializes a beam search chart using the terminal production distribution .