ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1587724 - in /ctakes/trunk/ctakes-constituency-parser/src/main/java/org/apache/ctakes/constituency/parser: MaxentParserWrapper.java ae/ConstituencyParser.java
Date Tue, 15 Apr 2014 20:51:47 GMT
Author: tmill
Date: Tue Apr 15 20:51:47 2014
New Revision: 1587724

URL: http://svn.apache.org/r1587724
Log:
Made parser use uimafit-style configuration parameters.

Modified:
    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/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=1587724&r1=1587723&r2=1587724&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
Tue Apr 15 20:51:47 2014
@@ -47,11 +47,16 @@ public class MaxentParserWrapper impleme
 	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){
 		try {
 			File d = new File(dataDir);
-
+			this.usePos = usePos;
 			if (!d.isDirectory()) {
 				FileInputStream fis = new FileInputStream(d);
 				ParserModel model = new ParserModel(fis);
@@ -98,7 +103,7 @@ public class MaxentParserWrapper impleme
 			TopTreebankNode top = TreeUtils.buildAlignedTree(jcas, parse, sentAnnot);
 			top.addToIndexes();
 		}
-//		logger.info("Done parsing: " + docId);
+		logger.info("Done parsing: " + docId);
 	}
 
 

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=1587724&r1=1587723&r2=1587724&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
Tue Apr 15 20:51:47 2014
@@ -25,34 +25,45 @@ 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_component.JCasAnnotator_ImplBase;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
+import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
 
 
 public class ConstituencyParser extends JCasAnnotator_ImplBase {
-	public static final String PARAM_MODELFILE = "modelFilename";
-	public static final String defaultModel = "org/apache/ctakes/constituency/parser/models/sharpacq-3.1.bin";
+	public static final String PARAM_MODEL_FILENAME = "MODEL_FILENAME";
+	public static final String PARAM_USE_POS = "USE_POS";
 	
-	ParserWrapper parser = null;
-	Logger logger = Logger.getLogger(this.getClass());
+	@ConfigurationParameter(
+			name = PARAM_MODEL_FILENAME,
+			description = "File containing the opennlp-trained parser model",
+			mandatory = false,
+			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());
 
 	@Override
 	public void initialize(UimaContext aContext)
 			throws ResourceInitializationException {
 		super.initialize(aContext);
-		String modelFileOrDirname = (String) aContext.getConfigParameterValue(PARAM_MODELFILE);
-		if(modelFileOrDirname == null){
-			modelFileOrDirname = defaultModel;
-		}
 		try {
-			logger.info("Initializing parser...");
-			
-			parser = new MaxentParserWrapper(FileLocator.locateFile(modelFileOrDirname).getAbsolutePath());
+			logger.info("Initializing parser...");		
+			parser = new MaxentParserWrapper(FileLocator.locateFile(modelFilename).getAbsolutePath(),
usePos);
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
 			logger.error("Error reading parser model file/directory: " + e.getMessage());
+			throw new ResourceInitializationException(e);
 		}
 	}
 



Mime
View raw message