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 java.util.Map;
 
 //import org.apache.ctakes.temporal.ae.feature.EventIndexOfSameSentenceRelationFeaturesExtractor;
 //import org.apache.ctakes.temporal.ae.feature.EventPositionRelationFeaturesExtractor;
 //import org.apache.ctakes.temporal.ae.feature.EventTimeRelationFeatureExtractor;
 //import org.apache.ctakes.temporal.ae.feature.SRLRelationFeaturesExtractor;
 //import org.apache.ctakes.temporal.ae.feature.SectionHeaderRelationExtractor;
 //import org.apache.ctakes.temporal.ae.feature.TimeWordTypeRelationExtractor;
 //import org.apache.ctakes.temporal.ae.feature.UnexpandedTokenFeaturesExtractor;
 //import org.apache.ctakes.temporal.ae.feature.TemporalAttributeFeatureExtractor;
 //import org.apache.ctakes.temporal.ae.feature.treekernel.EventTimeFlatTreeFeatureExtractor;
 //import org.apache.ctakes.temporal.ae.feature.treekernel.EventVerbRelationTreeExtractor;
 //import org.apache.ctakes.temporal.ae.feature.treekernel.TemporalPETExtractor;
 //import org.apache.ctakes.temporal.ae.feature.treekernel.TemporalPathExtractor;
 import  org.cleartk.ml.CleartkAnnotator;
 import  org.cleartk.ml.DataWriter;
 import  org.cleartk.ml.jar.DefaultDataWriterFactory;
 import  org.cleartk.ml.jar.DirectoryDataWriterFactory;
 import  org.cleartk.ml.jar.GenericJarClassifierFactory;
 
 
 public class EventTimeRelationAnnotator extends RelationExtractorAnnotator {
 
 			Class<? extends DataWriter<String>> dataWriterClass,
 					File outputDirectory,
 					double probabilityOfKeepingANegativeExamplethrows ResourceInitializationException {
 		return AnalysisEngineFactory.createEngineDescription(
 				CleartkAnnotator.PARAM_IS_TRAINING,
 				true,
 				DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
 				dataWriterClass,
 				DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
 				outputDirectory,
 				// not sure why this has to be cast; something funny going on in uimaFIT maybe?
 				(floatprobabilityOfKeepingANegativeExample);
 	}
 
 		return AnalysisEngineFactory.createEngineDescription(
 				CleartkAnnotator.PARAM_IS_TRAINING,
				false,
				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.
	 
		return AnalysisEngineFactory.createEngineDescription(
				CleartkAnnotator.PARAM_IS_TRAINING,
				false,
				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
				new File(modelDirectory"model.jar"));
	}
		return Lists.newArrayList(
				//				new UnexpandedTokenFeaturesExtractor() //use unexpanded version for i2b2 data
				//				, new EventTimeFlatTreeFeatureExtractor()
				//				, new TemporalPETExtractor()
				//, new TemporalPathExtractor()
				//				, new EventVerbRelationTreeExtractor()
				//				, new SectionHeaderRelationExtractor()
				//				, new SRLRelationFeaturesExtractor()// tried, but not helpful
				//				, new EventTimeRelationFeatureExtractor()
				//				, new EventPositionRelationFeaturesExtractor() //tried, but not helpful
				//				, new TimeWordTypeRelationExtractor() //tried, but not helpful
				//				, new EventIndexOfSameSentenceRelationFeaturesExtractor() //tried, but not helpful
				);
	}
	protected Class<? extends AnnotationgetCoveringClass() {
		return Sentence.class;
	}
	public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(
			JCas jCas,
			Annotation sentence) {
		List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
		for (EventMention event : JCasUtil.selectCovered(jCasEventMention.classsentence)) {
			// ignore subclasses like Procedure and Disease/Disorder
			if (event.getClass().equals(EventMention.class)) {
//				boolean eventValid = false;
//				for (EventMention ev : JCasUtil.selectCovered(jCas, EventMention.class, event)){
//					if(!ev.getClass().equals(EventMention.class)){// if there is an valid UMLS type in the same span, then true
//						eventValid = true;
//						break;
//					}
//				}
//				if(eventValid){
					for (TimeMention time : JCasUtil.selectCovered(jCasTimeMention.classsentence)) {
						pairs.add(new IdentifiedAnnotationPair(eventtime));
					}
//				}
			}
		}
		//only use gold pairs:
		//		for (BinaryTextRelation relation : JCasUtil.select(jCas, BinaryTextRelation.class)) {
		//			Annotation arg1 = relation.getArg1().getArgument();
		//			Annotation arg2 = relation.getArg2().getArgument();
		//			EventMention event = null;
		//			TimeMention time = null;
		//			if(arg1 instanceof EventMention){
		//				 event = (EventMention) arg1;
		//			}else if(arg1 instanceof TimeMention){
		//				time = (TimeMention) arg1;
		//			}
		//			if(arg2 instanceof EventMention){
		//				 event = (EventMention) arg2;
		//			}else if(arg2 instanceof TimeMention){
		//				time = (TimeMention) arg2;
		//			}
		//			if(event != null && time != null){
		//				pairs.add(new IdentifiedAnnotationPair(event, time));
		//			}
		//		}
		return pairs;
	}
	protected void createRelation(JCas jCasIdentifiedAnnotation arg1,
			IdentifiedAnnotation arg2String predictedCategory) {
		RelationArgument relArg1 = new RelationArgument(jCas);
		relArg1.setArgument(arg1);
		relArg1.setRole("Arg1");
		relArg1.addToIndexes();
		RelationArgument relArg2 = new RelationArgument(jCas);
		relArg2.setArgument(arg2);
		relArg2.setRole("Arg2");
		relArg2.addToIndexes();
		relation.setArg1(relArg1);
		relation.setArg2(relArg2);
		relation.setCategory(predictedCategory);
		relation.addToIndexes();
	}
		BinaryTextRelation relation = relationLookup.get(Arrays.asList(arg1arg2));
		String category = null;
		if (relation != null) {
			category = relation.getCategory();
else {
			relation = relationLookup.get(Arrays.asList(arg2arg1));
			if (relation != null) {
				if(relation.getCategory().equals("OVERLAP")){
					category = relation.getCategory();
					//				}else if (relation.getCategory().equals("BEFORE")){
					//					category = "AFTER";
					//				}else if (relation.getCategory().equals("AFTER")){
					//					category = "BEFORE";
					//				}
				}else{
					category = relation.getCategory() + "-1";
				}
			}
		}
		if (category == null && coin.nextDouble() <= this.) {
			category = NO_RELATION_CATEGORY;
		}
		return category;
	}
New to GrepCode? Check out our FAQ X