/** * {@inheritDoc} */ @Override public String toString() { return String.format( "Match %s; found %d labels", succeeded() ? "succeeded" : "failed", getLabels().size()); } }
public MultiMap<String, LabelElementPair> getElementLabelDefs() { MultiMap<String, LabelElementPair> defs = new MultiMap<String, LabelElementPair>(); for (int i=1; i<=numberOfAlts; i++) { for (List<LabelElementPair> pairs : alt[i].labelDefs.values()) { for (LabelElementPair p : pairs) { defs.map(p.label.getText(), p); } } } return defs; }
MultiMap<FeatureVectorAsObject,Integer> wsContextToIndex = new MultiMap<>(); MultiMap<FeatureVectorAsObject,Integer> hposContextToIndex = new MultiMap<>(); wsContextToIndex.map(new FeatureVectorAsObject(features, Trainer.FEATURES_INJECT_WS), i); hposContextToIndex.map(new FeatureVectorAsObject(features, Trainer.FEATURES_HPOS), i); for (FeatureVectorAsObject fo : wsContextToIndex.keySet()) { List<Integer> exemplarIndexes = wsContextToIndex.get(fo); MultiMap<Integer,Integer> wsCatToIndexes = new MultiMap<>(); for (Integer i : exemplarIndexes) { wsCatToIndexes.map(corpus.injectWhitespace.get(i), i); if ( wsCatToIndexes.size()==1 ) continue; if ( report ) System.out.println("Feature vector has "+exemplarIndexes.size()+" exemplars"); List<Integer> catCounts = BuffUtils.map(wsCatToIndexes.values(), List::size); double wsEntropy = getNormalizedCategoryEntropy(getCategoryRatios(catCounts)); if ( report ) System.out.printf("entropy=%5.4f\n", wsEntropy); for (Integer cat : wsCatToIndexes.keySet()) { List<Integer> indexes = wsCatToIndexes.get(cat); for (Integer i : indexes) { String display = getExemplarDisplay(Trainer.FEATURES_INJECT_WS, corpus, corpus.injectWhitespace, i); for (FeatureVectorAsObject fo : hposContextToIndex.keySet()) { List<Integer> exemplarIndexes = hposContextToIndex.get(fo); MultiMap<Integer,Integer> hposCatToIndexes = new MultiMap<>(); for (Integer i : exemplarIndexes) {
public void map(K key, V value) { List<V> elementsForKey = get(key); if ( elementsForKey==null ) { elementsForKey = new ArrayList<V>(); super.put(key, elementsForKey); } elementsForKey.add(value); }
public Set<String> getTokenRefs() { Set<String> refs = new HashSet<String>(); for (int i=1; i<=numberOfAlts; i++) { refs.addAll(alt[i].tokenRefs.keySet()); } return refs; }
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol(); labels.map(tokenTagToken.getTokenName(), tree); if ( tokenTagToken.getLabel()!=null ) { labels.map(tokenTagToken.getLabel(), tree); if ( r1.getRuleContext().getRuleIndex() == r2.getRuleContext().getRuleIndex() ) { labels.map(ruleTagToken.getRuleName(), tree); if ( ruleTagToken.getLabel()!=null ) { labels.map(ruleTagToken.getLabel(), tree);
MultiMap<String, File> grammarFileByFolder = new MultiMap<String, File>(); getLog().debug(" ... relative path is: " + relPath); grammarFileByFolder.map(relPathBase, grammarFile); for (Map.Entry<String, List<File>> entry : grammarFileByFolder.entrySet()) { List<String> folderArgs = new ArrayList<String>(args); if (!folderArgs.contains("-package") && !entry.getKey().isEmpty()) {
@Override public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { Alternative currentOuterMostAlt = getCurrentOuterMostAlt(); boolean actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.containsKey(ID.getText()); boolean actionRefsAsRule = currentOuterMostAlt.ruleRefsInActions.containsKey(ID.getText()); return op.getLabels().isEmpty() && (actionRefsAsToken || actionRefsAsRule); }
if (g.isLexer()) { LexerGrammar lexerGrammar = (LexerGrammar)g; for (List<Rule> rules : lexerGrammar.modes.values()) {
/** * Return all nodes matching a rule or token tag with the specified label. * * <p>If the {@code label} is the name of a parser rule or token in the * grammar, the resulting list will contain both the parse trees matching * rule or tags explicitly labeled with the label and the complete set of * parse trees matching the labeled and unlabeled tags in the pattern for * the parser rule or token. For example, if {@code label} is {@code "foo"}, * the result will contain <em>all</em> of the following.</p> * * <ul> * <li>Parse tree nodes matching tags of the form {@code <foo:anyRuleName>} and * {@code <foo:AnyTokenName>}.</li> * <li>Parse tree nodes matching tags of the form {@code <anyLabel:foo>}.</li> * <li>Parse tree nodes matching tags of the form {@code <foo>}.</li> * </ul> * * @param label The label. * * @return A collection of all {@link ParseTree} nodes matching tags with * the specified {@code label}. If no nodes matched the label, an empty list * is returned. */ public List<ParseTree> getAll(String label) { List<ParseTree> nodes = labels.get(label); if ( nodes==null ) { return Collections.emptyList(); } return nodes; }
public Set<String> getElementLabelNames() { Set<String> refs = new HashSet<String>(); for (int i=1; i<=numberOfAlts; i++) { refs.addAll(alt[i].labelDefs.keySet()); } if ( refs.isEmpty() ) return null; return refs; }
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link ParseTreeMatch} object that contains the matched elements, or the * node at which the match failed. Pass in a compiled pattern instead of a * string representation of a tree pattern. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }
@Override public void tokenRef(TerminalAST ref) { terminals.add(ref); tokenIDRefs.add(ref); if ( currentRule!=null ) { currentRule.alt[currentOuterAltNumber].tokenRefs.map(ref.getText(), ref); } }
if (lexerGrammar.modes.containsKey(channelName)) { g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_MODE, g.fileName, channel.token, channelName);
if (g.isLexer()) { LexerGrammar lexerGrammar = (LexerGrammar)g; for (List<Rule> rules : lexerGrammar.modes.values()) {