stanfordnlp/CoreNLP · error · Error

Attribute match already defined

Error message

Attribute match already defined: ${attr.image}

What it means

When parsing attribute match specifications (TokensRegex node attributes like word:/foo/), the parser collects attributes into a map and throws 'Attribute match already defined: <attr>' if the same attribute key appears twice. This enforces one explicit match per attribute key within a node specification.

Solutions

  1. Remove or merge the duplicate attribute; combine alternatives inside a single regex instead (e.g. word:/a|b/).
  2. If both constraints are intended, they must go on separate nested nodes or use a conjunction syntax the version supports.
  3. Add a pre-parse lint that detects repeated attribute keys within each {} block of rule files.
  4. Check whether templated rule generation can emit the same attribute twice.

Example fix

// before
String node = "{ word:/a/ tag:/N/ word:/b/ }";
// after
String node = "{ word:/a|b/ tag:/N/ }"; // or drop the redundant word constraint
Defensive patterns

Strategy: validation

Validate before calling

// Detect duplicate attribute keys inside each {} node block
static void lintNode(String nodeBody) {
  java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\\w+)\\s*:").matcher(nodeBody);
  java.util.Set<String> seen = new java.util.HashSet<>();
  while (m.find()) {
    if (!seen.add(m.group(1))) throw new IllegalStateException("Duplicate attribute: " + m.group(1));
  }
}

Try / catch

try {
  attributes = parser.parseAttributes(text);
} catch (Error e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Attribute match already defined")) {
    throw new IllegalArgumentException("Fix duplicate attribute in node spec: " + e.getMessage(), e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Parsing a pattern node that specifies the same attribute matcher twice, e.g. '{ word:/a/ tag:/N/ word:/b/ }' — the second 'word' attribute triggers the Error at line 1687.

Common situations: Hand-edited rule files where duplicate attribute constraints accumulated; templating or concatenation of rule fragments that repeat an attribute; copy-paste between node specs.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java:1687

        break;
        }
      default:
        jj_la1[56] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      break;
      }
    default:
      jj_la1[57] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
if (value != null) { str = value.image; }
              if (tok != null) { str = tok.image + str; }
              if (attr != null && str != null)  {
                if (attributes.containsKey(attr.image)) {
                {if (true) throw new Error("Attribute match already defined: " + attr.image);}
                }
                attributes.put(attr.image, str);
              }
          {if ("" != null) return attributes;}
    throw new Error("Missing return statement in function");
}

  final public NodePattern CoreMapWordPattern(Env env) throws ParseException {Map<String, String> attributes = new ArrayMap<String,String>();
    CoreMapNodePattern pat;
        Token value = null;
    switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
    case STR:{
      value = jj_consume_token(STR);
      break;
      }
    case REGEX:{
      value = jj_consume_token(REGEX);
      break;

View on GitHub (pinned to 1b7edd19c4)