ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1801587 - in /ctakes/trunk/ctakes-dependency-parser/src: main/java/org/apache/ctakes/dependency/parser/ae/ main/java/org/apache/ctakes/dependency/parser/ae/shared/ test/java/org/apache/ctakes/dependency/parser/ae/util/
Date Tue, 11 Jul 2017 10:12:28 GMT
Author: tmill
Date: Tue Jul 11 10:12:28 2017
New Revision: 1801587

URL: http://svn.apache.org/viewvc?rev=1801587&view=rev
Log:
Refactored dependency parser and srl models to use external resources; now possible to thread
or use multiple components.

Added:
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/DependencySharedModel.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/LemmatizerSharedModel.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedModel.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedParserModel.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedPredictionModel.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedRoleModel.java
Modified:
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPDependencyParserAE.java
    ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPSemanticRoleLabelerAE.java
    ctakes/trunk/ctakes-dependency-parser/src/test/java/org/apache/ctakes/dependency/parser/ae/util/TestClearNLPAnalysisEngines.java

Modified: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPDependencyParserAE.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPDependencyParserAE.java?rev=1801587&r1=1801586&r2=1801587&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPDependencyParserAE.java
(original)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPDependencyParserAE.java
Tue Jul 11 10:12:28 2017
@@ -18,16 +18,12 @@
  */
 package org.apache.ctakes.dependency.parser.ae;
 
-import com.googlecode.clearnlp.component.AbstractComponent;
-import com.googlecode.clearnlp.dependency.DEPFeat;
-import com.googlecode.clearnlp.dependency.DEPNode;
-import com.googlecode.clearnlp.dependency.DEPTree;
-import com.googlecode.clearnlp.engine.EngineGetter;
-import com.googlecode.clearnlp.morphology.AbstractMPAnalyzer;
-import com.googlecode.clearnlp.nlp.NLPLib;
-import com.googlecode.clearnlp.reader.AbstractReader;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.ctakes.core.pipeline.PipeBitInfo;
-import org.apache.ctakes.core.resource.FileLocator;
+import org.apache.ctakes.dependency.parser.ae.shared.DependencySharedModel;
+import org.apache.ctakes.dependency.parser.ae.shared.LemmatizerSharedModel;
 import org.apache.ctakes.dependency.parser.util.ClearDependencyUtility;
 import org.apache.ctakes.dependency.parser.util.DependencyUtility;
 import org.apache.ctakes.typesystem.type.syntax.BaseToken;
@@ -40,16 +36,21 @@ import org.apache.uima.analysis_engine.A
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
 import org.apache.uima.fit.descriptor.ConfigurationParameter;
