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 EventTimeSelfRelationAnnotator 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.
	 
	public static AnalysisEngineDescription createEngineDescription(File modelDirectory)
		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) {
				JCasUtil.indexCovering(jCasEventMention.classEventMention.class);
		List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
		for (EventMention event : JCasUtil.selectCovered(jCasEventMention.classsentence)) {
			boolean eventValid = false;
			if (event.getClass().equals(EventMention.class)) {//event is a gold event
				forEventMention aEve : JCasUtil.selectCovered(jCasEventMention.classevent)){
					if(!aEve.getClass().equals(EventMention.class)){//this event cover a UMLS semantic type
						eventValid = true;
						break;
					}
				}
			}
			if(eventValid){
				// ignore subclasses like Procedure and Disease/Disorder
				if(this.isTraining()){//if training mode, train on both gold event and span-overlapping system events
					for (TimeMention time : JCasUtil.selectCovered(jCasTimeMention.classsentence)) {
						Collection<EventMentioneventList = coveringMap.get(event);
						for(EventMention covEvent : eventList){
							pairs.add(new IdentifiedAnnotationPair(covEventtime));
						}
						pairs.add(new IdentifiedAnnotationPair(eventtime));
						for(EventMention covedEvent : JCasUtil.selectCovered(jCasEventMention.classevent)){//select covered events
							pairs.add(new IdentifiedAnnotationPair(covedEventtime));
						}
					}
				}else{//if testing mode, only test on system generated events
					for (TimeMention time : JCasUtil.selectCovered(jCasTimeMention.classsentence)) {
						pairs.add(new IdentifiedAnnotationPair(eventtime));
					}
				}
			}
		}
		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){
				..println("find system-event relations: "arg1.getCoveredText() + " -"+category+"- " + arg2.getCoveredText());
			}else{
				..println("find gold-event relations: "arg1.getCoveredText() + " -"+category+"- " + arg2.getCoveredText());
			}
		}
		if (category == null && coin.nextDouble() <= this.) {
			category = NO_RELATION_CATEGORY;
		}
		return category;
	}
New to GrepCode? Check out our FAQ X