@@ -97,28 +97,15 @@ public class CollectFeatures {
9797
9898 public static final int NUM_FEATURES = 18 ;
9999
100- // public static final int INDEX_RULE = 8; // what rule are we in?
101- // public static final int INDEX_EARLIEST_RIGHT_ANCESTOR = 9;
102- // public static final int INDEX_ANCESTORS_PARENT5_RULE = 11;
103- // public static final int INDEX_ANCESTORS_PARENT4_RULE = 12;
104- // public static final int INDEX_ANCESTORS_PARENT3_RULE = 13;
105- // public static final int INDEX_ANCESTORS_PARENT3_WID = 14;
106- // public static final int INDEX_ANCESTORS_PARENT2_RULE = 15;
107- // public static final int INDEX_ANCESTORS_PARENT2_WID = 16;
108- // public static final int INDEX_ANCESTORS_PARENT_RULE = 17;
109- // public static final int INDEX_ANCESTORS_PARENT_WID = 18;
110- // public static final int INDEX_NEXT_TYPE = 19;
111-
112-
113100 public static FeatureMetaData [] FEATURES_INJECT_WS = { // inject ws or nl
114101 new FeatureMetaData (FeatureType .TOKEN , new String [] {"" , "LT(-1)" }, 1 ),
115102 new FeatureMetaData (FeatureType .RULE , new String [] {"LT(-1)" , "right ancestor" }, 1 ),
116103 new FeatureMetaData (FeatureType .TOKEN , new String [] {"" , "LT(1)" }, 1 ),
117104 new FeatureMetaData (FeatureType .BOOL , new String []{"Pair" , "dif\\ n" }, 1 ),
118105 FeatureMetaData .UNUSED ,
119106 new FeatureMetaData (FeatureType .RULE , new String [] {"LT(1)" , "left ancestor" }, 1 ),
120- // these previous 5 features seem to predict newline really well. whitespace ok too
121107 new FeatureMetaData (FeatureType .INT , new String [] {"ancestor" , "child index" }, 1 ),
108+ // these previous 6 features seem to predict newline really well. whitespace ok too
122109 FeatureMetaData .UNUSED ,
123110 FeatureMetaData .UNUSED ,
124111 FeatureMetaData .UNUSED ,
@@ -174,10 +161,6 @@ public class CollectFeatures {
174161 new FeatureMetaData (FeatureType .INFO_CHARPOS , new String [] {"char" , "pos" }, 0 )
175162 };
176163
177- public static int getCurrentTokenType (int [] features ) { return features [INDEX_CUR_TYPE ]; }
178- public static int getInfoLine (int [] features ) { return features [INDEX_INFO_LINE ]; }
179- public static int getInfoCharPos (int [] features ) { return features [INDEX_INFO_CHARPOS ]; }
180-
181164 protected InputDocument doc ;
182165 protected ParserRuleContext root ;
183166 protected CommonTokenStream tokens ; // track stream so we can examine previous tokens
@@ -444,48 +427,17 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
444427
445428 // Get context information for current token
446429 parent = (ParserRuleContext )node .getParent ();
447- int curTokensParentRuleIndex = parent .getRuleIndex ();
448430 ParserRuleContext earliestLeftAncestor = earliestAncestorStartingWithToken (node , curToken );
449- int earliestLeftAncestorRuleIndex = earliestLeftAncestor .getRuleIndex ();
450- int earliestLeftAncestorRuleAlt = earliestLeftAncestor .getAltNumber ();
451431 ParserRuleContext earliestLeftAncestorParent = earliestLeftAncestor .getParent ();
452432
453433 ParserRuleContext earliestLeftAncestorParent2 = earliestLeftAncestorParent !=null ? earliestLeftAncestorParent .getParent () : null ;
454434 ParserRuleContext earliestLeftAncestorParent3 = earliestLeftAncestorParent2 !=null ? earliestLeftAncestorParent2 .getParent () : null ;
455435 ParserRuleContext earliestLeftAncestorParent4 = earliestLeftAncestorParent3 !=null ? earliestLeftAncestorParent3 .getParent () : null ;
456436
457437 ParserRuleContext earliestRightAncestor = earliestAncestorEndingWithToken (node , curToken );
458- int earliestRightAncestorRuleIndex = earliestRightAncestor .getRuleIndex ();
459- int earliestRightAncestorRuleAlt = earliestRightAncestor .getAltNumber ();
460438
461439 int matchingSymbolOnDiffLine = getMatchingSymbolOnDiffLine (doc , node , line );
462440
463- // Get some context from parse tree
464- // if ( earliestLeftAncestor==null ) { // just use regular parent then
465- // ancestorParent = getParent(node);
466- // if ( ancestorParent!=null ) {
467- // ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
468- // }
469- // }
470- // else {
471- // ancestorParent = getParent(earliestLeftAncestor); // get parent but skip chain rules
472- // if ( ancestorParent!=null ) {
473- // ancestorParent2 = ancestorParent.getParent(); // get immediate parent for context
474- // }
475- // }
476- // ParserRuleContext ancestorParent3 = ancestorParent2!=null ? ancestorParent2.getParent() : null;
477- // ParserRuleContext ancestorParent4 = ancestorParent3!=null ? ancestorParent3.getParent() : null;
478- // ParserRuleContext ancestorParent5 = ancestorParent4!=null ? ancestorParent4.getParent() : null;
479-
480- // public static final int INDEX_PREV_TYPE = 0;
481- // public static final int INDEX_PREV_EARLIEST_RIGHT_ANCESTOR = 1;
482- // public static final int INDEX_CUR_TYPE = 2;
483- // public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 3;
484- // public static final int INDEX_FIRST_ON_LINE = 4; // a \n right before this token?
485- // public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 5;
486- // new FeatureMetaData(FeatureType.RULE, new String[] {"left ancestor", "parent"}, 1),
487- // new FeatureMetaData(FeatureType.INT, new String[] {"left ancestor", "child index"}, 1),
488-
489441 boolean curTokenStartsNewLine = tokens .LT (1 ).getLine ()>tokens .LT (-1 ).getLine ();
490442 int [] features = {
491443 tokens .LT (-1 ).getType (),
@@ -510,7 +462,6 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
510462 curToken .getCharPositionInLine ()
511463 };
512464 assert features .length == NUM_FEATURES ;
513- // System.out.print(curToken+": "+CodekNNClassifier._toString(features));
514465 return features ;
515466 }
516467
@@ -762,10 +713,6 @@ public static List<Token> getRealTokens(CommonTokenStream tokens) {
762713 return real ;
763714 }
764715
765- public static ParserRuleContext getParent (TerminalNode p ) {
766- return parentClosure ((ParserRuleContext )p .getParent ());
767- }
768-
769716 public static int getChildIndex (ParseTree t ) {
770717 if ( t ==null ) return -1 ;
771718 ParseTree parent = t .getParent ();
@@ -790,26 +737,6 @@ public static int getChildIndex(ParseTree t) {
790737 return -1 ;
791738 }
792739
793- /** Same as p.getParent() except we scan through chain rule nodes */
794- public static ParserRuleContext getParent (ParserRuleContext p ) {
795- if ( p ==null ) return null ;
796- ParserRuleContext lastValidParent = p .getParent ();
797- if ( lastValidParent ==null ) return null ; // must have hit the root
798-
799- return parentClosure (p .getParent ());
800- }
801-
802- // try to walk chain rules starting with the parent of the usual parent
803- public static ParserRuleContext parentClosure (ParserRuleContext p ) {
804- ParserRuleContext lastValidParent = p ;
805- ParserRuleContext q = lastValidParent .getParent ();
806- while ( q !=null && q .getChildCount ()==1 ) { // while is a chain rule
807- lastValidParent = q ;
808- q = q .getParent ();
809- }
810- return lastValidParent ;
811- }
812-
813740 /** Pack a rule index and an alternative number into the same 32-bit integer. */
814741 public static int rulealt (int rule , int alt ) {
815742 if ( rule ==-1 ) return -1 ;
0 commit comments