private void printTopRules(short tag,int topN,boolean columnOutput,int padding){
  String[][] outputMatrix=new String[topN + 1][grammar.numSubStates[tag]];
  for (int i=0; i < outputMatrix.length; i++) {
    for (int j=0; j < outputMatrix[i].length; j++) {
      outputMatrix[i][j]="";
    }
  }
  for (int subState=0; subState < grammar.numSubStates[tag]; subState++) {
    outputMatrix[0][subState]=(String)tagNumberer.object(tag) + "-" + subState;
    PriorityQueue<RuleStruct> topRules=new PriorityQueue<RuleStruct>();
    for (    BinaryRule r : grammar.splitRulesWithP(tag)) {
      for (int lSubState=0; lSubState < grammar.numSubStates[r.getLeftChildState()]; lSubState++) {
        for (int rSubState=0; rSubState < grammar.numSubStates[r.getRightChildState()]; rSubState++) {
          double score=r.getScore(subState,lSubState,rSubState);
          topRules.add(new RuleStruct(r,score,subState,lSubState,rSubState),-score);
          if (topRules.size() > topN)           topRules.next();
        }
      }
    }
    for (    UnaryRule r : grammar.getUnaryRulesByParent(tag)) {
      for (int cSubState=0; cSubState < grammar.numSubStates[r.getChildState()]; cSubState++) {
        double score=r.getScore(subState,cSubState);
        topRules.add(new RuleStruct(r,score,subState,cSubState),-score);
        if (topRules.size() > topN)         topRules.next();
      }
    }
    ArrayList<RuleStruct> r=new ArrayList<RuleStruct>();
    while (topRules.hasNext()) {
      RuleStruct s=topRules.next();
      r.add(0,s);
    }
    for (int i=0; i < r.size(); i++) {
      outputMatrix[i + 1][subState]=ruleToString(r.get(i));
    }
  }
  String tagName=(String)tagNumberer.object(tag);
  printRules("Trunk","topShortRules",columnOutput,outputMatrix);
}

private void printTopRules ( short tag , int topN , boolean columnOutput , int padding ) { String [ ] [ ] outputMatrix = new String [ topN + 1 ] [ grammar . numSubStates [ tag ] ] ; for ( int i = 0 ; i < outputMatrix . length ; i ++ ) { for ( int j = 0 ; j < outputMatrix [ i ] . length ; j ++ ) { outputMatrix [ i ] [ j ] = "" ; } } for ( int subState = 0 ; subState < grammar . numSubStates [ tag ] ; subState ++ ) { outputMatrix [ 0 ] [ subState ] = ( String ) tagNumberer . object ( tag ) + "-" + subState ; PriorityQueue < RuleStruct > topRules = new PriorityQueue < RuleStruct > ( ) ; for ( BinaryRule r : grammar . splitRulesWithP ( tag ) ) { for ( int lSubState = 0 ; lSubState < grammar . numSubStates [ r . getLeftChildState ( ) ] ; lSubState ++ ) { for ( int rSubState = 0 ; rSubState < grammar . numSubStates [ r . getRightChildState ( ) ] ; rSubState ++ ) { double score = r . getScore ( subState , lSubState , rSubState ) ; topRules . add ( new RuleStruct ( r , score , subState , lSubState , rSubState ) , - score ) ; if ( topRules . size ( ) > topN ) topRules . next ( ) ; } } } for ( UnaryRule r : grammar . getUnaryRulesByParent ( tag ) ) { for ( int cSubState = 0 ; cSubState < grammar . numSubStates [ r . getChildState ( ) ] ; cSubState ++ ) { double score = r . getScore ( subState , cSubState ) ; topRules . add ( new RuleStruct ( r , score , subState , cSubState ) , - score ) ; if ( topRules . size ( ) > topN ) topRules . next ( ) ; } } ArrayList < RuleStruct > r = new ArrayList < RuleStruct > ( ) ; while ( topRules . hasNext ( ) ) { RuleStruct s = topRules . next ( ) ; r . add ( 0 , s ) ; } for ( int i = 0 ; i < r . size ( ) ; i ++ ) { outputMatrix [ i + 1 ] [ subState ] = ruleToString ( r . get ( i ) ) ; } } String tagName = ( String ) tagNumberer . object ( tag ) ; printRules ( "Trunk" , "topShortRules" , columnOutput , outputMatrix ) ; }
print the top topn rules starting from symbol tag .
