incubator-ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1414879 - /incubator/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/util/TreeUtils.java
Date Wed, 28 Nov 2012 19:43:58 GMT
Author: tmill
Date: Wed Nov 28 19:43:57 2012
New Revision: 1414879

URL: http://svn.apache.org/viewvc?rev=1414879&view=rev
Log:
jira issue ctakes-110 - new methods in TreeUtils for manipulating constituency parser data
structures.
containsIgnoreCase - generalizes contains() to ignore case - useful for lexicalized trees
getTopNode - get the top node for any node in a tree

Modified:
    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/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=1414879&r1=1414878&r2=1414879&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
Wed Nov 28 19:43:57 2012
@@ -21,6 +21,7 @@ package org.apache.ctakes.constituency.p
 import opennlp.tools.parser.Parse;
 
 
+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.apache.ctakes.utils.tree.SimpleTree;
@@ -104,27 +105,57 @@ public class TreeUtils {
 //		return same;
 //	}
 	
+	public static boolean containsIgnoreCase(SimpleTree node, SimpleTree frag){
+		return contains(node, frag, true);
+	}
+
 	public static boolean contains(SimpleTree node, SimpleTree frag){
-		if(fragmentMatch(node,frag)) return true;
-		
+		return contains(node, frag, false);
+	}
+
+	public static boolean contains(SimpleTree node, SimpleTree frag, boolean ignoreCase){
+		if(fragmentMatch(node,frag, ignoreCase)) return true;
+
 		for(int i = 0; i < node.children.size(); i++){
-			if(contains(node.children.get(i), frag)) return true;
+			if(contains(node.children.get(i), frag, ignoreCase)) return true;
 		}
 		return false;
 	}
 
-	private static boolean fragmentMatch(SimpleTree node, SimpleTree frag){
+	private static boolean fragmentMatch(SimpleTree node, SimpleTree frag, boolean ignoreCase){
 		boolean same = false;
-		if(node.cat.equals(frag.cat) && (frag.children.size() == 0 || node.children.size()
== frag.children.size())){
-			same = true;
-			for(int i = 0; i < frag.children.size(); i++){
-				if(!fragmentMatch(node.children.get(i), frag.children.get(i))){
-					same = false;
-					break;
+		if((ignoreCase && node.cat.equalsIgnoreCase(frag.cat)) || (!ignoreCase &&
node.cat.equals(frag.cat))){
+			if((frag.children.size() == 0 || node.children.size() == frag.children.size())){
+
+				same = true;
+				for(int i = 0; i < frag.children.size(); i++){
+					if(!fragmentMatch(node.children.get(i), frag.children.get(i), ignoreCase)){
+						same = false;
+						break;
+					}
 				}
 			}
 		}
 		return same;
 	}
+
+	private static int getHighestIndexTerm(TreebankNode inTree) {
+		if(inTree instanceof TerminalTreebankNode){
+			return ((TerminalTreebankNode) inTree).getIndex();
+		}else{
+			return getHighestIndexTerm(inTree.getChildren(inTree.getChildren().size()-1));
+		}
+	}
+
+	public static TopTreebankNode getTopNode(TreebankNode inTree) {
+		TreebankNode cur = inTree;
+		TopTreebankNode top = null;
+		
+		while(!(cur instanceof TopTreebankNode)){
+			cur = cur.getParent();
+		}
+		top = (TopTreebankNode) cur;
+		return top;
+	}
 }
 



Mime
View raw message