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.feature;
 
 import java.util.List;
 import java.util.Map;
 //import java.util.logging.Logger;
 
 //import org.apache.ctakes.temporal.ae.feature.treekernel.TemporalPETExtractor;
 //import org.apache.ctakes.temporal.ae.feature.treekernel.TemporalSingleTreeExtractor;
 import  org.cleartk.ml.Feature;
 import  org.cleartk.ml.feature.extractor.CleartkExtractorException;
 import  org.cleartk.ml.feature.extractor.FeatureExtractor1;
 
 public class TimeXExtractor implements FeatureExtractor1 {
 
   private String name;
 //  private TemporalPETExtractor path;
 //  private TemporalSingleTreeExtractor treeExt;
   
 //  private Logger logger = Logger.getLogger(this.getClass().getName());
 
     super();
     this. = "TimeXFeature";
 //    this.path = new TemporalPETExtractor();
     this. = new TemporalAttributeFeatureExtractor();
     this. = new TimeWordTypeExtractor<>();
 //    this.treeExt = new TemporalSingleTreeExtractor();
   }
 
   @Override
   public List<Feature> extract(JCas viewAnnotation annotationthrows CleartkExtractorException {
 	  List<Feature> features = new ArrayList<>();
 	  
 	  //1 get covering sentence:
 	  Map<EventMentionCollection<Sentence>> coveringMap =
 			  JCasUtil.indexCovering(viewEventMention.classSentence.class);
 	  EventMention targetTokenAnnotation = (EventMention)annotation;
 	  Collection<SentencesentList = coveringMap.get(targetTokenAnnotation);
 	  
 	  //2 get TimeX
 	  Map<IntegerIdentifiedAnnotationtimeDistMap = null;
 	  
 //	  List<Feature> treePath = new ArrayList<Feature>();
 	  
 	  //3 get Document Creation Time
 //	  String sofastr = view.getSofaDataString();
 //	  int start = sofastr.indexOf("meta rev_date=");
 //	  int end = sofastr.indexOf(" start_date=");
 //	  System.out.println(sofastr.substring(start, end));
 //	  Collection<SourceData> sources = JCasUtil.select(view, SourceData.class);
 //	  for(SourceData source : sources){
 //			System.out.println("original date: "+source.getSourceOriginalDate());
 //			System.out.println("revision date: "+source.getSourceRevisionDate());
 //		}
 	  
 	  if (sentList != null && !sentList.isEmpty()){
 		  timeDistMap = new TreeMap<>();
 		  
 		  for(Sentence sent : sentList) {
 			  for (TimeMention time : JCasUtil.selectCovered(viewTimeMention.classsent)) {
 				  timeDistMap.put(Math.abs(time.getBegin() - annotation.getBegin()), time);
 			  }
 			  for (TimeAnnotation time : JCasUtil.selectCovered(viewTimeAnnotation.classsent)) {
 				  timeDistMap.put(Math.abs(time.getBegin() - annotation.getBegin()), time);
			  }
			  for (DateAnnotation time : JCasUtil.selectCovered(viewDateAnnotation.classsent)) {
				  timeDistMap.put(Math.abs(time.getBegin() - annotation.getBegin()), time);
			  }
		  }
		  
		  //get the closest Time Expression feature
		  for (Map.Entry<IntegerIdentifiedAnnotationentry : timeDistMap.entrySet()) {
			  Feature feature = new Feature(this.entry.getValue().getCoveredText());
			  features.add(feature);
			  //			  logger.info("add time feature: "+ entry.getValue().getCoveredText() + entry.getValue().getTimeClass());
			  Feature indicator = new Feature("TimeXNearby"this.);
			  features.add(indicator);
			  Feature type = new Feature("TimeXType"entry.getValue().getClass());
			  features.add(type);
			  //add PP get Heading preposition
			  for(TreebankNode treebankNode : JCasUtil.selectCovering(
					  view
					  TreebankNode.class
					  entry.getValue().getBegin(), 
					  entry.getValue().getEnd())) {
				  if(treebankNode.getNodeType().equals("PP")) {
					  Feature PPNodeType = new Feature("Timex_PPNodeType"treebankNode.getNodeType());
					  features.add(PPNodeType);
					  break;
				  }
			  }
			  //add path tree, timex attributes
			  try {
//				  treePath=this.path.extract(view, targetTokenAnnotation, entry.getValue());//add path between timex and event
				  features.addAll(this..extract(viewtargetTokenAnnotationentry.getValue()));//add temporal attribute features
				  features.addAll(this..extract(viewentry.getValue()));
			  } catch (AnalysisEngineProcessException e) {
				  throw new IllegalArgumentException(String.format("error in gererating path feature:"features));
			  }
			  break;
		  }
	  }
//	  if (treePath.isEmpty()){
//		  try {
//			  features.addAll(this.treeExt.extract(view, targetTokenAnnotation));
//		  } catch (AnalysisEngineProcessException e) {
//			  throw new IllegalArgumentException(String.format("error in gererating path feature:", features));
//		  }
//	  }else{
//		  features.addAll(treePath);
//	  }
	  return features;
  }
New to GrepCode? Check out our FAQ X