Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.ctakes.temporal.ae;
 
 import java.io.File;
 import java.util.List;
 
 import  org.cleartk.classifier.CleartkAnnotator;
 import  org.cleartk.classifier.DataWriter;
 import  org.cleartk.classifier.Feature;
 import  org.cleartk.classifier.Instance;
 import  org.cleartk.classifier.chunking.BIOChunking;
 import  org.cleartk.classifier.feature.extractor.CleartkExtractor;
 import  org.cleartk.classifier.feature.extractor.CleartkExtractor.Following;
 import  org.cleartk.classifier.feature.extractor.CleartkExtractor.Preceding;
 import  org.cleartk.classifier.feature.extractor.simple.CharacterCategoryPatternExtractor;
 import  org.cleartk.classifier.feature.extractor.simple.CharacterCategoryPatternExtractor.PatternType;
 import  org.cleartk.classifier.feature.extractor.simple.CombinedExtractor;
 import  org.cleartk.classifier.feature.extractor.simple.CoveredTextExtractor;
 import  org.cleartk.classifier.feature.extractor.simple.SimpleFeatureExtractor;
 import  org.cleartk.classifier.feature.extractor.simple.TypePathExtractor;
 import  org.cleartk.classifier.jar.DefaultDataWriterFactory;
 import  org.cleartk.classifier.jar.DirectoryDataWriterFactory;
 import  org.cleartk.classifier.jar.GenericJarClassifierFactory;
 
 
 
 public class BackwardsTimeAnnotator extends TemporalEntityAnnotator_ImplBase {
 
   public static final String PARAM_TIMEX_VIEW = "TimexView";
       name = ,
       mandatory = false,
       description = "View to write timexes to (used for ensemble methods)")
   protected String timexView = .;
 
       Class<? extends DataWriter<String>> dataWriterClassFile outputDirectory)
       throws ResourceInitializationException {
     return AnalysisEngineFactory.createPrimitiveDescription(
         BackwardsTimeAnnotator.class,
         CleartkAnnotator.PARAM_IS_TRAINING,
         true,
         DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
         dataWriterClass,
         DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
         outputDirectory);
   }
 
 	      String modelPaththrows ResourceInitializationException {
 	    return AnalysisEngineFactory.createPrimitiveDescription(
 	        BackwardsTimeAnnotator.class,
 	        CleartkAnnotator.PARAM_IS_TRAINING,
 	        false,
 	        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
 	        modelPath);
 	  }
   
 	      String viewNamethrows ResourceInitializationException {
 	    return AnalysisEngineFactory.createPrimitiveDescription(
 	        BackwardsTimeAnnotator.class,
 	        CleartkAnnotator.PARAM_IS_TRAINING,
 	        false,
	        viewName,
	        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
	        modelPath);
	  }
  
  

Deprecated:
use String path instead of File. ClearTK will automatically Resolve the String to an InputStream. This will allow resources to be read within from a jar as well as File.
      File modelDirectorythrows ResourceInitializationException {
    return AnalysisEngineFactory.createPrimitiveDescription(
        BackwardsTimeAnnotator.class,
        CleartkAnnotator.PARAM_IS_TRAINING,
        false,
        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
        new File(modelDirectory"model.jar"));
  }
  

