ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1615936 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java
Date Tue, 05 Aug 2014 14:41:57 GMT
Author: clin
Date: Tue Aug  5 14:41:57 2014
New Revision: 1615936

URL: http://svn.apache.org/r1615936
Log:
add method to get the common ancestor

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java?rev=1615936&r1=1615935&r2=1615936&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DependencyParseUtils.java
Tue Aug  5 14:41:57 2014
@@ -63,6 +63,29 @@ public class DependencyParseUtils {
     paths.add(node2ToHeadPath);
 
     return paths;
+  }
+  
+  /**
+   * Returns the common ancestor between them
+   */
+  public static ConllDependencyNode getCommonAncestor(ConllDependencyNode node1, ConllDependencyNode
node2) {
+
+    LinkedList<ConllDependencyNode> node1ToHeadPath = DependencyParseUtils.getPathToSentenceHead(node1);
+    LinkedList<ConllDependencyNode> node2ToHeadPath = DependencyParseUtils.getPathToSentenceHead(node2);
+
+    // We will remove the last item in each path until they diverge
+    ConllDependencyNode ancestor = null;
+    while (!node1ToHeadPath.isEmpty() && !node2ToHeadPath.isEmpty()) {
+      if (node1ToHeadPath.getLast() == node2ToHeadPath.getLast()) {
+        node1ToHeadPath.removeLast();
+        ancestor = node2ToHeadPath.removeLast();
+      } else {
+        break;
+      }
+    }
+
+    //Return the common ancestor
+    return ancestor;
   }
 
   /**



Mime
View raw message