From d85ae8c28c947f48db3d5014ab2f12e7f014e911 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Fri, 22 Oct 2010 21:05:06 +0000 Subject: [PATCH] Fixed bug in protograph transposer in which cells in subsequent rows of a tree-shaped record (with blank context cells) are not processed. This bug was introduced when we started to allow a protograph node to correspond to more than one column. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1621 7d457c2a-affb-35e4-300a-418c747d4874 --- .../protograph/transpose/Transposer.java | 145 ++++++++++++------ 1 file changed, 97 insertions(+), 48 deletions(-) diff --git a/extensions/freebase/src/com/google/refine/freebase/protograph/transpose/Transposer.java b/extensions/freebase/src/com/google/refine/freebase/protograph/transpose/Transposer.java index 6b497bb6e..21da72c1a 100644 --- a/extensions/freebase/src/com/google/refine/freebase/protograph/transpose/Transposer.java +++ b/extensions/freebase/src/com/google/refine/freebase/protograph/transpose/Transposer.java @@ -132,7 +132,6 @@ public class Transposer { ) { List tnodes = new LinkedList(); - TransposedNode parentNode = context.parent == null ? null : context.parent.transposedNode; Link link = context.parent == null ? null : context.link; if (node instanceof CellNode) { @@ -144,6 +143,7 @@ public class Transposer { Cell cell = row.getCell(cellIndex); if (cell != null && ExpressionUtils.isNonBlankData(cell.value)) { + System.err.println("row " + rowIndex + " non-blank column " + columnName); if (node2 instanceof CellTopicNode && (cell.recon == null || cell.recon.judgment == Judgment.None)) { return; @@ -154,42 +154,95 @@ public class Transposer { return; } - tnodes.add(nodeFactory.transposeCellNode( - parentNode, - link, - node2, - rowIndex, - cellIndex, - cell - )); + if (context.parent == null) { + tnodes.add(nodeFactory.transposeCellNode( + null, + link, + node2, + rowIndex, + cellIndex, + cell + )); + } else { + for (TransposedNode parentNode : context.parent.transposedNodes) { + tnodes.add(nodeFactory.transposeCellNode( + parentNode, + link, + node2, + rowIndex, + cellIndex, + cell + )); + } + } + } else { + System.err.println("row " + rowIndex + " blank column " + columnName); } } } } else { if (node instanceof AnonymousNode) { - tnodes.add(nodeFactory.transposeAnonymousNode( - parentNode, - link, - (AnonymousNode) node, - rowIndex - )); + if (context.parent == null) { + tnodes.add(nodeFactory.transposeAnonymousNode( + null, + link, + (AnonymousNode) node, + rowIndex + )); + } else { + for (TransposedNode parentNode : context.parent.transposedNodes) { + tnodes.add(nodeFactory.transposeAnonymousNode( + parentNode, + link, + (AnonymousNode) node, + rowIndex + )); + } + } } else if (node instanceof FreebaseTopicNode) { - tnodes.add(nodeFactory.transposeTopicNode( - parentNode, - link, - (FreebaseTopicNode) node, - rowIndex - )); + if (context.parent == null) { + tnodes.add(nodeFactory.transposeTopicNode( + null, + link, + (FreebaseTopicNode) node, + rowIndex + )); + } else { + for (TransposedNode parentNode : context.parent.transposedNodes) { + tnodes.add(nodeFactory.transposeTopicNode( + parentNode, + link, + (FreebaseTopicNode) node, + rowIndex + )); + } + } } else if (node instanceof ValueNode) { - tnodes.add(nodeFactory.transposeValueNode( - parentNode, - link, - (ValueNode) node, - rowIndex - )); + if (context.parent == null) { + tnodes.add(nodeFactory.transposeValueNode( + null, + link, + (ValueNode) node, + rowIndex + )); + } else { + for (TransposedNode parentNode : context.parent.transposedNodes) { + tnodes.add(nodeFactory.transposeValueNode( + parentNode, + link, + (ValueNode) node, + rowIndex + )); + } + } } } + if (tnodes.size() > 0) { + context.transposedNodes.clear(); + context.transposedNodes.addAll(tnodes); + } + if (node instanceof NodeWithLinks) { NodeWithLinks node2 = (NodeWithLinks) node; int linkCount = node2.getLinkCount(); @@ -197,32 +250,28 @@ public class Transposer { for (int i = 0; i < linkCount; i++) { Link link2 = node2.getLink(i); if (link2.condition == null || link2.condition.test(project, rowIndex, row)) { - for (TransposedNode tnode : tnodes) { - context.transposedNode = tnode; - context.nullifySubContextNodes(); - - descend( - project, - protograph, - nodeFactory, - rowIndex, - row, - link2.getTarget(), - context.subContexts.get(i) - ); - } + System.err.println(" row " + rowIndex + " descend " + link2.property.id); + descend( + project, + protograph, + nodeFactory, + rowIndex, + row, + link2.getTarget(), + context.subContexts.get(i) + ); } } } } static class Context { - TransposedNode transposedNode; - List subContexts; - Context parent; - Link link; - int count; - int limit; + List transposedNodes = new LinkedList(); + List subContexts; + Context parent; + Link link; + int count; + int limit; Context(Node node, Context parent, Link link, int limit) { this.parent = parent; @@ -246,7 +295,7 @@ public class Transposer { public void nullifySubContextNodes() { if (subContexts != null) { for (Context context : subContexts) { - context.transposedNode = null; + context.transposedNodes.clear(); context.nullifySubContextNodes(); } }