You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2012/02/23 04:38:28 UTC
svn commit: r1292636 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
Author: colen
Date: Thu Feb 23 03:38:28 2012
New Revision: 1292636
URL: http://svn.apache.org/viewvc?rev=1292636&view=rev
Log:
OPENNLP-434: Implemented the create method.
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java?rev=1292636&r1=1292635&r2=1292636&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java Thu Feb 23 03:38:28 2012
@@ -17,6 +17,7 @@
package opennlp.tools.sentdetect;
+import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -125,9 +126,38 @@ public class SentenceDetectorFactory ext
public static SentenceDetectorFactory create(String subclassName,
String languageCode, boolean useTokenEnd,
- Dictionary abbreviationDictionary, char[] eosCharacters) {
- // TODO: implement
- return null;
+ Dictionary abbreviationDictionary, char[] eosCharacters)
+ throws InvalidFormatException {
+ if (subclassName == null) {
+ // will create the default factory
+ return new SentenceDetectorFactory(languageCode, useTokenEnd,
+ abbreviationDictionary, eosCharacters);
+ }
+ SentenceDetectorFactory theFactory = null;
+ Class<? extends BaseToolFactory> factoryClass = loadSubclass(subclassName);
+ if (factoryClass != null) {
+ try {
+ Constructor<?> constructor = null;
+ constructor = factoryClass.getConstructor(String.class, boolean.class,
+ Dictionary.class, char[].class);
+ theFactory = (SentenceDetectorFactory) constructor.newInstance(
+ languageCode, useTokenEnd, abbreviationDictionary, eosCharacters);
+ } catch (NoSuchMethodException e) {
+ String msg = "Could not instantiate the "
+ + subclassName
+ + ". The mandatory constructor (String, boolean, Dictionary, char[])) is missing.";
+ System.err.println(msg);
+ throw new IllegalArgumentException(msg);
+ } catch (Exception e) {
+ String msg = "Could not instantiate the "
+ + subclassName
+ + ". The constructor (String, boolean, Dictionary, char[]) throw an exception.";
+ System.err.println(msg);
+ e.printStackTrace();
+ throw new InvalidFormatException(msg);
+ }
+ }
+ return theFactory;
}
public char[] getEOSCharacters() {