MCPcopy Create free account
hub / github.com/antlr/codebuff / collectTokenPairsAndSplitListInfo

Method collectTokenPairsAndSplitListInfo

src/org/antlr/codebuff/Corpus.java:93–140  ·  view source on GitHub ↗

Walk all documents to compute matching token dependencies (we need this for feature computation) While we're at it, find sibling lists.

()

Source from the content-addressed store, hash-verified

91 * While we're at it, find sibling lists.
92 */
93 public void collectTokenPairsAndSplitListInfo() throws NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException {
94 Vocabulary vocab = getLexer(language.lexerClass, null).getVocabulary();
95 String[] ruleNames = getParser(language.parserClass, null).getRuleNames();
96 CollectTokenPairs collectTokenPairs = new CollectTokenPairs(vocab, ruleNames);
97 CollectSiblingLists collectSiblingLists = new CollectSiblingLists();
98 for (InputDocument doc : documents) {
99 collectSiblingLists.setTokens(doc.tokens, doc.tree, doc.tokenToNodeMap);
100 ParseTreeWalker.DEFAULT.walk(collectTokenPairs, doc.tree);
101 ParseTreeWalker.DEFAULT.walk(collectSiblingLists, doc.tree);
102 }
103 ruleToPairsBag = collectTokenPairs.getDependencies();
104 rootAndChildListStats = collectSiblingLists.getListStats();
105 rootAndSplitChildListStats = collectSiblingLists.getSplitListStats();
106 tokenToListInfo = collectSiblingLists.getTokenToListInfo();
107
108 if ( false ) {
109 for (RuleAltKey ruleAltKey : ruleToPairsBag.keySet()) {
110 List<Pair<Integer, Integer>> pairs = ruleToPairsBag.get(ruleAltKey);
111 System.out.print(ruleAltKey+" -> ");
112 for (Pair<Integer, Integer> p : pairs) {
113 System.out.print(vocab.getDisplayName(p.a)+","+vocab.getDisplayName(p.b)+" ");
114 }
115 System.out.println();
116 }
117 }
118
119 if ( false ) {
120 for (ParentSiblingListKey siblingPairs : rootAndChildListStats.keySet()) {
121 String parent = ruleNames[siblingPairs.parentRuleIndex];
122 parent = parent.replace("Context","");
123 String siblingListName = ruleNames[siblingPairs.childRuleIndex];
124 siblingListName = siblingListName.replace("Context","");
125 System.out.println(parent+":"+siblingPairs.parentRuleAlt+"->"+siblingListName+":"+siblingPairs.childRuleAlt+
126 " (n,min,median,var,max)="+rootAndChildListStats.get(siblingPairs));
127 }
128 Map<ParentSiblingListKey, Integer> splitListForms =
129 collectSiblingLists.getSplitListForms();
130 for (ParentSiblingListKey siblingPairs : rootAndSplitChildListStats.keySet()) {
131 String parent = ruleNames[siblingPairs.parentRuleIndex];
132 parent = parent.replace("Context","");
133 String siblingListName = ruleNames[siblingPairs.childRuleIndex];
134 siblingListName = siblingListName.replace("Context","");
135 System.out.println("SPLIT " +parent+":"+siblingPairs.parentRuleAlt+"->"+siblingListName+":"+siblingPairs.childRuleAlt+
136 " (n,min,median,var,max)="+rootAndSplitChildListStats.get(siblingPairs)+
137 " form "+splitListForms.get(siblingPairs));
138 }
139 }
140 }
141
142 public void trainOnSampleDocs() throws Exception {
143 documentsPerExemplar = new ArrayList<>();

Callers 1

trainMethod · 0.95

Calls 15

setTokensMethod · 0.95
getDependenciesMethod · 0.95
getListStatsMethod · 0.95
getSplitListStatsMethod · 0.95
getTokenToListInfoMethod · 0.95
getSplitListFormsMethod · 0.95
getVocabularyMethod · 0.80
getLexerMethod · 0.80
getRuleNamesMethod · 0.80
getParserMethod · 0.80
printMethod · 0.80
keySetMethod · 0.65

Tested by

no test coverage detected