Commit c8f4a70c99f6ed23aebde47d61ee6abfd4c0b01c
1 parent
1a96cd74
naprawienie problemu z numerami w grafie fleksyjnym
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/trunk@396 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
4 changed files
with
26 additions
and
22 deletions
morfeusz/InflexionGraph.cpp
... | ... | @@ -141,7 +141,7 @@ void InflexionGraph::redirectEdges(unsigned int fromNode, unsigned int toNode) { |
141 | 141 | if (oldEdge.nextNode == fromNode) { |
142 | 142 | Edge newEdge = {oldEdge.chunk, toNode}; |
143 | 143 | if (!containsEqualEdge(edges, newEdge)) { |
144 | - // if newEdge is not in edges, redirect edgeEdge | |
144 | + // if newEdge is not in edges, redirect oldEdge | |
145 | 145 | // so it becomes newEdge |
146 | 146 | oldEdge.nextNode = toNode; |
147 | 147 | } |
... | ... | @@ -179,14 +179,8 @@ void InflexionGraph::doMergeNodes(unsigned int node1, unsigned int node2) { |
179 | 179 | this->graph[node1].push_back(e); |
180 | 180 | } |
181 | 181 | } |
182 | - // DEBUG("1"); | |
183 | - // debugGraph(this->graph); | |
184 | 182 | this->redirectEdges(node2, node1); |
185 | - // DEBUG("2"); | |
186 | - // debugGraph(this->graph); | |
187 | 183 | this->doRemoveNode(node2); |
188 | - // DEBUG("3"); | |
189 | - // debugGraph(this->graph); | |
190 | 184 | } |
191 | 185 | } |
192 | 186 | |
... | ... | @@ -206,7 +200,7 @@ void InflexionGraph::minimizeGraph() { |
206 | 200 | if (this->graph.size() > 2) { |
207 | 201 | // debugGraph(this->graph); |
208 | 202 | while (this->tryToMergeTwoNodes()) { |
209 | - // debugGraph(this->graph); | |
203 | + //debugGraph(this->graph); | |
210 | 204 | } |
211 | 205 | } |
212 | 206 | } |
... | ... | @@ -247,32 +241,35 @@ private: |
247 | 241 | vector< const char* > node2ChunkStartPtr; |
248 | 242 | }; |
249 | 243 | |
250 | -void InflexionGraph::swapNodes(unsigned int node1, unsigned int node2) { | |
251 | - swap(this->graph[node1], this->graph[node2]); | |
252 | - swap(this->node2ChunkStartPtr[node1], this->node2ChunkStartPtr[node2]); | |
253 | -} | |
254 | - | |
255 | 244 | // XXX this is a bit dirty |
256 | 245 | // fixes problem with "radem," (incorrect node numbers when inflexion graph is NOT a tree) |
246 | +// and "Z rozdrażnienieniem:)" | |
257 | 247 | void InflexionGraph::sortNodeNumbersTopologically() { |
258 | - vector<unsigned int> nodesNewPositions(createIdentityNodesMap(this->graph.size())); | |
248 | + vector<unsigned int> nodesTopologicallySorted(createIdentityNodesMap(this->graph.size())); | |
259 | 249 | TopologicalComparator comparator(this->node2ChunkStartPtr); |
260 | - sort(nodesNewPositions.begin(), nodesNewPositions.end(), comparator); | |
250 | + sort(nodesTopologicallySorted.begin(), nodesTopologicallySorted.end(), comparator); | |
251 | + vector<unsigned int> oldNode2NewNode(nodesTopologicallySorted.size()); | |
252 | + for (unsigned int newNode = 0; newNode < nodesTopologicallySorted.size(); newNode++) { | |
253 | + unsigned int oldNode = nodesTopologicallySorted[newNode]; | |
254 | + oldNode2NewNode[oldNode] = newNode; | |
255 | + } | |
261 | 256 | // swap pointers in edges |
262 | 257 | for (unsigned int node = 0; node < this->graph.size(); node++) { |
263 | 258 | for (unsigned int edgeIdx = 0; edgeIdx < this->graph[node].size(); edgeIdx++) { |
264 | 259 | InflexionGraph::Edge& edge = this->graph[node][edgeIdx]; |
265 | 260 | if (edge.nextNode < this->graph.size()) { // don't change UINT_MAX nodes (outside current graph) |
266 | - edge.nextNode = nodesNewPositions[edge.nextNode]; | |
261 | + edge.nextNode = oldNode2NewNode[edge.nextNode]; | |
267 | 262 | } |
268 | 263 | } |
269 | 264 | } |
270 | 265 | |
271 | 266 | // swap nodes |
272 | - for (unsigned int node = 0; node < this->graph.size(); node++) { | |
273 | - if (node < nodesNewPositions[node]) { // prevent swapping 2 times | |
274 | - swapNodes(node, nodesNewPositions[node]); | |
275 | - } | |
267 | + vector< vector<Edge> > graphCopy(this->graph); | |
268 | + vector< const char* > node2ChunkStartPtrCopy(this->node2ChunkStartPtr); | |
269 | + for (unsigned int oldNode = 0; oldNode < this->graph.size(); oldNode++) { | |
270 | + unsigned int newNode = oldNode2NewNode[oldNode]; | |
271 | + this->graph[newNode] = graphCopy[oldNode]; | |
272 | + this->node2ChunkStartPtr[newNode] = node2ChunkStartPtrCopy[oldNode]; | |
276 | 273 | } |
277 | 274 | } |
278 | 275 | |
... | ... |
morfeusz/InflexionGraph.hpp
tests/analyzer/test_inflection_graph_numbers/input.txt
tests/analyzer/test_inflection_graph_numbers/output.txt
... | ... | @@ -5,4 +5,12 @@ |
5 | 5 | [2,3,m,być,aglt:sg:pri:imperf:nwok,_,_] |
6 | 6 | [3,4,,,,,interp,_,_] |
7 | 7 | [4,5,kaszanka,kaszanka,subst:sg:nom:f,nazwa pospolita,kulin.] |
8 | +[0,1,rad,rad:v,winien:sg:m1.m2.m3:imperf,_,_] | |
9 | +[0,2,rade,rad:v,winien:sg:n1.n2:imperf,_,_] | |
10 | +[0,3,radem,rad:s,subst:sg:inst:m3,nazwa pospolita,_] | |
11 | +[1,3,em,być,aglt:sg:pri:imperf:wok,_,_] | |
12 | +[2,3,m,być,aglt:sg:pri:imperf:nwok,_,_] | |
13 | +[3,4,,,,,interp,_,_] | |
14 | +[4,5,,,,,interp,_,_] | |
15 | +[5,6,,,,,interp,_,_] | |
8 | 16 | |
... | ... |