Skip to content

Commit e94c812

Browse files
committed
Some Ssurgeon commands don't use the standard argsbox. Parse those separately before using the argsbox (otherwise SetRoots won't correctly parse, for example)
1 parent 45f8c94 commit e94c812

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,9 @@ private static String[] parseArgs(String argsString) {
294294
return retList.toArray(StringUtils.EMPTY_STRING_ARRAY);
295295
}
296296

297-
/**
298-
* Given a string entry, converts it into a SsurgeonEdit object.
299-
*/
300-
public static SsurgeonEdit parseEditLine(String editLine) {
301-
// Extract the operation name first
302-
final String[] tuples1 = editLine.split("\\s+", 2);
303-
if (tuples1.length < 1) {
304-
throw new SsurgeonParseException("Error in SsurgeonEdit.parseEditLine: invalid number of arguments");
305-
}
306-
final String command = tuples1[0];
307-
final String[] argsArray = tuples1.length == 1 ? new String[0] : parseArgs(tuples1[1]);
297+
private static SsurgeonArgs parseArgsBox(String args) {
308298
SsurgeonArgs argsBox = new SsurgeonArgs();
299+
final String[] argsArray = parseArgs(args);
309300

310301
for (int argIndex = 0; argIndex < argsArray.length; ++argIndex) {
311302
switch (argsArray[argIndex]) {
@@ -345,7 +336,29 @@ public static SsurgeonEdit parseEditLine(String editLine) {
345336
throw new SsurgeonParseException("Parsing Ssurgeon args: unknown flag " + argsArray[argIndex]);
346337
}
347338
}
339+
return argsBox;
340+
}
341+
342+
/**
343+
* Given a string entry, converts it into a SsurgeonEdit object.
344+
*/
345+
public static SsurgeonEdit parseEditLine(String editLine) {
346+
// Extract the operation name first
347+
final String[] tuples1 = editLine.split("\\s+", 2);
348+
if (tuples1.length < 1) {
349+
throw new SsurgeonParseException("Error in SsurgeonEdit.parseEditLine: invalid number of arguments");
350+
}
351+
final String command = tuples1[0];
348352

353+
if (command.equalsIgnoreCase(SetRoots.LABEL)) {
354+
String[] names = tuples1[1].split("\\s+");
355+
List<String> newRoots = Arrays.asList(names);
356+
return new SetRoots(newRoots);
357+
} else if (command.equalsIgnoreCase(KillNonRootedNodes.LABEL)) {
358+
return new KillNonRootedNodes();
359+
}
360+
361+
final SsurgeonArgs argsBox = parseArgsBox(tuples1.length == 1 ? "" : tuples1[1]);
349362

350363
// Parse the arguments based upon the type of command to execute.
351364
// TODO: this logic really should be moved into the individual classes. The string-->class
@@ -367,12 +380,6 @@ public static SsurgeonEdit parseEditLine(String editLine) {
367380
retEdit = new RemoveEdge(reln, argsBox.govNodeName, argsBox.dep);
368381
} else if (command.equalsIgnoreCase(RemoveNamedEdge.LABEL)) {
369382
retEdit = new RemoveNamedEdge(argsBox.edge);
370-
} else if (command.equalsIgnoreCase(SetRoots.LABEL)) {
371-
String[] names = tuples1[1].split("\\s+");
372-
List<String> newRoots = Arrays.asList(names);
373-
retEdit = new SetRoots(newRoots);
374-
} else if (command.equalsIgnoreCase(KillNonRootedNodes.LABEL)) {
375-
retEdit = new KillNonRootedNodes();
376383
} else if (command.equalsIgnoreCase(KillAllIncomingEdges.LABEL)) {
377384
retEdit = new KillAllIncomingEdges(argsBox.node);
378385
} else {

0 commit comments

Comments
 (0)