Deprecated:
use String path instead of File. ClearTK will automatically Resolve the String to an InputStream. This will allow resources to be read within from a jar as well as File.
  public static AnalysisEngineDescription createEnsembleDescription(File modelDirectory,
      String viewNamethrows ResourceInitializationException {
    return AnalysisEngineFactory.createPrimitiveDescription(
        BackwardsTimeAnnotator.class,
        CleartkAnnotator.PARAM_IS_TRAINING,
        false,
        viewName,
        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
        new File(modelDirectory"model.jar"));
  }
  protected List<SimpleFeatureExtractor> tokenFeatureExtractors;
  protected List<CleartkExtractor> contextFeatureExtractors;
  
//  protected List<SimpleFeatureExtractor> parseFeatureExtractors;
  
  private BIOChunking<BaseTokenTimeMentiontimeChunking;
  public void initialize(UimaContext contextthrows ResourceInitializationException {
    super.initialize(context);
    // define chunking
    this. = new BIOChunking<BaseTokenTimeMention>(BaseToken.classTimeMention.class);
    CombinedExtractor allExtractors = new CombinedExtractor(
        new CoveredTextExtractor(),
        new CharacterCategoryPatternExtractor(PatternType.REPEATS_MERGED),
        new CharacterCategoryPatternExtractor(PatternType.ONE_PER_CHAR),
        new TypePathExtractor(BaseToken.class"partOfSpeech"),
        new TimeWordTypeExtractor());
//    CombinedExtractor parseExtractors = new CombinedExtractor(
//        new ParseSpanFeatureExtractor()
//        );
    this. = new ArrayList<SimpleFeatureExtractor>();
    this..add(allExtractors);
    this. = new ArrayList<CleartkExtractor>();
    this..add(new CleartkExtractor(
        BaseToken.class,
        allExtractors,
        new Preceding(3),
        new Following(3)));
//    this.parseFeatureExtractors = new ArrayList<ParseSpanFeatureExtractor>();
//    this.parseFeatureExtractors.add(new ParseSpanFeatureExtractor());
  }
  public void process(JCas jCasSegment segmentthrows AnalysisEngineProcessException {
    // classify tokens within each sentence
    for (Sentence sentence : JCasUtil.selectCovered(jCasSentence.classsegment)) {
      List<BaseTokentokens = JCasUtil.selectCovered(jCasBaseToken.classsentence);
      
      // during training, the list of all outcomes for the tokens
      List<Stringoutcomes;
      if (this.isTraining()) {
        List<TimeMentiontimes = JCasUtil.selectCovered(jCasTimeMention.classsentence);
        outcomes = this..createOutcomes(jCastokenstimes);
        outcomes = Lists.reverse(outcomes);
      }
      // during prediction, the list of outcomes predicted so far
      else {
        outcomes = new ArrayList<String>();
      }
      tokens = Lists.reverse(tokens);
      // extract features for all tokens
      int tokenIndex = -1;
      for (BaseToken token : tokens) {
        ++tokenIndex;
        List<Feature> features = new ArrayList<Feature>();
        // features from token attributes
        for (SimpleFeatureExtractor extractor : this.) {
          features.addAll(extractor.extract(jCastoken));
        }
        // features from surrounding tokens
        for (CleartkExtractor extractor : this.) {
          features.addAll(extractor.extractWithin(jCastokensentence));
        }
        // features from previous classifications
        int nPreviousClassifications = 2;
        for (int i = nPreviousClassificationsi > 0; --i) {
          int index = tokenIndex - i;
          String previousOutcome = index < 0 ? "O" : outcomes.get(index);
          features.add(new Feature("PreviousOutcome_" + ipreviousOutcome));
        }
        // features from dominating parse tree
//        for(SimpleFeatureExtractor extractor : this.parseFeatureExtractors){
        BaseToken startToken = token;
        for(int i = tokenIndex-1; i >= 0; --i){
          String outcome = outcomes.get(i);
          if(outcome.equals("O")){
            break;
          }
          startToken = tokens.get(i);
        }
        features.addAll(.extract(jCasstartToken.getBegin(), token.getEnd()));
//        }
        // if training, write to data file
        if (this.isTraining()) {
          String outcome = outcomes.get(tokenIndex);
          this..write(new Instance<String>(outcomefeatures));
        }
        // if predicting, add prediction to outcomes
        else {
          outcomes.add(this..classify(features));
        }
      }
      // during prediction, convert chunk labels to times and add them to the CAS
      if (!this.isTraining()) {
        tokens = Lists.reverse(tokens);
        outcomes = Lists.reverse(outcomes);
        JCas timexCas;
        try{
          timexCas = jCas.getView();
        }catch(CASException e){
          throw new AnalysisEngineProcessException(e);
        }
        this..createChunks(timexCastokensoutcomes);
      }
    }
  }
New to GrepCode? Check out our FAQ X