You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by tm...@apache.org on 2013/02/12 16:33:21 UTC

svn commit: r1445197 - in /incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util: AnnotationTreeUtils.java TreeUtils.java

Author: tmill
Date: Tue Feb 12 15:33:21 2013
New Revision: 1445197

URL: http://svn.apache.org/r1445197
Log:
ctakes-153 - still had a few issues discovered after testing on real data.

Modified:
    incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java
    incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java

Modified: incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java?rev=1445197&r1=1445196&r2=1445197&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java (original)
+++ incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java Tue Feb 12 15:33:21 2013
@@ -146,7 +146,7 @@ public class AnnotationTreeUtils {
 			lastTree = tree;
 			// only continue downward traversal if we are not at a POS node...
 //			if(tree.getChildren().size() > 1 || tree.getChildren(0).getChildren() != null){
-			if(tree.getLeaf()){
+			if(!tree.getLeaf()){
 				for(int i = 0; i < tree.getChildren().size(); i++){
 					TreebankNode child = tree.getChildren(i);
 					if(child.getBegin() <= arg1.getBegin() && child.getEnd() >= arg1.getEnd()){
@@ -169,6 +169,7 @@ public class AnnotationTreeUtils {
 			newTree.setChildren(0, tree);
 			newTree.setParent(tree.getParent());
 			TreeUtils.replaceChild(tree.getParent(), tree, newTree);
+			tree.setParent(newTree);
 //			newTree.setNodeType(tree.getNodeType());
 //			newTree.setChildren(tree.getChildren());
 //			newTree.setParent(tree);
@@ -181,16 +182,22 @@ public class AnnotationTreeUtils {
 
 			int startChild = -1;
 			int endChild = -1;
-			for(int i = 0; i < tree.getChildren().size(); i++){
-				if(startChild == -1){
-					if(tree.getChildren(i).getBegin() == arg1.getBegin()){
-						startChild = i;
+			
+			if(!tree.getLeaf()){
+				// it can happen that the tree here is a terminal (pos tag:word) and thus has no children, in the case that the gold
+				// standard entities are tokenized correctly and the tokenizer is wrong. With automatic tokens and entities this shouldn't happen.
+				for(int i = 0; i < tree.getChildren().size(); i++){
+					if(startChild == -1){
+						if(tree.getChildren(i).getBegin() == arg1.getBegin()){
+							startChild = i;
+						}
+					}else if(tree.getChildren(i).getEnd() == arg1.getEnd()){
+						endChild = i;
+						break;
 					}
-				}else if(tree.getChildren(i).getEnd() == arg1.getEnd()){
-					endChild = i;
-					break;
 				}
 			}
+			
 			// here is where we insert if possible
 			if(startChild >= 0 && endChild >= 0){
 				newTree = new TreebankNode(jcas, tree.getChildren(startChild).getBegin(), tree.getChildren(endChild).getEnd());
@@ -220,6 +227,7 @@ public class AnnotationTreeUtils {
 				newTree.setChildren(0, tree);
 				newTree.setParent(tree.getParent());
 				TreeUtils.replaceChild(tree.getParent(), tree, newTree);
+				tree.setParent(newTree);
 //				newTree.setNodeType(tree.getNodeType());
 //				newTree.setChildren(tree.getChildren());
 //				newTree.setParent(tree);

Modified: incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java?rev=1445197&r1=1445196&r2=1445197&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java (original)
+++ incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java Tue Feb 12 15:33:21 2013
@@ -219,7 +219,7 @@ public class TreeUtils {
 			}else{
 				ttn.setNodeValue(w.getCoveredText());
 			}
-			ttn.addToIndexes();
+//			ttn.addToIndexes();
 			terms.set(i, ttn);
 		}
 		
@@ -271,13 +271,15 @@ public class TreeUtils {
 				TerminalTreebankNode term = root.getTerminals(subtree.getHeadIndex());
 				term.setNodeType(subtree.getType());
 				children.set(i,term);
-				term.setParent(parent);				
+				term.setParent(parent);
+				term.addToIndexes();
 			}else{
 				try{
 					TreebankNode child = new TreebankNode(jcas);
 					child.setParent(parent);
 					children.set(i, child);
 					recursivelyCreateStructure(jcas, child, subtree, root);
+					child.addToIndexes();
 				}catch(NullPointerException e){
 					System.err.println("MaxentParserWrapper Error: " + e);
 					throw new AnalysisEngineProcessException();
@@ -293,9 +295,12 @@ public class TreeUtils {
 
 	public static void replaceChild(TreebankNode parent, TreebankNode oldTree,
 			TreebankNode newTree) {
-		for(int i = 0; i < parent.getChildren().size(); i++){
-			if(parent.getChildren(i) == oldTree){
-				parent.setChildren(i, newTree);
+		// if parent is null that means we're already at the top -- no pointers to fix.
+		if(parent != null){
+			for(int i = 0; i < parent.getChildren().size(); i++){
+				if(parent.getChildren(i) == oldTree){
+					parent.setChildren(i, newTree);
+				}
 			}
 		}
 	}