ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1511873 - /ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java
Date Thu, 08 Aug 2013 16:59:30 GMT
Author: tmill
Date: Thu Aug  8 16:59:29 2013
New Revision: 1511873

URL: http://svn.apache.org/r1511873
Log:
Added public method which does manipulations on list elements in trees.

Modified:
    ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java

Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java?rev=1511873&r1=1511872&r2=1511873&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java
(original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/util/AssertionTreeUtils.java
Thu Aug  8 16:59:29 2013
@@ -11,6 +11,7 @@ import org.apache.ctakes.typesystem.type
 import org.apache.ctakes.typesystem.type.syntax.TreebankNode;
 import org.apache.ctakes.utils.tree.SimpleTree;
 import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.cas.FSArray;
 import org.apache.uima.jcas.tcas.Annotation;
 
 public class AssertionTreeUtils {
@@ -27,6 +28,8 @@ public class AssertionTreeUtils {
 				node =  node.getParent();
 			}
 
+//	    elevateListConcepts(jcas, node);
+	    
 			// remove nodes to the right of the CONCEPT node
 			AnnotationTreeUtils.removeRightOfAnnotation(jcas, node, conceptNode);
 			
@@ -39,10 +42,62 @@ public class AssertionTreeUtils {
 		if(sems != null){
 			replaceWordsWithSemanticClasses(tree, sems);
 		}
+		
 		return tree;
 	}
 	
-	public static SimpleTree extractAboveRightConceptTree(JCas jcas, Annotation mention, SemanticClasses
sems){
+	public static void elevateListConcepts(JCas jcas, TreebankNode tree) {
+	  if(tree.getLeaf()) return;
+	  
+	  int conceptIndex = -1;
+	  for(int i = 0; i < tree.getChildren().size(); i++){
+	    if(tree.getChildren(i).getNodeType().equals("CONCEPT")){
+	      conceptIndex = i;
+	      break;
+	    }
+	  }
+	  
+	  if(conceptIndex == -1){
+	    // explore children
+//	    for(SimpleTree child : tree.children){
+	    for(int i = 0; i < tree.getChildren().size(); i++){
+	      elevateListConcepts(jcas, tree.getChildren(i));
+	    }
+	  }else{
+	    // check 3 conditions:
+	    // 1) First node under tree, with at least one node to the right, with category CC or
,
+	    // 2) last node under tree, with at least one node to the left, with category CC or
,
+	    // 3) node in the middle with node to the left category , and node to the right category
CC or ,
+	    if(conceptIndex == 0 && tree.getChildren().size() > 1 && tree.getChildren(1).getNodeType().matches("CC|,")
+	        || conceptIndex == tree.getChildren().size()-1 && tree.getChildren().size()
> 1 && tree.getChildren(conceptIndex-1).getNodeType().matches("CC|,") 
+	        || conceptIndex > 0 && conceptIndex < tree.getChildren().size()-1
&& tree.getChildren().size() > 2 && tree.getChildren(conceptIndex-1).getNodeType().equals(",")
&& tree.getChildren(conceptIndex+1).getNodeType().matches("CC|,")){
+	      // if we meet this simple condition we raise the CONCEPT node!
+	      // remove old concept node:
+	      TreebankNode entityRoot = tree.getChildren(conceptIndex).getChildren(0);
+	      tree.setChildren(conceptIndex, entityRoot);
+	      entityRoot.setParent(tree);
+	      
+	      // insert new concept node:
+//	      SimpleTree replacementNode = new SimpleTree(tree.cat);
+	      TreebankNode replacementNode = new TreebankNode(jcas);
+	      replacementNode.setNodeType(tree.getNodeType());
+	      replacementNode.setChildren(tree.getChildren());
+	      for(int i = 0; i < replacementNode.getChildren().size(); i++){
+	        replacementNode.getChildren(i).setParent(replacementNode);
+	      }
+	      replacementNode.setParent(tree);
+	      
+	      tree.setNodeType("CONCEPT");
+//	      tree.children = new ArrayList<SimpleTree>();
+	      FSArray children = new FSArray(jcas, 1);
+	      children.set(0, replacementNode);
+	      tree.setChildren(children);
+//	      tree.addChild(replacementNode);
+	    }
+	  }
+  }
+
+  public static SimpleTree extractAboveRightConceptTree(JCas jcas, Annotation mention, SemanticClasses
sems){
 		SimpleTree tree = null;
 		TopTreebankNode annotationTree = AnnotationTreeUtils.getAnnotationTree(jcas, mention);
 		if(annotationTree != null){



Mime
View raw message