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.utils;
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;

Author: SPF Affiliation: CHIP-NLP Date: 6/17/13
 
 public class AnnotationIdCollection {
 
 	static public final int NO_ENTITY_ID = .;
 
 
 	// Key = Annotation (named, event, timex), Value = id number for each "unique" reference.
 	// Co-referent entities will have the same id number
 	private final Map<Annotation,Integer_entityIdMap;
 	// Key = id number for each "unique" reference, value = primary entity
 
 
 	public AnnotationIdCollection(ArrayList<BinaryTextRelationtemporalRelation){ //final AnnotationCollection annotationCollection ) {
 		
 		Set<AnnotationallAnnotations = new HashSet<Annotation>();
 		for (BinaryTextRelation relation : temporalRelation) {
 			allAnnotations.add(relation.getArg1().getArgument());
 			allAnnotations.add(relation.getArg2().getArgument());
 		}
 		final List<AnnotationannotationsList = new ArrayList<Annotation>( allAnnotations );
 		Collections.sortannotationsList. );// just so that closure counts are consistent
 		
 		int id = 0;
 		for (Annotation annotation : annotationsList) {
 			.putannotationid );
 			.putidannotation );
 			id++;			
 		}
 
 		//      int id = 0;
 		//      for ( Annotation entity : annotationCollection.getNamedEntities() ) {
 		//         _entityIdMap.put( entity, id );
 		//         _idAnnotationMap.put( id, entity );
 		//         id++;
 		//      }
 		//      for ( Annotation entity : annotationCollection.getTimes() ) {
 		//         _entityIdMap.put( entity, id );
 		//         _idAnnotationMap.put( id, entity );
 		//         id++;
 		//      }
 		//      for ( Annotation entity : annotationCollection.getEvents() ) {
 		//         _entityIdMap.put( entity, id );
 		//         _idAnnotationMap.put( id, entity );
 		//         id++;
 		//      }
 		//      for ( CoreferenceChain chain : annotationCollection.getCoreferenceEntities() ) {
 		//         for ( Annotation entity : chain ) {
 		//            _entityIdMap.put( entity, id );
 		//         }
 		//         _entityIdMap.put( chain, id );
 		//         _idAnnotationMap.put( id, chain );
 		//         id++;
 		//      }
 
 	}


Returns:
a collection of unique ids for all unique entities
 
		//      return Collections.unmodifiableSet( _idAnnotationMap.keySet() );
		return Collections.unmodifiableSetnew HashSet<Integer>( .values() ) );
	}

Parameters:
entity some entity, be it unique on its own or part of a coreference chain
Returns:
an id for the entity
	public int getAnnotationIdfinal Annotation entity ) {
		final Integer id = .getentity );
		if ( id != null ) {
			return id;
		}
		return getIdByAnnotationEqualentity );
	}
	private int getIdByAnnotationEqualfinal Annotation entity ) {
		for ( Annotation referenceAnnotation : .keySet() ) {
			if ( referenceAnnotation.equalsentity ) ) {
				final int id = .getreferenceAnnotation );
				// Prevent future iteration searches
				.putentityid );
				return id;
			}
		}
		return getIdByTextSpanentity.getBegin(), entity.getEnd() );
	}
	private int getIdByTextSpanfinal int beginint end ) {
		for ( Annotation referenceAnnotation : .keySet() ) {
			if ( referenceAnnotation.getBegin()==begin &&  referenceAnnotation.getEnd()==end){//.getTextSpan().equals( textSpan ) ) {
				return .getreferenceAnnotation );
			}
//			// TODO necessary?
//			if ( referenceAnnotation instanceof CoreferenceChain ) {
//				for ( Annotation coreference : (CoreferenceChain)referenceAnnotation ) {
//					if ( coreference.getTextSpan().equals( textSpan ) ) {
//						return _entityIdMap.get( referenceAnnotation );
//					}
//				}
//			}
		}
		return ;
	}


Parameters:
entityId some id
Returns:
the NamedAnnotation, Event, Timex, or CoreferenceChain with the given referenceId
	public Annotation getAnnotationfinal int entityId ) {
		return .getentityId );
	}
	public Annotation getAnnotationfinal Annotation entity ) {
		final int id = getAnnotationIdentity );
		if ( id !=  ) {
			return getAnnotationid );
		}
		return null;
	}
	static private enum ArgComparator implements Comparator<Annotation> {
		INSTANCE;
		public int comparefinal Annotation arg1final Annotation arg2 ) {
			final int startDiff = arg1.getBegin() - arg2.getBegin();
			if ( startDiff != 0 ) {
				return startDiff;
			}
			return arg1.getEnd() - arg2.getEnd();
		}		
	}
New to GrepCode? Check out our FAQ X