Skip to content

Commit 07cca17

Browse files
committed
Apparently new relations need to go at the bottom to avoid messing up the order of serial version ids in a map in already serialized parse models...?
1 parent 1438b40 commit 07cca17

File tree

1 file changed

+105
-105
lines changed

1 file changed

+105
-105
lines changed

src/edu/stanford/nlp/trees/tregex/Relation.java

Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -296,111 +296,6 @@ Iterator<Tree> searchNodeIterator(final Tree t,
296296
}
297297
};
298298

299-
private static final Relation ANCESTOR_OF_LEAF = new Relation("<<<") {
300-
301-
private static final long serialVersionUID = -78542691313554L;
302-
303-
@Override
304-
Iterator<Tree> searchNodeIterator(final Tree t,
305-
final TregexMatcher matcher) {
306-
return new SearchNodeIterator() {
307-
Stack<Tree> searchStack;
308-
309-
@Override
310-
public void initialize() {
311-
searchStack = new Stack<>();
312-
for (int i = t.numChildren() - 1; i >= 0; i--) {
313-
searchStack.push(t.getChild(i));
314-
}
315-
if (!searchStack.isEmpty()) {
316-
advance();
317-
}
318-
}
319-
320-
@Override
321-
void advance() {
322-
// using getLeaves() would be simpler code,
323-
// but this was easy enough
324-
next = null;
325-
while (next == null && !searchStack.isEmpty()) {
326-
next = searchStack.pop();
327-
for (int i = next.numChildren() - 1; i >= 0; i--) {
328-
searchStack.push(next.getChild(i));
329-
}
330-
// we've added the next layer of children, but we're not
331-
// at a leaf, so keep going if there are nodes left to search
332-
if (!next.isLeaf()) {
333-
next = null;
334-
}
335-
}
336-
}
337-
};
338-
}
339-
};
340-
341-
/**
342-
* Looks for the ith leaf of the current node
343-
*/
344-
private static class AncestorOfIthLeaf extends Relation {
345-
346-
private static final long serialVersionUID = -6495191354526L;
347-
348-
private final int leafNum;
349-
350-
AncestorOfIthLeaf(int i) {
351-
super("<<<" + String.valueOf(i));
352-
if (i == 0) {
353-
throw new IllegalArgumentException("Error -- no such thing as zeroth leaf!");
354-
}
355-
leafNum = i;
356-
}
357-
358-
@Override
359-
Iterator<Tree> searchNodeIterator(final Tree t,
360-
final TregexMatcher matcher) {
361-
return new SearchNodeIterator() {
362-
@Override
363-
void initialize() {
364-
// this is a little lazy in terms of coding
365-
// would be a bit faster to actually recurse through the tree
366-
// this is unlikely to ever be a performance limitation, though
367-
List<Tree> leaves = t.getLeaves();
368-
if (leaves.size() >= Math.abs(leafNum)) {
369-
final int index;
370-
if (leafNum > 0) {
371-
index = leafNum - 1;
372-
} else {
373-
index = leafNum + leaves.size();
374-
}
375-
next = leaves.get(index);
376-
}
377-
}
378-
};
379-
}
380-
381-
@Override
382-
public boolean equals(Object o) {
383-
if (this == o) {
384-
return true;
385-
}
386-
if (!(o instanceof AncestorOfIthLeaf)) {
387-
return false;
388-
}
389-
390-
final AncestorOfIthLeaf other = (AncestorOfIthLeaf) o;
391-
if (leafNum != other.leafNum) {
392-
return false;
393-
}
394-
395-
return true;
396-
}
397-
398-
@Override
399-
public int hashCode() {
400-
return leafNum + 20;
401-
}
402-
};
403-
404299
private static final Relation DOMINATES = new Relation("<<") {
405300

406301
private static final long serialVersionUID = -2580199434621268260L;
@@ -1057,6 +952,111 @@ public void advance() {
1057952
}
1058953
};
1059954

955+
private static final Relation ANCESTOR_OF_LEAF = new Relation("<<<") {
956+
957+
private static final long serialVersionUID = -78542691313554L;
958+
959+
@Override
960+
Iterator<Tree> searchNodeIterator(final Tree t,
961+
final TregexMatcher matcher) {
962+
return new SearchNodeIterator() {
963+
Stack<Tree> searchStack;
964+
965+
@Override
966+
public void initialize() {
967+
searchStack = new Stack<>();
968+
for (int i = t.numChildren() - 1; i >= 0; i--) {
969+
searchStack.push(t.getChild(i));
970+
}
971+
if (!searchStack.isEmpty()) {
972+
advance();
973+
}
974+
}
975+
976+
@Override
977+
void advance() {
978+
// using getLeaves() would be simpler code,
979+
// but this was easy enough
980+
next = null;
981+
while (next == null && !searchStack.isEmpty()) {
982+
next = searchStack.pop();
983+
for (int i = next.numChildren() - 1; i >= 0; i--) {
984+
searchStack.push(next.getChild(i));
985+
}
986+
// we've added the next layer of children, but we're not
987+
// at a leaf, so keep going if there are nodes left to search
988+
if (!next.isLeaf()) {
989+
next = null;
990+
}
991+
}
992+
}
993+
};
994+
}
995+
};
996+
997+
/**
998+
* Looks for the ith leaf of the current node
999+
*/
1000+
private static class AncestorOfIthLeaf extends Relation {
1001+
1002+
private static final long serialVersionUID = -6495191354526L;
1003+
1004+
private final int leafNum;
1005+
1006+
AncestorOfIthLeaf(int i) {
1007+
super("<<<" + String.valueOf(i));
1008+
if (i == 0) {
1009+
throw new IllegalArgumentException("Error -- no such thing as zeroth leaf!");
1010+
}
1011+
leafNum = i;
1012+
}
1013+
1014+
@Override
1015+
Iterator<Tree> searchNodeIterator(final Tree t,
1016+
final TregexMatcher matcher) {
1017+
return new SearchNodeIterator() {
1018+
@Override
1019+
void initialize() {
1020+
// this is a little lazy in terms of coding
1021+
// would be a bit faster to actually recurse through the tree
1022+
// this is unlikely to ever be a performance limitation, though
1023+
List<Tree> leaves = t.getLeaves();
1024+
if (leaves.size() >= Math.abs(leafNum)) {
1025+
final int index;
1026+
if (leafNum > 0) {
1027+
index = leafNum - 1;
1028+
} else {
1029+
index = leafNum + leaves.size();
1030+
}
1031+
next = leaves.get(index);
1032+
}
1033+
}
1034+
};
1035+
}
1036+
1037+
@Override
1038+
public boolean equals(Object o) {
1039+
if (this == o) {
1040+
return true;
1041+
}
1042+
if (!(o instanceof AncestorOfIthLeaf)) {
1043+
return false;
1044+
}
1045+
1046+
final AncestorOfIthLeaf other = (AncestorOfIthLeaf) o;
1047+
if (leafNum != other.leafNum) {
1048+
return false;
1049+
}
1050+
1051+
return true;
1052+
}
1053+
1054+
@Override
1055+
public int hashCode() {
1056+
return leafNum + 20;
1057+
}
1058+
};
1059+
10601060
private static final Relation[] SIMPLE_RELATIONS = {
10611061
DOMINATES, DOMINATED_BY, PARENT_OF, CHILD_OF, PRECEDES,
10621062
IMMEDIATELY_PRECEDES, FOLLOWS, IMMEDIATELY_FOLLOWS,

0 commit comments

Comments
 (0)