stanfordnlp/CoreNLP · error · Error

Attribute match already defined:

Error message

Attribute match already defined: 

What it means

A plain java.lang.Error thrown by the grammar's CoreMap attribute-match production when the same attribute name appears twice in a CoreMap node match expression (e.g. [{word:foo} {word:bar} {word:baz}] style constructs or [ner:X ner:Y]). The parser accumulates attribute matches into a Map and rejects duplicate keys. It is an Error, not a ParseException, so catch(ParseException) will not intercept it.

Solutions

  1. Remove or merge the duplicated attribute in the CoreMap node expression.
  2. Express alternatives within one attribute using a regex (e.g. word:/foo|bar/) instead of repeating the key.
  3. Deduplicate attribute names when generating rule strings programmatically.
  4. Pre-scan rule files for repeated keys within a single bracket expression before loading.

Example fix

// before
parser.parseNode(env, "[{word:foo}{word:foo}]"); // Error: Attribute match already defined: word
// after
parser.parseNode(env, "[{word:foo}]");
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: no repeated attribute keys inside a CoreMap node expression
static void checkNoDupAttrs(String expr) {
  java.util.regex.Matcher m = java.util.regex.Pattern.compile("(word|tag|ner|lemma|pos)\\s*:").matcher(expr);
  java.util.Set<String> seen = new java.util.HashSet<>();
  while (m.find()) { if (!seen.add(m.group(1))) throw new IllegalArgumentException("Duplicate attribute match: " + m.group(1)); }
}

Try / catch

try {
  parser.parseNode(env, coreMapExpr);
} catch (Error e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Attribute match already defined")) {
    throw new IllegalArgumentException("Duplicate attribute in CoreMap node: " + coreMapExpr, e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Parsing a CoreMap node expression that specifies the same attribute match key twice, e.g. [word:"a" word:"b"], via TokenSequenceParser node parsing paths for CoreMap attributes.

Common situations: Copy-pasted attribute clauses in rules files; template-based rule generation that appends the same attribute condition twice; merging rule fragments without checking for overlapping keys.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/7cd5f75764a2c4e7. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj:971

Map<String,String> AttrValue(Env env, Map<String,String> attributes) : {
	Token attr = null;
	Token value = null;
	Token tok = null;
	String str = null;
}   {
	    attr = <IDENTIFIER>
	    (    ":" (value = <STR> | value = <REGEX> | value = <IDENTIFIER> | str = CoreMapVarValue(env) )
	        | tok = "::"
	            value = <IDENTIFIER>
	        | tok = <NUMCMP>
	            ( value = NumberToken() | str = CoreMapVarValue(env) )
	    )
	    { if (value != null) { str = value.image; }
	      if (tok != null) { str = tok.image + str; }
	      if (attr != null && str != null)  {
	        if (attributes.containsKey(attr.image)) {
                throw new Error("Attribute match already defined: " + attr.image);
	        }
	        attributes.put(attr.image, str);
	      }
     	  return attributes;
	    }
	}



NodePattern CoreMapWordPattern(Env env) : {
    Map<String, String> attributes = new ArrayMap<String,String>();
    CoreMapNodePattern pat;
	Token value = null;
} {
	(
        ( value = <STR> | value = <REGEX>  | value = <IDENTIFIER>
           | value = <NONNEGINT> | value = <INT> | value = <LONGINT>
           | value = <REAL> | value = <STRSIMPLE> )

View on GitHub (pinned to 1b7edd19c4)