+import org.apache.uima.fit.descriptor.ExternalResource;
 import org.apache.uima.fit.descriptor.TypeCapability;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.fit.factory.ExternalResourceFactory;
 import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ExternalResourceDescription;
 import org.apache.uima.resource.ResourceInitializationException;
 
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
+import com.googlecode.clearnlp.component.AbstractComponent;
+import com.googlecode.clearnlp.dependency.DEPFeat;
+import com.googlecode.clearnlp.dependency.DEPNode;
+import com.googlecode.clearnlp.dependency.DEPTree;
+import com.googlecode.clearnlp.morphology.AbstractMPAnalyzer;
+import com.googlecode.clearnlp.reader.AbstractReader;
 
 /**
  * <br>
@@ -86,30 +87,10 @@ public class ClearNLPDependencyParserAE
   final String language = AbstractReader.LANG_EN;
   public Logger logger = Logger.getLogger(getClass().getName());
 
-  // Default model values
-  public static final String DEFAULT_MODEL_FILE_NAME = "org/apache/ctakes/dependency/parser/models/dependency/mayo-en-dep-1.3.0.jar";
-  public static final String ENG_LEMMATIZER_DATA_FILE = "org/apache/ctakes/dependency/parser/models/lemmatizer/dictionary-1.3.1.jar";
-
-
-  // Configuration Parameters 
-  public static final String PARAM_PARSER_MODEL_FILE_NAME = "ParserModelFileName";
-  @ConfigurationParameter(
-		  name = PARAM_PARSER_MODEL_FILE_NAME,
-		  description = "This parameter provides the file name of the dependency parser model required
" +
-					      "by the factory method provided by ClearNLPUtil.  If not specified, this " +
-					      "analysis engine will use a default model from the resources directory",
-		  defaultValue = DEFAULT_MODEL_FILE_NAME)
-  protected URI parserModelUri;
-
-  public static final String PARAM_LEMMATIZER_DATA_FILE = "LemmatizerDataFile";
-
-  @ConfigurationParameter(
-      name = PARAM_LEMMATIZER_DATA_FILE,
-      description = "This parameter provides the data file required for the MorphEnAnalyzer.
If not "
-          + "specified, this analysis engine will use a default model from the resources
directory",
-      defaultValue = ENG_LEMMATIZER_DATA_FILE)
-  protected URI lemmatizerDataFile;
-
+  // single class-based model:
+  private static ExternalResourceDescription defaultParserResource = null;
+  private static ExternalResourceDescription defaultLemmatizerResource = null;
+  
 	public static final String PARAM_USE_LEMMATIZER = "UseLemmatizer";
 	@ConfigurationParameter(
 			name = PARAM_USE_LEMMATIZER,
@@ -117,37 +98,28 @@ public class ClearNLPDependencyParserAE
 			description = "If true, use the default ClearNLP lemmatizer, otherwise use lemmas from
the BaseToken normalizedToken field")
 	protected boolean useLemmatizer;
 
-
-	protected AbstractComponent parser;
-	protected AbstractMPAnalyzer lemmatizer;
-	//protected boolean useLemmatizer = false;
+  public static final String DEP_MODEL_KEY = "DepModel";
+  @ExternalResource(key = DEP_MODEL_KEY)
+  private DependencySharedModel parserModel;
+  
+  public static final String LEM_MODEL_KEY = "LemmatizerModel";
+  @ExternalResource(key = LEM_MODEL_KEY)
+  private LemmatizerSharedModel lemmatizerModel;
+  
+	protected AbstractComponent parser=null;
+	protected AbstractMPAnalyzer lemmatizer=null;
 
 	@Override
 	public void initialize(UimaContext context) throws ResourceInitializationException {
 		super.initialize(context);
+		logger.info("Initializing ClearNLP dependency parser with lemmatizer=" + useLemmatizer);
 
-		logger.info("using Morphy analysis? " + useLemmatizer);
-
-		try {
-			if (useLemmatizer) {
-				// Note: If lemmatizer data file is not specified, then use lemmas from the BaseToken
normalizedToken field.
-				// Initialize lemmatizer
-				
-                InputStream lemmatizerModel = (this.lemmatizerDataFile == null)
-                        ? FileLocator.getAsStream(ENG_LEMMATIZER_DATA_FILE)
-                        : FileLocator.getAsStream(this.lemmatizerDataFile.getPath());
-                        
-                    this.lemmatizer = EngineGetter.getMPAnalyzer(language, lemmatizerModel);
-			}
-				InputStream parserModel = (this.parserModelUri == null)
-                    ? FileLocator.getAsStream(DEFAULT_MODEL_FILE_NAME)
-                    : FileLocator.getAsStream(this.parserModelUri.getPath());
-                 
-                    this.parser = EngineGetter.getComponent(parserModel, this.language, NLPLib.MODE_DEP);
-
-        } catch (Exception e) {
-            throw new ResourceInitializationException(e);
-        }
+		if (useLemmatizer) {
+		  // Note: If lemmatizer data file is not specified, then use lemmas from the BaseToken
normalizedToken field.
+		  // Initialize lemmatizer
+		  this.lemmatizer = lemmatizerModel.getLemmatizerModel();
+		}
+		this.parser = parserModel.getParser();
 	}
 
 	@Override
@@ -178,11 +150,29 @@ public class ClearNLPDependencyParserAE
 			ArrayList<ConllDependencyNode> nodes = ClearDependencyUtility.convert( jCas, tree,
sentence, printableTokens );
 			DependencyUtility.addToIndexes( jCas, nodes );
 		}
-		
-		
 	}
 	
+	// If someone calls this, they want the default model, lazy initialization of the external
resources:
 	public static AnalysisEngineDescription createAnnotatorDescription() throws ResourceInitializationException{
-	  return AnalysisEngineFactory.createEngineDescription(ClearNLPDependencyParserAE.class);
+	  if(defaultParserResource == null){
+	    defaultParserResource = ExternalResourceFactory.createExternalResourceDescription(
+	        DependencySharedModel.class,
+	        DependencySharedModel.DEFAULT_MODEL_FILE_NAME);
+	  }
+	  if(defaultLemmatizerResource == null){
+	    defaultLemmatizerResource = ExternalResourceFactory.createExternalResourceDescription(
+	        LemmatizerSharedModel.class, 
+	        LemmatizerSharedModel.ENG_LEMMATIZER_DATA_FILE);
+	  }
+	  return createAnnotatorDescription(defaultParserResource, defaultLemmatizerResource);
+	}
+	
+	public static AnalysisEngineDescription createAnnotatorDescription(ExternalResourceDescription
parserDesc, ExternalResourceDescription lemmaDesc) throws ResourceInitializationException{
+	  return AnalysisEngineFactory.createEngineDescription(
+	      ClearNLPDependencyParserAE.class, 
+	      DEP_MODEL_KEY, 
+	      parserDesc, 
+	      LEM_MODEL_KEY, 
+	      lemmaDesc);
 	}
 }

Modified: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPSemanticRoleLabelerAE.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPSemanticRoleLabelerAE.java?rev=1801587&r1=1801586&r2=1801587&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPSemanticRoleLabelerAE.java
(original)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/ClearNLPSemanticRoleLabelerAE.java
Tue Jul 11 10:12:28 2017
@@ -18,14 +18,16 @@
  */
 package org.apache.ctakes.dependency.parser.ae;
 
