ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1471600 - in /ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util: AnnotationTreeUtils.java TreeUtils.java
Date Wed, 24 Apr 2013 19:03:36 GMT
Author: tmill
Date: Wed Apr 24 19:03:36 2013
New Revision: 1471600

URL: http://svn.apache.org/r1471600
Log:
Bugfix - make sure something has root as its parent.

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

Modified: ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java?rev=1471600&r1=1471599&r2=1471600&view=diff
==============================================================================
--- ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java
(original)
+++ ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/AnnotationTreeUtils.java
Wed Apr 24 19:03:36 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.ctakes.constituency.parser.util;
 
+import java.util.Collection;
+
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.cas.FSArray;
@@ -26,24 +28,31 @@ import org.apache.uima.jcas.tcas.Annotat
 import org.apache.ctakes.typesystem.type.syntax.TerminalTreebankNode;
 import org.apache.ctakes.typesystem.type.syntax.TopTreebankNode;
 import org.apache.ctakes.typesystem.type.syntax.TreebankNode;
+import org.uimafit.util.JCasUtil;
 
 
 public class AnnotationTreeUtils {
 	
 	public static TopTreebankNode getAnnotationTree(JCas jcas, Annotation annot){
 		TopTreebankNode tree = null;
-		FSIterator<Annotation> iter = jcas.getJFSIndexRepository().getAnnotationIndex(TopTreebankNode.type).iterator();
-		while(iter.hasNext()){
-			TopTreebankNode root = (TopTreebankNode) iter.next();
+//		FSIterator<Annotation> iter = jcas.getJFSIndexRepository().getAnnotationIndex(TopTreebankNode.type).iterator();
+		Collection<TopTreebankNode> roots = JCasUtil.select(jcas, TopTreebankNode.class);
+//		while(iter.hasNext()){
+		for(TopTreebankNode root : roots){
+//			TopTreebankNode root = (TopTreebankNode) iter.next();
 			if(root.getBegin() <= annot.getBegin() && root.getEnd() >= annot.getEnd()){
 				tree = root;
 				break;
 			}
 		}
+		if(tree == null){
+			System.err.println("Could not find a tree.");
+		}
 		return tree;
 	}
 
 	public static TopTreebankNode getTreeCopy(JCas jcas, TopTreebankNode orig){
+		if(orig == null) return null;
 		TopTreebankNode copy = new TopTreebankNode(jcas);
 		copy.setNodeType(orig.getNodeType());
 		copy.setBegin(orig.getBegin());
@@ -55,6 +64,7 @@ public class AnnotationTreeUtils {
 			System.err.println("WHAT?");
 		}
 		copy.setChildren(0, getTreeCopy(jcas, orig.getChildren(0)));
+		copy.getChildren(0).setParent(copy);
 		return copy;
 	}
 

Modified: ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java?rev=1471600&r1=1471599&r2=1471600&view=diff
==============================================================================
--- ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java
(original)
+++ ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java
Wed Apr 24 19:03:36 2013
@@ -80,9 +80,9 @@ public class TreeUtils {
 		}catch(Exception e){
 			System.err.println("Caught NPE");
 		}
-		if(pathTree.getChildren().size() == 1 && pathTree.getChildren(0).getLeaf()){
+		if(pathTree.getLeaf()){ //pathTree.getChildren().size() == 1 && pathTree.getChildren(0).getLeaf()){
 			buff.append(" ");
-			buff.append(pathTree.getChildren(0).getNodeType());
+			buff.append(pathTree.getNodeValue());
 //			buff.append(")");
 		}else{
 			for(int i = 0; i < pathTree.getChildren().size(); i++){



Mime
View raw message