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.eval;
 
 import java.io.File;
 import java.util.Set;
 
 import  org.cleartk.ml.tksvmlight.model.CompositeKernel.ComboOperator;
 import  org.cleartk.eval.AnnotationStatistics;
 
 
 public abstract class EvaluationOfTemporalRelations_ImplBase extends
 Evaluation_ImplBase<AnnotationStatistics<String>> {
 
 	public static interface TempRelOptions extends Evaluation_ImplBase.Options{
 		public boolean getTest();
 
 		public boolean getPrintFormattedRelations();
 
 		public boolean getBaseline();
 
 		public boolean getClosure();
 
 		public boolean getClassificationOnly();
 
 	}
 
 	protected static boolean DEFAULT_BOTH_DIRECTIONS = false;
 	protected static float DEFAULT_DOWNSAMPLE = 1.0f;
 	protected static double DEFAULT_SVM_C = 1.0;
 	protected static double DEFAULT_SVM_G = 1.0;
 	protected static double DEFAULT_TK = 0.5;
 	protected static double DEFAULT_LAMBDA = 0.5;
 
 			"polynomial", ComboOperator.SUM, );
 
 
 	protected ParameterSettings params = null;
 	protected boolean printRelations = false;
 
 			File rawTextDirectoryFile xmlDirectoryXMLFormat xmlFormatSubcorpus subcorpus,
 			File xmiDirectoryFile treebankDirectoryboolean printErrorsboolean printRelationsParameterSettings params) {
 		super(baseDirectoryrawTextDirectoryxmlDirectoryxmlFormatsubcorpusxmiDirectory,
 				treebankDirectory);
 		this. = params;
 		this. = printRelations;
 		this. =  printErrors;
 	}
 
 		public static final String PARAM_GOLD_VIEW = "GoldView";
 
 		@ConfigurationParameter(name = ,mandatory=false)
 
 		public void process(JCas jCasthrows AnalysisEngineProcessException {
			for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(jCasBinaryTextRelation.class))){
				RelationArgument arg1 = relation.getArg1();
				RelationArgument arg2 = relation.getArg2();
				if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof EventMention && relation instanceof TemporalTextRelation){
					// these are the kind we keep.
					continue;
				}
			}
		}   
	}
		public static final String PARAM_RELATION_VIEW = "RelationView";
		public void process(JCas jCasthrows AnalysisEngineProcessException {
			JCas relationView = null;
			try {
				relationView = jCas.getView();
catch (CASException e) {
			}
			for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
					relationView,
				RelationArgument arg1 = relation.getArg1();
				RelationArgument arg2 = relation.getArg2();
				if (arg1.getArgument()instanceof EventMention && arg2.getArgument()instanceof EventMention && !relation.getCategory().startsWith("CONTAINS")) {
				}
			}
		}
	}
	public static class RemoveGoldAttributes extends JCasAnnotator_ImplBase {
		public void process(JCas jCasthrows AnalysisEngineProcessException {
			for(EventMention event : JCasUtil.select(jCasEventMention.class)){
				if(event.getEvent() != null && event.getEvent().getProperties() != null){
				}
			}
			for(TimeMention timex : JCasUtil.select(jCasTimeMention.class)){
				timex.setTimeClass("UNK");
			}
		}
	}
			Collection<BinaryTextRelationsystemRelations,
			Collection<BinaryTextRelationgoldRelations) {
		Set<BinaryTextRelationgoodSys = Sets.newHashSet();
		for(BinaryTextRelation sysrel : systemRelations){
			Annotation sysArg1 = sysrel.getArg1().getArgument();
			Annotation sysArg2 = sysrel.getArg2().getArgument();
			for(BinaryTextRelation goldrel : goldRelations){
				Annotation goldArg1 = goldrel.getArg1().getArgument();
				Annotation goldArg2 = goldrel.getArg2().getArgument();
				if (matchSpan(sysArg2goldArg1) && matchSpan(sysArg1goldArg2)){//the order of system pair was flipped 
					if(sysrel.getCategory().equals("OVERLAP")){ //if the relation is overlap, and the arg order was flipped, then change back the order
						RelationArgument tempArg = (RelationArgumentsysrel.getArg1().clone();
						sysrel.setArg1((RelationArgumentsysrel.getArg2().clone());
						sysrel.setArg2(tempArg);
					}//for other types of relation, still maintain the type.
					continue;
				}
			}
			goodSys.add(sysrel);
		}
		return goodSys;
	}
	private static boolean matchSpan(Annotation arg1Annotation arg2) {
		boolean result = false;
		result = arg1.getBegin() == arg2.getBegin() && arg1.getEnd() == arg2.getEnd();
		return result;
	}
	protected static void printRelationAnnotations(String fileNameCollection<BinaryTextRelationrelations) {
		for(BinaryTextRelation binaryTextRelation : relations) {
			Annotation arg1 = binaryTextRelation.getArg1().getArgument();
			Annotation arg2 = binaryTextRelation.getArg2().getArgument();
			String arg1Type = arg1.getClass().getSimpleName();
			String arg2Type = arg2.getClass().getSimpleName();
			int arg1Begin = arg1.getBegin();
			int arg1End = arg1.getEnd();
			int arg2Begin = arg2.getBegin();
			int arg2End = arg2.getEnd();
			String category = binaryTextRelation.getCategory();
			..format("%s\t%s\t%s\t%d\t%d\t%s\t%d\t%d\n"
					fileNamecategoryarg1Typearg1Beginarg1Endarg2Typearg2Beginarg2End);
		}
	}
	protected static String formatRelation(BinaryTextRelation relation) {
		String arg1Type ="E";
		String arg2Type ="T";
		if(arg1 instanceof TimeMentionarg1Type = "T";
		if(arg2 instanceof EventMentionarg2Type = "E";
		String text = arg1.getCAS().getDocumentText();
		int begin = Math.min(arg1.getBegin(), arg2.getBegin());
		int end = Math.max(arg1.getEnd(), arg2.getEnd());
		int begin1 = 0;
		int end1 = 0;
		int begin2 = 0;
		int end2 = 0;
		if(arg1.getBegin()< arg2.getBegin()){
			begin1 = arg1.getBegin();
			end1 = arg1.getEnd();
			begin2 = arg2.getBegin();
			end2 = arg2.getEnd();
		}else//arg1 is after arg2
			begin1 = arg2.getBegin();
			end1 = arg2.getEnd();
			begin2 = arg1.getBegin();
			end2 = arg1.getEnd();
		}
		begin = Math.max(0, begin - 200);
		end = Math.min(text.length(), end + 200);
		StringBuilder between = new StringBuilder();
		if(begin<begin1between.append(text.substring(beginbegin1).replaceAll("[\r\n]"" "));
		between.append(" [" + text.substring(begin1end1) + "] ");
		if(begin2<=end1){
			between.append(text.substring(begin,begin1).replaceAll("[\r\n]"" ")+" ["text.substring(begin1,begin2)+" [");
			if(end1<end2){
				between.append(text.substring(begin2,end1) + "]" + text.substring(end1,end2) + "]" +  text.substring(end2,end));
			}else{
				between.append(text.substring(begin2,end2) + "]" + text.substring(end2,end1) + "]" +  text.substring(end1,end));
			}
		}else if(begin2-end1 <=400){
			between.append(text.substring(end1begin2).replaceAll("[\r\n]"" "));
		}else{
			between.append(text.substring(end1end1+200).replaceAll("[\r\n]"" ")+ "...");
			int extra = (begin2-end1-400)/10;
			for (int i = 1; i<extrai++){
				between.append(".");
			}
			between.append(text.substring(begin2-200, begin2).replaceAll("[\r\n]"" "));
		}
		between.append(" [" + text.substring(begin2end2)+ "] ");
		if(end2 < end)  between.append(text.substring(end2end).replaceAll("[\r\n]"" ") );
		return String.format(
				"%s(%s(type=%d!%d-%d!%s), %s(type=%d!%d-%d!%s)) in ...%s...",
				relation.getCategory(),
				arg1.getTypeID(),
				//add extra
				arg1.getBegin(),
				arg1.getEnd(),
				arg1Type,
				arg2.getTypeID(),
				//add extra
				arg2.getBegin(),
				arg2.getEnd(),
				arg2Type,
				between.toString());
	}
New to GrepCode? Check out our FAQ X