stanfordnlp/CoreNLP · error · SemgrexParseException
Duplicate attribute found in semgrex expression
Error message
Duplicate attribute found in semgrex expression
What it means
NodePattern.setAttribute (used by NodeAttributes) tracks positive (non-negated) attribute keys; setting the same key twice in one semgrex node is ambiguous, so it throws SemgrexParseException. Negated attributes are exempt from the duplicate check.
Solutions
- Remove the duplicate attribute from the node expression, merging values if possible
- Use a coordination/disanjunctive form if two values for one key were intended
- Deduplicate keys programmatically before calling AddAttribute/setAttribute
Example fix
// before
node.addAttribute("word", "foo", false); node.addAttribute("word", "bar", false);
// after
node.addAttribute("word", "foo", false); node.addAttribute("tag", "bar", false); Defensive patterns
Strategy: validation
Validate before calling
Set<String> seen = new HashSet<>(); for (Triple<String,String,Boolean> a : attrs) if (!a.third() && !seen.add(a.first())) throw new IllegalArgumentException("Duplicate attribute " + a.first()); Try / catch
try { nodeAttributes.setAttribute(key, value, negated); } catch (SemgrexParseException e) { log.error(e.getMessage()); } Prevention
- Deduplicate attribute keys before building a node
- Merge repeated keys with disjunction instead of repeating them
- Validate generated patterns with a dry parse in CI
When it happens
Trigger: Calling setAttribute twice with the same key and negated=false on the same node's attribute builder, or writing a semgrex node with a repeated positive attribute (e.g. '[word foo word bar]').
Common situations: Hand-written semgrex patterns repeating an attribute, generated patterns from templates where a key is substituted twice, or programmatic AddAttribute calls in a loop without deduplication.
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
- Semgrex pattern asked for uniq of node which does not…
- We need at least 2 extractors for ExtractorMerger to make…
- Too many columns: / (offset: )
- Too few columns: / (offset: )
- Sentence.toSentence: lengths differ
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/446b93c490a22d7c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/NodeAttributes.java:65
this.root = root;
}
public boolean root() {
return root;
}
public void setEmpty(boolean empty) {
this.empty = empty;
}
public boolean empty() {
return empty;
}
public void setAttribute(String key, String value, boolean negated) {
if (!negated) {
if (positiveAttributes.contains(key)) {
throw new SemgrexParseException("Duplicate attribute " + key + " found in semgrex expression");
}
positiveAttributes.add(key);
}
attributes.add(new Triple(key, value, negated));
}
public void addContains(String annotation, String key, String value, Boolean negated) {
contains.add(new Quadruple(annotation, key, value, negated));
}
public List<Triple<String, String, Boolean>> attributes() {
return Collections.unmodifiableList(attributes);
}
public List<Quadruple<String, String, String, Boolean>> contains() {
return Collections.unmodifiableList(contains);
}
}View on GitHub (pinned to 1b7edd19c4)