Revision: 15135
          http://gate.svn.sourceforge.net/gate/?rev=15135&view=rev
Author:   valyt
Date:     2012-01-19 15:52:00 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
The framework is basically there. Next we'll need some actual rules implemented.

Modified Paths:
--------------
    futures/orthoref/src/gate/creole/coref/CorefBase.java

Added Paths:
-----------
    futures/orthoref/build.xml
    futures/orthoref/creole.xml
    futures/orthoref/src/gate/creole/coref/Matcher.java
    futures/orthoref/src/gate/creole/coref/OrthoRef.java
    futures/orthoref/src/gate/creole/coref/Tagger.java

Added: futures/orthoref/build.xml
===================================================================
--- futures/orthoref/build.xml                          (rev 0)
+++ futures/orthoref/build.xml  2012-01-19 15:52:00 UTC (rev 15135)
@@ -0,0 +1,97 @@
+<project name="OrthoRef" basedir="." default="build" >
+  <property file="build.properties" />
+
+  <!-- Make environment variables available -->
+  <property environment="env" />
+
+  <!-- If environment variable GATE_HOME is set, use it for
+       gate.home (unless it was already set in build.properties -->
+  <condition property="gate.home" value="${env.GATE_HOME}">
+    <isset property="env.GATE_HOME"/>
+  </condition>
+
+  <!-- If gate.home is not set from build.properties or the 
+       environment variable GATE_HOME, assume that this
+       plugin is in GATE Developer's plugin directory -->
+  <property name="gate.home" location="../.." />
+  <property name="src.dir" location="src" />
+  <property name="classes.dir" location="classes" />
+  <property name="lib.dir" location="lib" />
+       <property name="doc.dir" location="doc" />
+  <property name="javadoc.dir" location="${doc.dir}/javadoc" />
+  <property name="jar.location" location="orthoref.jar" />
+       <property name="plugin.name" value="OrthoRef" />
+       
+
+  <!-- Path to compile - includes gate.jar and GATE/lib/*.jar -->
+  <path id="compile.classpath">
+    <pathelement location="${lib.dir}/*.jar" />
+    <pathelement location="${gate.home}/bin/gate.jar" />
+    <fileset dir="${gate.home}/lib">
+      <include name="**/*.jar" />
+      <include name="**/*.zip" />
+    </fileset>
+  </path>
+
+  <!-- create build directory structure -->
+  <target name="prepare">
+    <mkdir dir="${classes.dir}" />
+  </target>
+
+  <!-- compile the source -->
+  <target name="compile" depends="prepare">
+    <javac classpathref="compile.classpath"
+           srcdir="${src.dir}"
+           destdir="${classes.dir}"
+           debug="true"
+           debuglevel="lines,source"
+           encoding="UTF-8"
+           source="1.5" target="1.5" />
+  </target>
+
+  <!-- create the JAR file -->
+  <target name="jar" depends="compile" >
+    <jar destfile="${jar.location}"
+         update="false"
+         basedir="${classes.dir}" />
+  </target>
+
+  <!-- remove the generated .class files -->
+  <target name="clean.classes" >
+    <delete dir="${classes.dir}" />
+  </target>
+
+  <!-- Clean up - remove .class and .jar files -->
+  <target name="clean" depends="clean.classes" >
+    <delete file="${jar.location}" />
+  </target>
+
+  <!-- Build JavaDoc documentation -->
+  <target name="doc.prepare">
+    <mkdir dir="${javadoc.dir}" />
+  </target>
+
+  <target name="javadoc" depends="doc.prepare">
+    <javadoc destdir="${javadoc.dir}" packagenames="*"
+             classpathref="compile.classpath"
+             encoding="UTF-8"
+             windowtitle="${plugin.name} JavaDoc"
+             source="1.5">
+      <sourcepath>
+        <pathelement location="${src.dir}" />
+      </sourcepath>
+      <link href="http://java.sun.com/j2se/1.6.0/docs/api/"; />
+      <link href="http://gate.ac.uk/gate/doc/javadoc/"; />
+    </javadoc>
+  </target>
+       
+  <!-- Targets used by the main GATE build file:
+         build: build the plugin - just calls "jar" target
+         test : run the unit tests - there aren't any
+         distro.prepare: remove intermediate files that shouldn't be in the
+                         distribution
+  -->
+  <target name="build" depends="jar" />
+  <target name="test" />
+  <target name="distro.prepare" depends="clean.classes" />
+</project>


Property changes on: futures/orthoref/build.xml
___________________________________________________________________
Added: svn:eol-style
   + native

Added: futures/orthoref/creole.xml
===================================================================
--- futures/orthoref/creole.xml                         (rev 0)
+++ futures/orthoref/creole.xml 2012-01-19 15:52:00 UTC (rev 15135)
@@ -0,0 +1,3 @@
+<CREOLE-DIRECTORY>
+  <JAR SCAN="true">orthoref.jar</JAR>
+</CREOLE-DIRECTORY>

Modified: futures/orthoref/src/gate/creole/coref/CorefBase.java
===================================================================
--- futures/orthoref/src/gate/creole/coref/CorefBase.java       2012-01-19 
12:21:27 UTC (rev 15134)
+++ futures/orthoref/src/gate/creole/coref/CorefBase.java       2012-01-19 
15:52:00 UTC (rev 15135)
@@ -1,7 +1,7 @@
 /*
  *  OrthoRef.java
  *
- *  Copyright (c) 1995-2010, The University of Sheffield. See the file
+ *  Copyright (c) 1995-2012, The University of Sheffield. See the file
  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
  *
  *  This file is part of GATE (see http://gate.ac.uk/), and is free
@@ -9,6 +9,8 @@
  *  Version 2, June 1991 (in the distribution as file licence.html,
  *  and also available at http://gate.ac.uk/gate/licence.html).
  *
+ *  Valentin Tablan 18 Jan 2012
+ *  
  *  $Id$
  */
 package gate.creole.coref;
@@ -16,17 +18,24 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import gate.Annotation;
+import gate.Gate;
+import gate.Resource;
 import gate.Utils;
 import gate.creole.AbstractLanguageAnalyser;
 import gate.creole.ExecutionException;
+import gate.creole.ResourceInstantiationException;
+import gate.creole.metadata.CreoleParameter;
 import gate.creole.metadata.CreoleResource;
+import gate.creole.metadata.RunTime;
 
-@CreoleResource (comment = "An orthographic coreferencer")
+@CreoleResource
 /**
  * Base class for coreferencers. This class has no internal state, so it safe 
to
  * use in a multi-threaded environment. The same may not be true about 
@@ -35,17 +44,171 @@
 public abstract class CorefBase extends AbstractLanguageAnalyser {
   
   /**
+   * 
+   */
+  private static final long serialVersionUID = -4069411446200124751L;
+
+  /**
    * Which annotation types are seen as anaphors
    */
   private Set<String> anaphorAnnotationTypes;
   
   private String annotationSetName;
   
-  public abstract Set<String> anaphorTags(Annotation anaphor);
+  private List<Tagger> taggers;
   
-  public abstract boolean matches(Annotation anaphor, Annotation antecedent);
+  private List<Matcher> matchers;
+  
+  private List<String> packageNames;
 
+  private List<String> taggerClassNames;
+  
+  private List<String> matcherClassNames;
+  
+  
+  public List<String> getPackageNames() {
+    return packageNames;
+  }
+
+  @CreoleParameter (defaultValue = "gate.creole.coref",
+      comment="<html>Java <b>packages</b> that should be searched for Tagger " 
+
+               "and Matcher implementations.</html>")
+  public void setPackageNames(List<String> packageNames) {
+    this.packageNames = packageNames;
+  }
+
+  public List<String> getTaggerClassNames() {
+    return taggerClassNames;
+  }
+  
+  @CreoleParameter (comment =
+      "<html>List of <b>class names</b< of Tagger implementations that " +
+      "should be instantiated and used.<br>" +
+      "Non fully-qualified names will be searched for in the provided " +
+      "package names.</html>")
+  public void setTaggerClassNames(List<String> taggerClassNames) {
+    this.taggerClassNames = taggerClassNames;
+  }
+
+  public List<String> getMatcherClassNames() {
+    return matcherClassNames;
+  }
+
+  @CreoleParameter (comment =
+      "<html>List of <b>class names</b> of Matcher implementations that " +
+      "should be instantiated and used.<br>" +
+      "Non fully-qualified names will be searched for in the provided " +
+      "package names.</html>")
+  public void setMatcherClassNames(List<String> matcherClassNames) {
+    this.matcherClassNames = matcherClassNames;
+  }
+  
+  public Set<String> getAnaphorAnnotationTypes() {
+    return anaphorAnnotationTypes;
+  }
+
+  @CreoleParameter(comment = "Annotation types that should be considered", 
+      defaultValue = "Person;Location;Organization")
+  @RunTime
+  public void setAnaphorAnnotationTypes(Set<String> anaphorAnnotationTypes) {
+    this.anaphorAnnotationTypes = anaphorAnnotationTypes;
+  }
+
+  public String getAnnotationSetName() {
+    return annotationSetName;
+  }
+
+  @CreoleParameter(comment="The name of the annotation set to be processed", 
+      defaultValue="")
+  @RunTime
+  public void setAnnotationSetName(String annotationSetName) {
+    this.annotationSetName = annotationSetName;
+  }
+
   @Override
+  public Resource init() throws ResourceInstantiationException {
+    if(packageNames == null) packageNames = Collections.EMPTY_LIST;
+    if(taggerClassNames == null) throw new ResourceInstantiationException(
+      "No tagger class names provided!");
+    if(matcherClassNames == null) throw new ResourceInstantiationException(
+        "No matcher class names provided!");
+    // create the list of taggers
+    taggers = new LinkedList<Tagger>();
+    for(String taggerClassName : taggerClassNames) {
+      Class<Tagger> taggerClass = null;
+      if(taggerClassName.indexOf('.') >= 0) {
+        // fully qualified name
+        try {
+          taggerClass = (Class<Tagger>)Class.forName(taggerClassName, true, 
+              Gate.getClassLoader());
+        } catch(ClassNotFoundException e) {
+          throw new ResourceInstantiationException(e);
+        }        
+      } else {
+        // search packages
+        for(String packageName : packageNames) {
+          try {
+            taggerClass = (Class<Tagger>)Class.forName(
+              packageName + "." + taggerClassName, true, 
Gate.getClassLoader());
+            break;
+          } catch(ClassNotFoundException e) {
+            // ignore
+          }
+        }
+      }
+      if(taggerClass == null) {
+        throw new ResourceInstantiationException(
+          "Could not find class for tagger class name \"" + taggerClassName + 
+          "\".");
+      }
+      // create an instance
+      try {
+        taggers.add(taggerClass.newInstance());
+      } catch(Exception e) {
+        throw new ResourceInstantiationException(e);
+      } 
+    }
+    
+    // create the list of matchers
+    matchers = new LinkedList<Matcher>();
+    for(String matcherClassName : matcherClassNames) {
+      Class<Matcher> matcherClass = null;
+      if(matcherClassName.indexOf('.') >= 0) {
+        // fully qualified name
+        try {
+          matcherClass = (Class<Matcher>)Class.forName(matcherClassName, true, 
+              Gate.getClassLoader());
+        } catch(ClassNotFoundException e) {
+          throw new ResourceInstantiationException(e);
+        }        
+      } else {
+        // search packages
+        for(String packageName : packageNames) {
+          try {
+            matcherClass = (Class<Matcher>)Class.forName(
+              packageName + "." + matcherClassName, true, 
Gate.getClassLoader());
+            break;
+          } catch(ClassNotFoundException e) {
+            // ignore
+          }
+        }
+      }
+      if(matcherClass == null) {
+        throw new ResourceInstantiationException(
+          "Could not find class for matcher class name \"" + matcherClassName 
+ 
+          "\".");
+      }
+      // create an instance
+      try {
+        matchers.add(matcherClass.newInstance());
+      } catch(Exception e) {
+        throw new ResourceInstantiationException(e);
+      } 
+    }
+    return super.init();
+  }
+
+  @Override
   public void execute() throws ExecutionException {
     fireProgressChanged(1);
     //collect all candidates
@@ -55,27 +218,47 @@
         
document.getAnnotations(annotationSetName)).get(anaphorAnnotationTypes));
     Collections.sort(anaphors, Utils.OFFSET_COMPARATOR);
     
