Skip to content

Commit be70dd1

Browse files
committed
reorder features slightly.
1 parent 71a2dc3 commit be70dd1

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

java/src/org/antlr/codebuff/CollectFeatures.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public class CollectFeatures {
7070
public static final int INDEX_PREV_TYPE = 0;
7171
public static final int INDEX_PREV_EARLIEST_RIGHT_ANCESTOR = 1;
7272
public static final int INDEX_CUR_TYPE = 2;
73-
public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 3;
74-
public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 4;
75-
public static final int INDEX_FIRST_ON_LINE = 5; // a \n right before this token?
73+
public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 3;
74+
public static final int INDEX_FIRST_ON_LINE = 4; // a \n right before this token?
75+
public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 5;
7676

7777
public static final int INDEX_INFO_FILE = 6;
7878
public static final int INDEX_INFO_LINE = 7;
@@ -97,9 +97,10 @@ public class CollectFeatures {
9797
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(-1)"}, 1),
9898
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(-1)", "right ancestor"}, 1),
9999
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(1)"}, 1),
100-
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
101100
new FeatureMetaData(FeatureType.BOOL, new String[]{"Pair", "dif\\n"}, 1),
102101
new FeatureMetaData(FeatureType.BOOL, new String[]{"Strt", "line"}, 1),
102+
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
103+
// these 6 features seem to predict newline really well. whitespace ok too
103104
new FeatureMetaData(FeatureType.INFO_FILE, new String[] {"", "file"}, 0),
104105
new FeatureMetaData(FeatureType.INFO_LINE, new String[] {"", "line"}, 0),
105106
new FeatureMetaData(FeatureType.INFO_CHARPOS, new String[] {"char", "pos"}, 0)
@@ -109,9 +110,9 @@ public class CollectFeatures {
109110
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(-1)"}, 1),
110111
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(-1)", "right ancestor"}, 1),
111112
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(1)"}, 1),
112-
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
113113
new FeatureMetaData(FeatureType.BOOL, new String[]{"Pair", "dif\\n"}, 1),
114114
new FeatureMetaData(FeatureType.BOOL, new String[]{"Strt", "line"}, 1),
115+
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
115116
new FeatureMetaData(FeatureType.INFO_FILE, new String[] {"", "file"}, 0),
116117
new FeatureMetaData(FeatureType.INFO_LINE, new String[] {"", "line"}, 0),
117118
new FeatureMetaData(FeatureType.INFO_CHARPOS, new String[] {"char", "pos"}, 0)
@@ -121,9 +122,9 @@ public class CollectFeatures {
121122
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(-1)"}, 1),
122123
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(-1)", "right ancestor"}, 1),
123124
new FeatureMetaData(FeatureType.TOKEN, new String[] {"", "LT(1)"}, 1),
124-
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
125125
new FeatureMetaData(FeatureType.BOOL, new String[]{"Pair", "dif\\n"}, 1),
126126
new FeatureMetaData(FeatureType.BOOL, new String[]{"Strt", "line"}, 1),
127+
new FeatureMetaData(FeatureType.RULE, new String[] {"LT(1)", "left ancestor"}, 1),
127128
new FeatureMetaData(FeatureType.INFO_FILE, new String[] {"", "file"}, 0),
128129
new FeatureMetaData(FeatureType.INFO_LINE, new String[] {"", "line"}, 0),
129130
new FeatureMetaData(FeatureType.INFO_CHARPOS, new String[] {"char", "pos"}, 0)
@@ -429,21 +430,21 @@ public static int[] getNodeFeatures(Map<Token, TerminalNode> tokenToNodeMap,
429430
// ParserRuleContext ancestorParent4 = ancestorParent3!=null ? ancestorParent3.getParent() : null;
430431
// ParserRuleContext ancestorParent5 = ancestorParent4!=null ? ancestorParent4.getParent() : null;
431432

432-
// public static final int INDEX_PREV_TYPE = 0;
433-
// public static final int INDEX_PREV_EARLIEST_RIGHT_ANCESTOR = 1;
434-
// public static final int INDEX_TYPE = 2;
435-
// public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 3;
436-
// public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 4;
437-
// public static final int INDEX_FIRST_ON_LINE = 5; // a \n right before this token?
433+
// public static final int INDEX_PREV_TYPE = 0;
434+
// public static final int INDEX_PREV_EARLIEST_RIGHT_ANCESTOR = 1;
435+
// public static final int INDEX_CUR_TYPE = 2;
436+
// public static final int INDEX_MATCHING_TOKEN_DIFF_LINE = 3;
437+
// public static final int INDEX_FIRST_ON_LINE = 4; // a \n right before this token?
438+
// public static final int INDEX_EARLIEST_LEFT_ANCESTOR = 5;
438439

439440
boolean curTokenStartsNewLine = tokens.LT(1).getLine()>tokens.LT(-1).getLine();
440441
int[] features = {
441442
tokens.LT(-1).getType(),
442443
rulealt(prevEarliestAncestorRuleIndex,prevEarliestAncestorRuleAltNum),
443444
tokens.LT(1).getType(),
444-
rulealt(earliestLeftAncestorRuleIndex,earliestLeftAncestorRuleAlt),
445445
matchingSymbolOnDiffLine,
446446
curTokenStartsNewLine ? 1 : 0,
447+
rulealt(earliestLeftAncestorRuleIndex,earliestLeftAncestorRuleAlt),
447448

448449
// info
449450
0, // dummy; we don't store file index into feature vector

0 commit comments

Comments
 (0)