@@ -99,10 +99,8 @@ public String toEditString() {
99
99
return buf .toString ();
100
100
}
101
101
102
- // TODO: update the SemgrexMatcher
103
- // currently the Ssurgeon will not be able to proceed after this edit
104
- // since all of the node and edge pointers will be rewritten
105
- public static void moveNode (SemanticGraph sg , IndexedWord word , int newIndex ) {
102
+ // TODO: update the SemgrexMatcher's edges as well
103
+ public static void moveNode (SemanticGraph sg , SemgrexMatcher sm , IndexedWord word , int newIndex ) {
106
104
List <SemanticGraphEdge > outgoing = sg .outgoingEdgeList (word );
107
105
List <SemanticGraphEdge > incoming = sg .incomingEdgeList (word );
108
106
boolean isRoot = sg .isRoot (word );
@@ -120,6 +118,12 @@ public static void moveNode(SemanticGraph sg, IndexedWord word, int newIndex) {
120
118
sg .setRoots (newRoots );
121
119
}
122
120
121
+ for (String name : sm .getNodeNames ()) {
122
+ if (sm .getNode (name ) == word ) {
123
+ sm .putNode (name , newWord );
124
+ }
125
+ }
126
+
123
127
for (SemanticGraphEdge oldEdge : outgoing ) {
124
128
SemanticGraphEdge newEdge = new SemanticGraphEdge (newWord , oldEdge .getTarget (), oldEdge .getRelation (), oldEdge .getWeight (), oldEdge .isExtra ());
125
129
sg .addEdge (newEdge );
@@ -131,13 +135,13 @@ public static void moveNode(SemanticGraph sg, IndexedWord word, int newIndex) {
131
135
}
132
136
}
133
137
134
- public static void moveNodes (SemanticGraph sg , Function <Integer , Boolean > shouldMove , Function <Integer , Integer > destination ) {
138
+ public static void moveNodes (SemanticGraph sg , SemgrexMatcher sm , Function <Integer , Boolean > shouldMove , Function <Integer , Integer > destination ) {
135
139
// iterate first, then move, so that we don't screw up the graph while iterating
136
140
List <IndexedWord > toMove = sg .vertexSet ().stream ().filter (x -> shouldMove .apply (x .index ())).collect (Collectors .toList ());
137
141
Collections .sort (toMove );
138
142
Collections .reverse (toMove );
139
143
for (IndexedWord word : toMove ) {
140
- moveNode (sg , word , destination .apply (word .index ()));
144
+ moveNode (sg , sm , word , destination .apply (word .index ()));
141
145
}
142
146
}
143
147
@@ -195,8 +199,8 @@ public boolean evaluate(SemanticGraph sg, SemgrexMatcher sm) {
195
199
if (position != null && !position .equals ("+" )) {
196
200
// the payoff for tempIndex == maxIndex + 2:
197
201
// everything will be moved one higher, unless it's the new node
198
- moveNodes (sg , x -> (x >= newIndex && x != tempIndex ), x -> x +1 );
199
- moveNode (sg , newNode , newIndex );
202
+ moveNodes (sg , sm , x -> (x >= newIndex && x != tempIndex ), x -> x +1 );
203
+ moveNode (sg , sm , newNode , newIndex );
200
204
}
201
205
202
206
return true ;
0 commit comments