-import com.googlecode.clearnlp.component.AbstractComponent;
-import com.googlecode.clearnlp.dependency.*;
-import com.googlecode.clearnlp.engine.EngineGetter;
-import com.googlecode.clearnlp.nlp.NLPLib;
-import com.googlecode.clearnlp.reader.AbstractReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.ctakes.core.pipeline.PipeBitInfo;
-import org.apache.ctakes.core.resource.FileLocator;
 import org.apache.ctakes.core.util.ListFactory;
+import org.apache.ctakes.dependency.parser.ae.shared.SRLSharedParserModel;
+import org.apache.ctakes.dependency.parser.ae.shared.SRLSharedPredictionModel;
+import org.apache.ctakes.dependency.parser.ae.shared.SRLSharedRoleModel;
 import org.apache.ctakes.typesystem.type.syntax.BaseToken;
 import org.apache.ctakes.typesystem.type.syntax.ConllDependencyNode;
 import org.apache.ctakes.typesystem.type.syntax.NewlineToken;
@@ -35,23 +37,28 @@ import org.apache.ctakes.typesystem.type
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.log4j.Logger;
 import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
-import org.apache.uima.fit.descriptor.ConfigurationParameter;
+import org.apache.uima.fit.descriptor.ExternalResource;
 import org.apache.uima.fit.descriptor.TypeCapability;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.fit.factory.ExternalResourceFactory;
 import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.cas.EmptyFSList;
 import org.apache.uima.jcas.cas.FSList;
 import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.resource.ExternalResourceDescription;
 import org.apache.uima.resource.ResourceInitializationException;
 
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.googlecode.clearnlp.component.AbstractComponent;
+import com.googlecode.clearnlp.dependency.DEPArc;
+import com.googlecode.clearnlp.dependency.DEPFeat;
+import com.googlecode.clearnlp.dependency.DEPLib;
+import com.googlecode.clearnlp.dependency.DEPNode;
+import com.googlecode.clearnlp.dependency.DEPTree;
+import com.googlecode.clearnlp.reader.AbstractReader;
 
 /**
  *This class provides a UIMA wrapper for the ClearNLP Semantic Role Labeler, which is
@@ -86,45 +93,24 @@ import java.util.Map;
 public class ClearNLPSemanticRoleLabelerAE extends JCasAnnotator_ImplBase {
    final String language = AbstractReader.LANG_EN;
    public Logger logger = Logger.getLogger( getClass().getName() );
-   public static final String DEFAULT_SRL_MODEL_FILE_NAME
-         = "org/apache/ctakes/dependency/parser/models/srl/mayo-en-srl-1.3.0.jar";
-   public static final String DEFAULT_PRED_MODEL_FILE_NAME
-         = "org/apache/ctakes/dependency/parser/models/pred/mayo-en-pred-1.3.0.jar";
-   public static final String DEFAULT_ROLE_MODEL_FILE_NAME
-         = "org/apache/ctakes/dependency/parser/models/role/mayo-en-role-1.3.0.jar";
 
-
-   public static final String PARAM_PARSER_MODEL_FILE_NAME = "ParserModelFileName";
-   public static final String PARAM_PRED_MODEL_FILE_NAME = "ParserPredFileName";
-   public static final String PARAM_ROLE_MODEL_FILE_NAME = "ParserRoleFileName";
-
-   protected URI srlModelUri;
-   protected URI srlPredUri;
-   protected URI srlRoleUri;
-
-
-   @ConfigurationParameter(
-         name = PARAM_PARSER_MODEL_FILE_NAME,
-         description = "This parameter provides the file name of the semantic role labeler
model required by the factory method provided by ClearNLPUtil.",
-         defaultValue = DEFAULT_SRL_MODEL_FILE_NAME )
-   private String parserModelFileName;
-
-   public static final String PARAM_LEMMATIZER_DATA_FILE = "LemmatizerDataFile";
-
-   @ConfigurationParameter(
-         name = PARAM_PRED_MODEL_FILE_NAME,
-         description = "This parameter provides the file name of the pred model required
by the factory method provided by ClearNLPUtil.",
-         defaultValue = DEFAULT_PRED_MODEL_FILE_NAME )
-   private String parserPredFileName;
-
-   @ConfigurationParameter(
-         name = PARAM_ROLE_MODEL_FILE_NAME,
-         description = "This parameter provides the file name of the role model required
by the factory method provided by ClearNLPUtil.",
-         defaultValue = DEFAULT_ROLE_MODEL_FILE_NAME )
-   private String parserRoleFileName;
-
-
-   protected AbstractComponent srlabeler;
+   public static final String SRL_PRED_MODEL_KEY = "SrlPredModel";
+   @ExternalResource(key = SRL_PRED_MODEL_KEY)
+   private SRLSharedPredictionModel predModel;
+
+   public static final String SRL_PARSER_MODEL_KEY = "SrlParserModel";
+   @ExternalResource(key = SRL_PARSER_MODEL_KEY)
+   private SRLSharedParserModel classifierModel;
+   
+   public static final String SRL_ROLE_MODEL_KEY = "SrlRoleModel";
+   @ExternalResource(key = SRL_ROLE_MODEL_KEY)
+   private SRLSharedRoleModel roleModel;
+   
+   private static ExternalResourceDescription defaultParserResource = null;
+   private static ExternalResourceDescription defaultPredictionResource = null;
+   private static ExternalResourceDescription defaultRoleResource = null;
+   
+   protected AbstractComponent parser;
    protected AbstractComponent identifier;
    protected AbstractComponent classifier;
 
@@ -133,23 +119,11 @@ public class ClearNLPSemanticRoleLabeler
    public void initialize( UimaContext context ) throws ResourceInitializationException {
       super.initialize( context );
 
+      logger.info("Initializing ClearNLP semantic role labeler");
       try {
-
-         InputStream srlPred = (this.srlPredUri == null)
-                               ? FileLocator.getAsStream( DEFAULT_PRED_MODEL_FILE_NAME )
-                               : FileLocator.getAsStream( parserPredFileName );
-         this.identifier = EngineGetter.getComponent( srlPred, this.language, NLPLib.MODE_PRED
);
-
-         InputStream srlRole = (this.srlRoleUri == null)
-                               ? FileLocator.getAsStream( DEFAULT_ROLE_MODEL_FILE_NAME )
-                               : FileLocator.getAsStream( parserRoleFileName );
-         this.classifier = EngineGetter.getComponent( srlRole, this.language, NLPLib.MODE_ROLE
);
-
-         InputStream srlModel = (this.srlModelUri == null)
-                                ? FileLocator.getAsStream( DEFAULT_SRL_MODEL_FILE_NAME )
-                                : FileLocator.getAsStream( parserModelFileName );
-         this.srlabeler = EngineGetter.getComponent( srlModel, this.language, NLPLib.MODE_SRL
);
-
+         this.identifier = predModel.getComponent(); 
+         this.classifier = roleModel.getComponent();
+         this.parser = classifierModel.getComponent();
       } catch ( Exception e ) {
          throw new ResourceInitializationException( e );
       }
@@ -236,7 +210,7 @@ public class ClearNLPSemanticRoleLabeler
          // Run the SRL
          identifier.process( tree );
          classifier.process( tree );
-         srlabeler.process( tree );
+         parser.process( tree );
 
 
          // Convert ClearNLP SRL output to CAS types
@@ -331,4 +305,30 @@ public class ClearNLPSemanticRoleLabeler
       return argument;
    }
 
+   public static AnalysisEngineDescription createAnnotatorDescription() throws ResourceInitializationException{
+     if(defaultParserResource == null){
+       defaultParserResource = ExternalResourceFactory.createExternalResourceDescription(
+           SRLSharedParserModel.class, 
+           SRLSharedParserModel.DEFAULT_SRL_MODEL_FILE_NAME);
+     }
+     if(defaultPredictionResource == null){
+       defaultPredictionResource = ExternalResourceFactory.createExternalResourceDescription(
+           SRLSharedPredictionModel.class, 
+           SRLSharedPredictionModel.DEFAULT_PRED_MODEL_FILE_NAME);
+     }
+     if(defaultRoleResource == null){
+       defaultRoleResource = ExternalResourceFactory.createExternalResourceDescription(
+           SRLSharedRoleModel.class, 
+           SRLSharedRoleModel.DEFAULT_ROLE_MODEL_FILE_NAME);
+     }
+     return AnalysisEngineFactory.createEngineDescription(
+         ClearNLPSemanticRoleLabelerAE.class,
+         SRL_PARSER_MODEL_KEY,
+         defaultParserResource,
+         SRL_PRED_MODEL_KEY,
+         defaultPredictionResource,
+         SRL_ROLE_MODEL_KEY,
+         defaultRoleResource);
+
+   }
 }

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/DependencySharedModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/DependencySharedModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/DependencySharedModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/DependencySharedModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,42 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.apache.ctakes.core.resource.FileLocator;
+import org.apache.log4j.Logger;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.SharedResourceObject;
+
+import com.googlecode.clearnlp.component.AbstractComponent;
+import com.googlecode.clearnlp.engine.EngineGetter;
+import com.googlecode.clearnlp.nlp.NLPLib;
+import com.googlecode.clearnlp.reader.AbstractReader;
+
+public class DependencySharedModel implements SharedResourceObject {
+
+  private AbstractComponent parser;
+  public static final String DEFAULT_MODEL_FILE_NAME = "org/apache/ctakes/dependency/parser/models/dependency/mayo-en-dep-1.3.0.jar";
+  final String language = AbstractReader.LANG_EN;
+  public Logger logger = Logger.getLogger(getClass().getName());
+
+  @Override
+  public void load(DataResource aData) throws ResourceInitializationException {
+    URI uri = aData.getUri();
+    try{
+      InputStream parserModel = (uri == null)
+          ? FileLocator.getAsStream(DEFAULT_MODEL_FILE_NAME)
+              : FileLocator.getAsStream(uri.getPath());
+
+          this.parser = EngineGetter.getComponent(parserModel, this.language, NLPLib.MODE_DEP);
+    }catch(IOException e){
+      throw new ResourceInitializationException(e);
+    }
+  }
+
+  public AbstractComponent getParser(){
+    return parser;
+  }
+}

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/LemmatizerSharedModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/LemmatizerSharedModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/LemmatizerSharedModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/LemmatizerSharedModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,43 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.apache.ctakes.core.resource.FileLocator;
+import org.apache.log4j.Logger;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.SharedResourceObject;
+
+import com.googlecode.clearnlp.engine.EngineGetter;
+import com.googlecode.clearnlp.morphology.AbstractMPAnalyzer;
+import com.googlecode.clearnlp.reader.AbstractReader;
+
+public class LemmatizerSharedModel implements SharedResourceObject {
+
+  public static final String ENG_LEMMATIZER_DATA_FILE = "org/apache/ctakes/dependency/parser/models/lemmatizer/dictionary-1.3.1.jar";
+
+  private AbstractMPAnalyzer lemmatizer = null;
+  final String language = AbstractReader.LANG_EN;
+  public Logger logger = Logger.getLogger(getClass().getName());
+
+  @Override
+  public void load(DataResource aData) throws ResourceInitializationException {
+    URI modelUri = aData.getUri();
+    try{
+      InputStream lemmatizerModel = (modelUri == null)
+          ? FileLocator.getAsStream(ENG_LEMMATIZER_DATA_FILE)
+              : FileLocator.getAsStream(modelUri.getPath());
+          
+      this.lemmatizer = EngineGetter.getMPAnalyzer(language, lemmatizerModel);
+    }catch(IOException e){
+      throw new ResourceInitializationException(e);
+    }
+  }
+
+  public AbstractMPAnalyzer getLemmatizerModel(){
+    return this.lemmatizer;
+  }
+
+}

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,41 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.apache.ctakes.core.resource.FileLocator;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.SharedResourceObject;
+
+import com.googlecode.clearnlp.component.AbstractComponent;
+import com.googlecode.clearnlp.engine.EngineGetter;
+import com.googlecode.clearnlp.reader.AbstractReader;
+
+public abstract class SRLSharedModel implements SharedResourceObject {
+
+  protected AbstractComponent component;
+  protected String language = AbstractReader.LANG_EN;
+  
+  @Override
+  public void load(DataResource aData) throws ResourceInitializationException {
+    URI modelUri = aData.getUri();
+    try{
+      InputStream modelInputStream = (modelUri == null)
+          ? FileLocator.getAsStream( this.getDefaultModel() )
+              : FileLocator.getAsStream( modelUri.toString() );
+          this.component = EngineGetter.getComponent( modelInputStream, this.language, this.getMode()
);
+    }catch(IOException e){
+      throw new ResourceInitializationException(e);
+    }
+  }
+
+  public AbstractComponent getComponent(){
+    return this.component;
+  }
+  
+  protected abstract String getMode();
+
+  protected abstract String getDefaultModel();
+}

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedParserModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedParserModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedParserModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedParserModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,18 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import com.googlecode.clearnlp.nlp.NLPLib;
+
+public class SRLSharedParserModel extends SRLSharedModel {
+  public static final String DEFAULT_SRL_MODEL_FILE_NAME = 
+      "org/apache/ctakes/dependency/parser/models/srl/mayo-en-srl-1.3.0.jar";
+
+  @Override
+  protected String getMode() {
+    return NLPLib.MODE_SRL;
+  }
+
+  @Override
+  protected String getDefaultModel() {
+    return DEFAULT_SRL_MODEL_FILE_NAME;
+  }
+}

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedPredictionModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedPredictionModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedPredictionModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedPredictionModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,19 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import com.googlecode.clearnlp.nlp.NLPLib;
+
+public class SRLSharedPredictionModel extends SRLSharedModel {
+  public static final String DEFAULT_PRED_MODEL_FILE_NAME = 
+      "org/apache/ctakes/dependency/parser/models/pred/mayo-en-pred-1.3.0.jar";
+  
+  @Override
+  protected String getMode() {
+    return NLPLib.MODE_PRED;
+  }
+
+  @Override
+  protected String getDefaultModel() {
+    return DEFAULT_PRED_MODEL_FILE_NAME;
+  }
+
+}

Added: ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedRoleModel.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedRoleModel.java?rev=1801587&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedRoleModel.java
(added)
+++ ctakes/trunk/ctakes-dependency-parser/src/main/java/org/apache/ctakes/dependency/parser/ae/shared/SRLSharedRoleModel.java
Tue Jul 11 10:12:28 2017
@@ -0,0 +1,18 @@
+package org.apache.ctakes.dependency.parser.ae.shared;
+
+import com.googlecode.clearnlp.nlp.NLPLib;
+
+public class SRLSharedRoleModel extends SRLSharedModel {
+  public static final String DEFAULT_ROLE_MODEL_FILE_NAME
+  = "org/apache/ctakes/dependency/parser/models/role/mayo-en-role-1.3.0.jar";
+  
+  @Override
+  protected String getMode() {
+    return NLPLib.MODE_ROLE;
+  }
+
+  @Override
+  protected String getDefaultModel() {
+    return DEFAULT_ROLE_MODEL_FILE_NAME;
+  }
+}

Modified: ctakes/trunk/ctakes-dependency-parser/src/test/java/org/apache/ctakes/dependency/parser/ae/util/TestClearNLPAnalysisEngines.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dependency-parser/src/test/java/org/apache/ctakes/dependency/parser/ae/util/TestClearNLPAnalysisEngines.java?rev=1801587&r1=1801586&r2=1801587&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dependency-parser/src/test/java/org/apache/ctakes/dependency/parser/ae/util/TestClearNLPAnalysisEngines.java
(original)
+++ ctakes/trunk/ctakes-dependency-parser/src/test/java/org/apache/ctakes/dependency/parser/ae/util/TestClearNLPAnalysisEngines.java
Tue Jul 11 10:12:28 2017
@@ -24,6 +24,7 @@ import org.apache.ctakes.dependency.pars
 import org.apache.ctakes.dependency.parser.util.SRLUtility;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.collection.CollectionReader;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
@@ -110,27 +111,20 @@ public class TestClearNLPAnalysisEngines
 				);
 		
 		// Load preprocessing pipeline (consists of 
-		AnalysisEngine preprocessingAE = WriteClearNLPDescriptors.getPlaintextAggregateBuilder().createAggregate();
+		AnalysisEngineDescription preprocessingAE = WriteClearNLPDescriptors.getPlaintextAggregateBuilder().createAggregateDescription();
 		
 		// Create dependency parsers analysis engine with the default models
 		// The dummy models from ClearParser haven't been updated to work with ClearNLP.
-		AnalysisEngine ClearNLPDepParser = AnalysisEngineFactory.createEngine(
-				ClearNLPDependencyParserAE.class,
-				typeSystem
-				);
-	
+		AnalysisEngineDescription clearNLPDepParser = ClearNLPDependencyParserAE.createAnnotatorDescription();
 				
 		// Create analysis engine for SRL
-		AnalysisEngine ClearNLPSRL = AnalysisEngineFactory.createEngine(
-				ClearNLPSemanticRoleLabelerAE.class,
-				typeSystem
-				);
+		AnalysisEngineDescription clearNLPSRL = ClearNLPSemanticRoleLabelerAE.createAnnotatorDescription();
 		
-		AnalysisEngine dumpClearNLPOutput = AnalysisEngineFactory.createEngine(
+		AnalysisEngineDescription dumpClearNLPOutput = AnalysisEngineFactory.createEngineDescription(
 				DumpClearNLPOutputAE.class,
 				typeSystem);
 		
-		SimplePipeline.runPipeline(reader1, preprocessingAE, ClearNLPDepParser, ClearNLPSRL, dumpClearNLPOutput);

+		SimplePipeline.runPipeline(reader1, preprocessingAE, clearNLPDepParser, clearNLPSRL, dumpClearNLPOutput);

 	}
 	
 }



Mime
View raw message