ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chen...@apache.org
Subject svn commit: r1641469 - in /ctakes/trunk/ctakes-constituency-parser: desc/ src/main/java/org/apache/ctakes/constituency/parser/ src/main/java/org/apache/ctakes/constituency/parser/ae/
Date Mon, 24 Nov 2014 20:27:35 GMT
Author: chenpei
Date: Mon Nov 24 20:27:35 2014
New Revision: 1641469

URL: http://svn.apache.org/r1641469
Log:
CTAKES-336
Allow constituency parser to allow reading of model from input stream
- Fixed modelfile param name in descriptor xml
- Removed not used usePos parameter in code
- Added static getDescriptor() factory method for uimaFit style pipeline instantiation.

Modified:
    ctakes/trunk/ctakes-constituency-parser/desc/ConstituencyParserAnnotator.xml
    ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/MaxentParserWrapper.java
    ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/ae/ConstituencyParser.java

Modified: ctakes/trunk/ctakes-constituency-parser/desc/ConstituencyParserAnnotator.xml
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-constituency-parser/desc/ConstituencyParserAnnotator.xml?rev=1641469&r1=1641468&r2=1641469&view=diff
==============================================================================
--- ctakes/trunk/ctakes-constituency-parser/desc/ConstituencyParserAnnotator.xml (original)
+++ ctakes/trunk/ctakes-constituency-parser/desc/ConstituencyParserAnnotator.xml Mon Nov 24
20:27:35 2014
@@ -30,7 +30,7 @@
     <vendor/>
     <configurationParameters>
       <configurationParameter>
-        <name>modelFilename</name>
+        <name>MODEL_FILENAME</name>
         <type>String</type>
         <multiValued>false</multiValued>
         <mandatory>true</mandatory>
@@ -38,7 +38,7 @@
     </configurationParameters>
     <configurationParameterSettings>
       <nameValuePair>
-        <name>modelFilename</name>
+        <name>MODEL_FILENAME</name>
         <value>
           <string>org/apache/ctakes/constituency/parser/models/sharpacq-3.1.bin</string>
         </value>

Modified: ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/MaxentParserWrapper.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/MaxentParserWrapper.java?rev=1641469&r1=1641468&r2=1641469&view=diff
==============================================================================
--- ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/MaxentParserWrapper.java
(original)
+++ ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/MaxentParserWrapper.java
Mon Nov 24 20:27:35 2014
@@ -18,48 +18,35 @@
  */
 package org.apache.ctakes.constituency.parser;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 
-import opennlp.tools.cmdline.parser.ParserTool;
 import opennlp.tools.parser.AbstractBottomUpParser;
 import opennlp.tools.parser.Parse;
 import opennlp.tools.parser.ParserModel;
 import opennlp.tools.parser.chunking.Parser;
-import opennlp.tools.util.Span;
 
 import org.apache.ctakes.constituency.parser.util.TreeUtils;
 import org.apache.ctakes.core.util.DocumentIDAnnotationUtil;
-import org.apache.ctakes.typesystem.type.syntax.TerminalTreebankNode;
 import org.apache.ctakes.typesystem.type.syntax.TopTreebankNode;
-import org.apache.ctakes.typesystem.type.syntax.TreebankNode;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
 import org.apache.log4j.Logger;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.cas.FSArray;
-import org.apache.uima.jcas.cas.StringArray;
 
 public class MaxentParserWrapper implements ParserWrapper {
 
 	Parser parser = null;
 	private String parseStr = "";
 	Logger logger = Logger.getLogger(this.getClass().getName());
-	private boolean usePos;
-	
-	public MaxentParserWrapper(String dataDir) {
-		this(dataDir, false);
-	}
-	
-	public MaxentParserWrapper(String dataDir, boolean usePos){
+
+
+	public MaxentParserWrapper(InputStream is){
 		try {
-			File d = new File(dataDir);
-			this.usePos = usePos;
-			if (!d.isDirectory()) {
-				FileInputStream fis = new FileInputStream(d);
-				ParserModel model = new ParserModel(fis);
+			if (is!=null) {
+				ParserModel model = new ParserModel(is);
 				parser = new Parser(model, AbstractBottomUpParser.defaultBeamSize, AbstractBottomUpParser.defaultAdvancePercentage);
 			}
 		} catch (IOException e) {

Modified: ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/ae/ConstituencyParser.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/ae/ConstituencyParser.java?rev=1641469&r1=1641468&r2=1641469&view=diff
==============================================================================
--- ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/ae/ConstituencyParser.java
(original)
+++ ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser/ae/ConstituencyParser.java
Mon Nov 24 20:27:35 2014
@@ -25,16 +25,17 @@ import org.apache.ctakes.constituency.pa
 import org.apache.ctakes.core.resource.FileLocator;
 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.jcas.JCas;
-import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
 import org.apache.uima.fit.descriptor.ConfigurationParameter;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
 
 
 public class ConstituencyParser extends JCasAnnotator_ImplBase {
 	public static final String PARAM_MODEL_FILENAME = "MODEL_FILENAME";
-	public static final String PARAM_USE_POS = "USE_POS";
 	
 	@ConfigurationParameter(
 			name = PARAM_MODEL_FILENAME,
@@ -43,12 +44,6 @@ public class ConstituencyParser extends 
 			defaultValue = "org/apache/ctakes/constituency/parser/models/sharpacq-3.1.bin"
 	) private String modelFilename;
 	
-	@ConfigurationParameter(
-			name = PARAM_USE_POS,
-			description = "Whether to use the POS tags generated by cTAKES pos tagger or generate
our own",
-			mandatory = false,
-			defaultValue = "false"
-	) private boolean usePos;
 	
 	private ParserWrapper parser = null;
 	private Logger logger = Logger.getLogger(this.getClass());
@@ -59,7 +54,7 @@ public class ConstituencyParser extends 
 		super.initialize(aContext);
 		try {
 			logger.info("Initializing parser...");		
-			parser = new MaxentParserWrapper(FileLocator.locateFile(modelFilename).getAbsolutePath(),
usePos);
+			parser = new MaxentParserWrapper(FileLocator.getAsStream(modelFilename));
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
 			logger.error("Error reading parser model file/directory: " + e.getMessage());
@@ -72,4 +67,17 @@ public class ConstituencyParser extends 
 	public void process(JCas jcas) throws AnalysisEngineProcessException {
 		parser.createAnnotations(jcas);
 	}
+	
+	  public static AnalysisEngineDescription createAnnotatorDescription(
+		      String modelPath) throws ResourceInitializationException {
+		    return AnalysisEngineFactory.createEngineDescription(
+		    		ConstituencyParser.class,
+		    		ConstituencyParser.PARAM_MODEL_FILENAME,
+		        modelPath);
+		  }
+	  public static AnalysisEngineDescription createAnnotatorDescription() 
+			  throws ResourceInitializationException {
+		    return AnalysisEngineFactory.createEngineDescription(
+		    		ConstituencyParser.class);
+		  }	  
 }



Mime
View raw message