-    Map<String, Annotation> tag2candidate = new HashMap<String, Annotation>();
-    Map<Annotation, String> anaphor2chain = new HashMap<Annotation, String>();
+    Map<String, Integer> tag2antecedent = new HashMap<String, Integer>();
+    Map<Integer, String> anaphor2chain = new HashMap<Integer, String>();
+    Map<String, List<Annotation>> chain2anaphors = 
+        new HashMap<String, List<Annotation>>();
     
     // for each candidate, check the hash map 
-    for(Annotation anaphor : anaphors) {
-      Set<String> newTags = anaphorTags(anaphor);
+    for(int anaphorIdx = 0; anaphorIdx < anaphors.size(); anaphorIdx++) {
+      Set<String> newTags = new HashSet<String>();
+      for(Tagger tagger : taggers){
+        newTags.addAll(tagger.tags(anaphors, anaphorIdx));
+      }
       for(String tag : newTags) {
-        Annotation candidate = tag2candidate.get(tag);
-        if(candidate != null && matches(anaphor, candidate)) {
-          // we have a match
-          String chainLabel  = anaphor2chain.get(candidate);
-          if(chainLabel == null) {
-            // first match for this chain
-            chainLabel = Utils.contentFor(document, candidate).toString();
-            anaphor2chain.put(candidate, chainLabel);
+        Integer candidateIdx = tag2antecedent.get(tag);
+        if(candidateIdx != null) {
+          for(Matcher matcher : matchers) {
+            if(matcher.matches(anaphors, candidateIdx, anaphorIdx)) {
+              // we have a match
+              String chainLabel  = anaphor2chain.get(candidateIdx);
+              if(chainLabel == null) {
+                // first match for this chain
+                chainLabel = Utils.contentFor(document, 
+                    anaphors.get(candidateIdx)).toString();
+                anaphor2chain.put(candidateIdx, chainLabel);
+              }
+              anaphor2chain.put(anaphorIdx, chainLabel);
+              List<Annotation> chain = chain2anaphors.get(chainLabel);
+              if(chain == null) {
+                chain = new LinkedList<Annotation>();
+                chain2anaphors.put(chainLabel, chain);
+              }
+              chain.add(anaphors.get(anaphorIdx));
+              // no need to look for more
+              break; 
+            }
           }
-          anaphor2chain.put(anaphor, chainLabel);
         }
       }
     }
     
+    // create the annotation features
+    //TODO
     
     
     

Added: futures/orthoref/src/gate/creole/coref/Matcher.java
===================================================================
--- futures/orthoref/src/gate/creole/coref/Matcher.java                         
(rev 0)
+++ futures/orthoref/src/gate/creole/coref/Matcher.java 2012-01-19 15:52:00 UTC 
(rev 15135)
@@ -0,0 +1,26 @@
+/*
+ *  AnaphorMatcher.java
+ *
+ *  Copyright (c) 1995-2012, The University of Sheffield. See the file
+ *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 2, June 1991 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ *  Valentin Tablan 19 Jan 2012
+ *  
+ *  $Id$
+ */
+package gate.creole.coref;
+
+import gate.Annotation;
+
+import java.util.List;
+
+public interface Matcher {
+  
+  public boolean matches(List<Annotation> anaphors, int antecedent, 
+                                  int anaphor);
+}


Property changes on: futures/orthoref/src/gate/creole/coref/Matcher.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: futures/orthoref/src/gate/creole/coref/OrthoRef.java
===================================================================
--- futures/orthoref/src/gate/creole/coref/OrthoRef.java                        
        (rev 0)
+++ futures/orthoref/src/gate/creole/coref/OrthoRef.java        2012-01-19 
15:52:00 UTC (rev 15135)
@@ -0,0 +1,28 @@
+package gate.creole.coref;
+
+import gate.creole.metadata.CreoleParameter;
+import gate.creole.metadata.CreoleResource;
+
+import java.util.List;
+
+@CreoleResource (name="OrthoRef", comment = "An orthographic coreferencer")
+public class OrthoRef extends CorefBase {
+
+  /**
+   * 
+   */
+  private static final long serialVersionUID = -1723494592444418868L;
+
+  @Override
+  @CreoleParameter(defaultValue="tagger1;tagger2")
+  public void setTaggerClassNames(List<String> taggerClassNames) {
+    super.setTaggerClassNames(taggerClassNames);
+  }
+
+  @Override
+  @CreoleParameter(defaultValue="matcher1;matcher2")
+  public void setMatcherClassNames(List<String> matcherClassNames) {
+    super.setMatcherClassNames(matcherClassNames);
+  }
+  
+}


Property changes on: futures/orthoref/src/gate/creole/coref/OrthoRef.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: futures/orthoref/src/gate/creole/coref/Tagger.java
===================================================================
--- futures/orthoref/src/gate/creole/coref/Tagger.java                          
(rev 0)
+++ futures/orthoref/src/gate/creole/coref/Tagger.java  2012-01-19 15:52:00 UTC 
(rev 15135)
@@ -0,0 +1,27 @@
+/*
+ *  AnaphorTagger.java
+ *
+ *  Copyright (c) 1995-2012, The University of Sheffield. See the file
+ *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 2, June 1991 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ *  Valentin Tablan 19 Jan 2012
+ *  
+ *  $Id$
+ */
+package gate.creole.coref;
+
+import gate.Annotation;
+
+import java.util.List;
+import java.util.Set;
+
+public interface Tagger {
+  
+  public Set<String> tags(List<Annotation> anaphors, int anaphor);
+  
+}


Property changes on: futures/orthoref/src/gate/creole/coref/Tagger.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to