Skip to content

Commit 71ad47e

Browse files
committed
Push the Ssurgeon exception handling into the individual operation. Check for unreadable attributes at the same time as checking for illegal attributes - this will make EditNode also support checking those attributes
1 parent 5a0c2d5 commit 71ad47e

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/AddDep.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,17 @@ public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, Stri
4747
}
4848

4949
public AddDep(String govNodeName, GrammaticalRelation relation, Map<String, String> attributes, String position, double weight) {
50-
// if there's an exception, we'll barf here rather than at runtime
51-
try {
52-
CoreLabel newNodeObj = fromCheapStrings(attributes);
53-
} catch (UnsupportedOperationException e) {
54-
throw new SsurgeonParseException("Unable to process keys for AddDep operation", e);
55-
}
56-
5750
if (position != null) {
5851
if (!position.startsWith("-") && !position.startsWith("+")) {
5952
throw new SsurgeonParseException("Unknown position " + position + " in AddDep operation");
6053
}
6154
}
62-
55+
if (govNodeName == null) {
56+
throw new SsurgeonParseException("No governor given for an AddDep");
57+
}
58+
if (relation == null) {
59+
throw new SsurgeonParseException("No relation given for an AddDep");
60+
}
6361
checkIllegalAttributes(attributes);
6462

6563
this.attributes = new TreeMap<>(attributes);
@@ -220,6 +218,13 @@ public static void checkIllegalAttributes(Map<String, String> attributes) {
220218
if (attributes.containsKey("docID")) {
221219
throw new SsurgeonParseException("Cannot manually change a document ID. If you need an operation to change an entire sentence's document ID, please file an issue on github.");
222220
}
221+
222+
// if there's an exception, we'll barf when creating the pattern rather than at runtime
223+
try {
224+
CoreLabel newNodeObj = fromCheapStrings(attributes);
225+
} catch (UnsupportedOperationException e) {
226+
throw new SsurgeonParseException("Unable to process node attribute keys for Ssurgeon operation", e);
227+
}
223228
}
224229

225230
/**

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,11 @@ public static SsurgeonEdit parseEditLine(String editLine) {
375375
return new KillNonRootedNodes();
376376
}
377377

378+
// Parse the arguments based upon the type of command to execute.
378379
final SsurgeonArgs argsBox = parseArgsBox(tuples1.length == 1 ? "" : tuples1[1]);
379380

380-
// Parse the arguments based upon the type of command to execute.
381-
// TODO: this logic really should be moved into the individual classes. The string-->class
382-
// mappings should also be stored in more appropriate data structure.
383381
SsurgeonEdit retEdit;
384382
if (command.equalsIgnoreCase(AddDep.LABEL)) {
385-
if (argsBox.govNodeName == null) {
386-
throw new SsurgeonParseException("No governor given for an AddDep edit: " + editLine);
387-
}
388-
if (argsBox.reln == null) {
389-
throw new SsurgeonParseException("No relation given for an AddDep edit: " + editLine);
390-
}
391383
retEdit = AddDep.createEngAddDep(argsBox.govNodeName, argsBox.reln, argsBox.annotations, argsBox.position);
392384
} else if (command.equalsIgnoreCase(AddNode.LABEL)) {
393385
retEdit = AddNode.createAddNode(argsBox.nodeString, argsBox.name);

0 commit comments

Comments
 (0)