Author: markg
Date: Sat Jan 18 20:00:17 2014
New Revision: 1559406
URL: http://svn.apache.org/r1559406
Log:
OPENNLP-638
Changed method to init and added throws Exception in EntityLinker inteface, added static generic type param to entitylinkerfactory. Also updated GeoEntityLinker.
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinker.java
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinker.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinker.java?rev=1559406&r1=1559405&r2=1559406&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinker.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinker.java Sat Jan 18 20:00:17 2014
@@ -26,20 +26,25 @@ import opennlp.tools.util.Span;
* Intended to return n best matches for any give search, but can also be
* implemented as deterministic
*
- * @param <T> A type that extends Span. LinkedSpan and BaseLink are provided to provide this signature:
- * EntityLinker<LinkedSpan<BaseLink>> as a default
- *
+ * @param <T> A type that extends Span. LinkedSpan and BaseLink are provided to
+ * provide this signature: EntityLinker<LinkedSpan<BaseLink>> as a
+ * default
+ * * @param <I> A type that extends EntityLinkerProperties. This enables
+ * passing external resources into an EntityLinker via the @link EtityLinkerFactory
*/
-public interface EntityLinker<T extends Span> {
+public interface EntityLinker<T extends Span, I extends EntityLinkerProperties> {
/**
* allows for passing properties through the EntityLinkerFactory into all
- * impls dynamically
+ * impls dynamically. EntityLinker impls should initialize reusable objects
+ * used by the impl in this method. If this is done, any errors will be
+ * captured and thrown by the EntityLinkerFactory.
*
- * @param properties the EntityLinkerProperties object that contains
- * properties needed by the impl
+ * @param initializationData the EntityLinkerProperties object that contains
+ * properties needed by the impl, as well as any
+ * other objects required for the impl
*/
- void setEntityLinkerProperties(EntityLinkerProperties properties);
+ void init(I initializationData) throws Exception;
/**
* Links an entire document of named entities to an external source
@@ -49,12 +54,51 @@ public interface EntityLinker<T extends
* text.
* @param tokensBySentence a list of tokens that correspond to each sentence.
* The outer array refers to the sentence, the inner
- * array is the tokens for the outer sentence. Similar in nature to Map<SentenceIndex,List<Tokens>>
- * @param namesBySentence a list of name spans that correspond to each
- * sentence. The outer array refers to the sentence,
- * the inner array refers to the tokens that for the
- * same sentence.Similar in nature to Map<SentenceIndex,List<Name Spans For This Sentence's Tokens>>
- * @return
+ * array is the tokens for the outer sentence. Similar
+ * in nature to Map<SentenceIndex,List<Tokens>> @param
+ * names
+ * B
+ * y Sentence
+ * a
+ * list
+ * of
+ * name
+ * spans
+ * that
+ * correspond
+ * to
+ * each
+ * sentence.
+ * The
+ * outer
+ * array
+ * refers
+ * to
+ * the
+ * sentence,
+ * the
+ * inner
+ * array
+ * refers
+ * to
+ * the
+ * tokens
+ * that
+ * for
+ * the
+ * same
+ * sentence.Similar
+ * in
+ * nature
+ * to
+ * Map<SentenceIndex,List<Name
+ * Spans
+ * For
+ * This
+ * Sentence's
+ * Tokens>>
+ * @
+ * return
*/
List<T> find(String doctext, Span[] sentences, String[][] tokensBySentence, Span[][] namesBySentence);
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java?rev=1559406&r1=1559405&r2=1559406&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/entitylinker/EntityLinkerFactory.java Sat Jan 18 20:00:17 2014
@@ -16,34 +16,37 @@
package opennlp.tools.entitylinker;
/**
- * Generates an EntityLinker implementation via properties file
- * configuration
+ * Generates an EntityLinker implementation via properties file configuration
*
*/
public class EntityLinkerFactory {
/**
- * instantiates a single linker based on properties file configuration.
- * @param entityType the type of entity, i.e. person, organization, location
- * @param properties the properties file that holds the configuration for entitylinkers.
- * @return
+ *
+ * @param <I> An type that extends EntityLinkerProperties.
+ * @param entityType The type of entity being linked to. This value is used to
+ * retrieve the implementation of the entitylinker from the
+ * entitylinker properties file.
+ * @param properties An object that extends EntityLinkerProperties. This
+ * object will be passed into the implemented EntityLinker
+ * init(..) within this getLinker method.
+ * @return an EntityLinker impl
*/
- public static synchronized EntityLinker getLinker(String entityType, EntityLinkerProperties properties) {
+ public static synchronized <I extends EntityLinkerProperties> EntityLinker getLinker(String entityType, I properties) {
if (entityType == null || properties == null) {
throw new IllegalArgumentException("Null argument in entityLinkerFactory");
}
EntityLinker linker = null;
try {
- String linkerImplFullName = properties.getProperty("linker." + entityType,"");
+ String linkerImplFullName = properties.getProperty("linker." + entityType, "");
Class theClass = Class.forName(linkerImplFullName);
linker = (EntityLinker) theClass.newInstance();
System.out.println("EntityLinker factory instantiated: " + linker.getClass().getName());
- linker.setEntityLinkerProperties(properties);
+ linker.init(properties);
} catch (Exception ex) {
- System.out.println("Check the entity linker properties file. The entry must be formatted as linker.<type>=<fullclassname>, i.e linker.person=org.my.company.MyPersonLinker\n" + ex);
- }
+ System.out.println("Error in EntityLinker factory. Check the entity linker properties file. The entry must be formatted as linker.<type>=<fullclassname>, i.e linker.person=org.my.company.MyPersonLinker\n" + ex);
+ }
return linker;
}
-
}