void doConstrainedViterbiInsideScores(Grammar grammar,boolean level0grammar){
  short[] numSubStatesArray=grammar.numSubStates;
  for (int diff=1; diff <= length; diff++) {
    for (int start=0; start < (length - diff + 1); start++) {
      int end=start + diff;
      final int lastState=(level0grammar) ? 1 : numSubStatesArray.length;
      for (int pState=0; pState < lastState; pState++) {
        if (diff == 1)         continue;
        if (!grammarTags[pState])         continue;
        if (!vAllowedStates[start][end])         continue;
        double oldIScore=viScore[start][end][pState];
        double bestIScore=oldIScore;
        BinaryRule[] parentRules=grammar.splitRulesWithP(pState);
        for (int i=0; i < parentRules.length; i++) {
          BinaryRule r=parentRules[i];
          int lState=r.leftChildState;
          int rState=r.rightChildState;
          int narrowR=narrowRExtent[start][lState];
          boolean iPossibleL=(narrowR < end);
          if (!iPossibleL) {
            continue;
          }
          int narrowL=narrowLExtent[end][rState];
          boolean iPossibleR=(narrowL >= narrowR);
          if (!iPossibleR) {
            continue;
          }
          int min1=narrowR;
          int min2=wideLExtent[end][rState];
          int min=(min1 > min2 ? min1 : min2);
          if (min > narrowL) {
            continue;
          }
          int max1=wideRExtent[start][lState];
          int max2=narrowL;
          int max=(max1 < max2 ? max1 : max2);
          if (min > max) {
            continue;
          }
          double[][][] scores=r.getScores2();
          double pS=Double.NEGATIVE_INFINITY;
          if (scores[0][0] != null)           pS=scores[0][0][0];
          if (pS == Double.NEGATIVE_INFINITY)           continue;
          for (int split=min; split <= max; split++) {
            if (!vAllowedStates[start][split])             continue;
            if (!vAllowedStates[split][end])             continue;
            double lS=viScore[start][split][lState];
            if (lS == Double.NEGATIVE_INFINITY)             continue;
            double rS=viScore[split][end][rState];
            if (rS == Double.NEGATIVE_INFINITY)             continue;
            double tot=pS + lS + rS;
            if (tot >= bestIScore) {
              bestIScore=tot;
            }
          }
        }
        if (bestIScore > oldIScore) {
          viScore[start][end][pState]=bestIScore;
          if (oldIScore == Double.NEGATIVE_INFINITY) {
            if (start > narrowLExtent[end][pState]) {
              narrowLExtent[end][pState]=start;
              wideLExtent[end][pState]=start;
            }
 else {
              if (start < wideLExtent[end][pState]) {
                wideLExtent[end][pState]=start;
              }
            }
            if (end < narrowRExtent[start][pState]) {
              narrowRExtent[start][pState]=end;
              wideRExtent[start][pState]=end;
            }
 else {
              if (end > wideRExtent[start][pState]) {
                wideRExtent[start][pState]=end;
              }
            }
          }
        }
      }
      final int lastStateU=(level0grammar && diff > 1) ? 1 : numSubStatesArray.length;
      for (int pState=0; pState < lastStateU; pState++) {
        if (!grammarTags[pState])         continue;
        if (diff != 1 && !vAllowedStates[start][end])         continue;
        UnaryRule[] unaries=grammar.getClosedViterbiUnaryRulesByParent(pState);
        double oldIScore=viScore[start][end][pState];
        double bestIScore=oldIScore;
        for (int r=0; r < unaries.length; r++) {
          UnaryRule ur=unaries[r];
          int cState=ur.childState;
          if ((pState == cState))           continue;
          double iS=viScore[start][end][cState];
          if (iS == Double.NEGATIVE_INFINITY)           continue;
          double[][] scores=ur.getScores2();
          double pS=Double.NEGATIVE_INFINITY;
          if (scores[0] != null)           pS=scores[0][0];
          if (pS == Double.NEGATIVE_INFINITY)           continue;
          double tot=iS + pS;
          if (tot >= bestIScore) {
            bestIScore=tot;
          }
        }
        if (bestIScore > oldIScore) {
          viScore[start][end][pState]=bestIScore;
          if (oldIScore == Double.NEGATIVE_INFINITY) {
            if (start > narrowLExtent[end][pState]) {
              narrowLExtent[end][pState]=start;
              wideLExtent[end][pState]=start;
            }
 else {
              if (start < wideLExtent[end][pState]) {
                wideLExtent[end][pState]=start;
              }
            }
            if (end < narrowRExtent[start][pState]) {
              narrowRExtent[start][pState]=end;
              wideRExtent[start][pState]=end;
            }
 else {
              if (end > wideRExtent[start][pState]) {
                wideRExtent[start][pState]=end;
              }
            }
          }
        }
      }
    }
  }
}

void doConstrainedViterbiInsideScores ( Grammar grammar , boolean level0grammar ) { short [ ] numSubStatesArray = grammar . numSubStates ; for ( int diff = 1 ; diff <= length ; diff ++ ) { for ( int start = 0 ; start < ( length - diff + 1 ) ; start ++ ) { int end = start + diff ; final int lastState = ( level0grammar ) ? 1 : numSubStatesArray . length ; for ( int pState = 0 ; pState < lastState ; pState ++ ) { if ( diff == 1 ) continue ; if ( ! grammarTags [ pState ] ) continue ; if ( ! vAllowedStates [ start ] [ end ] ) continue ; double oldIScore = viScore [ start ] [ end ] [ pState ] ; double bestIScore = oldIScore ; BinaryRule [ ] parentRules = grammar . splitRulesWithP ( pState ) ; for ( int i = 0 ; i < parentRules . length ; i ++ ) { BinaryRule r = parentRules [ i ] ; int lState = r . leftChildState ; int rState = r . rightChildState ; int narrowR = narrowRExtent [ start ] [ lState ] ; boolean iPossibleL = ( narrowR < end ) ; if ( ! iPossibleL ) { continue ; } int narrowL = narrowLExtent [ end ] [ rState ] ; boolean iPossibleR = ( narrowL >= narrowR ) ; if ( ! iPossibleR ) { continue ; } int min1 = narrowR ; int min2 = wideLExtent [ end ] [ rState ] ; int min = ( min1 > min2 ? min1 : min2 ) ; if ( min > narrowL ) { continue ; } int max1 = wideRExtent [ start ] [ lState ] ; int max2 = narrowL ; int max = ( max1 < max2 ? max1 : max2 ) ; if ( min > max ) { continue ; } double [ ] [ ] [ ] scores = r . getScores2 ( ) ; double pS = Double . NEGATIVE_INFINITY ; if ( scores [ 0 ] [ 0 ] != null ) pS = scores [ 0 ] [ 0 ] [ 0 ] ; if ( pS == Double . NEGATIVE_INFINITY ) continue ; for ( int split = min ; split <= max ; split ++ ) { if ( ! vAllowedStates [ start ] [ split ] ) continue ; if ( ! vAllowedStates [ split ] [ end ] ) continue ; double lS = viScore [ start ] [ split ] [ lState ] ; if ( lS == Double . NEGATIVE_INFINITY ) continue ; double rS = viScore [ split ] [ end ] [ rState ] ; if ( rS == Double . NEGATIVE_INFINITY ) continue ; double tot = pS + lS + rS ; if ( tot >= bestIScore ) { bestIScore = tot ; } } } if ( bestIScore > oldIScore ) { viScore [ start ] [ end ] [ pState ] = bestIScore ; if ( oldIScore == Double . NEGATIVE_INFINITY ) { if ( start > narrowLExtent [ end ] [ pState ] ) { narrowLExtent [ end ] [ pState ] = start ; wideLExtent [ end ] [ pState ] = start ; } else { if ( start < wideLExtent [ end ] [ pState ] ) { wideLExtent [ end ] [ pState ] = start ; } } if ( end < narrowRExtent [ start ] [ pState ] ) { narrowRExtent [ start ] [ pState ] = end ; wideRExtent [ start ] [ pState ] = end ; } else { if ( end > wideRExtent [ start ] [ pState ] ) { wideRExtent [ start ] [ pState ] = end ; } } } } } final int lastStateU = ( level0grammar && diff > 1 ) ? 1 : numSubStatesArray . length ; for ( int pState = 0 ; pState < lastStateU ; pState ++ ) { if ( ! grammarTags [ pState ] ) continue ; if ( diff != 1 && ! vAllowedStates [ start ] [ end ] ) continue ; UnaryRule [ ] unaries = grammar . getClosedViterbiUnaryRulesByParent ( pState ) ; double oldIScore = viScore [ start ] [ end ] [ pState ] ; double bestIScore = oldIScore ; for ( int r = 0 ; r < unaries . length ; r ++ ) { UnaryRule ur = unaries [ r ] ; int cState = ur . childState ; if ( ( pState == cState ) ) continue ; double iS = viScore [ start ] [ end ] [ cState ] ; if ( iS == Double . NEGATIVE_INFINITY ) continue ; double [ ] [ ] scores = ur . getScores2 ( ) ; double pS = Double . NEGATIVE_INFINITY ; if ( scores [ 0 ] != null ) pS = scores [ 0 ] [ 0 ] ; if ( pS == Double . NEGATIVE_INFINITY ) continue ; double tot = iS + pS ; if ( tot >= bestIScore ) { bestIScore = tot ; } } if ( bestIScore > oldIScore ) { viScore [ start ] [ end ] [ pState ] = bestIScore ; if ( oldIScore == Double . NEGATIVE_INFINITY ) { if ( start > narrowLExtent [ end ] [ pState ] ) { narrowLExtent [ end ] [ pState ] = start ; wideLExtent [ end ] [ pState ] = start ; } else { if ( start < wideLExtent [ end ] [ pState ] ) { wideLExtent [ end ] [ pState ] = start ; } } if ( end < narrowRExtent [ start ] [ pState ] ) { narrowRExtent [ start ] [ pState ] = end ; wideRExtent [ start ] [ pState ] = end ; } else { if ( end > wideRExtent [ start ] [ pState ] ) { wideRExtent [ start ] [ pState ] = end ; } } } } } } } }
fills in the iscore array of each category over each span of length 2 or more .
