001 /* 002 * The contents of this file are subject to the Mozilla Public 003 * License Version 1.1 (the "License"); you may not use this file 004 * except in compliance with the License. You may obtain a copy of 005 * the License at http://www.mozilla.org/MPL/ 006 * 007 * Software distributed under the License is distributed on an "AS 008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 009 * implied. See the License for the specific language governing 010 * rights and limitations under the License. 011 * 012 * The Original Code is Knowtator. 013 * 014 * The Initial Developer of the Original Code is University of Colorado. 015 * Copyright (C) 2005 - 2008. All Rights Reserved. 016 * 017 * Knowtator was developed by the Center for Computational Pharmacology 018 * (http://compbio.uchcs.edu) at the University of Colorado Health 019 * Sciences Center School of Medicine with support from the National 020 * Library of Medicine. 021 * 022 * Current information about Knowtator can be obtained at 023 * http://knowtator.sourceforge.net/ 024 * 025 * Contributor(s): 026 * Philip V. Ogren <philip@ogren.info> (Original Author) 027 */ 028 package edu.uchsc.ccp.iaa.matcher; 029 030 import java.util.Set; 031 032 import edu.uchsc.ccp.iaa.Annotation; 033 import edu.uchsc.ccp.iaa.IAA; 034 035 public class OverlappingSpanMatcher implements Matcher { 036 037 public Annotation match(Annotation annotation, String compareSetName, Set<Annotation> excludeAnnotations, IAA iaa, 038 MatchResult matchResult) { 039 040 Annotation spanAndClassMatch = ClassAndSpanMatcher.match(annotation, compareSetName, iaa, excludeAnnotations); 041 if (spanAndClassMatch != null) { 042 matchResult.setResult(MatchResult.NONTRIVIAL_MATCH); 043 return spanAndClassMatch; 044 } 045 046 Set<Annotation> classMatches = ClassMatcher.matches(annotation, compareSetName, iaa, excludeAnnotations); 047 if (classMatches.size() > 0) { 048 Annotation match = Annotation.getShortestAnnotation(classMatches); 049 matchResult.setResult(MatchResult.NONTRIVIAL_MATCH); 050 return match; 051 } 052 053 Set<Annotation> overlappingAnnotations = iaa.getOverlappingAnnotations(annotation, compareSetName); 054 if (overlappingAnnotations.size() > 0) { 055 Annotation match = Annotation.getShortestAnnotation(overlappingAnnotations); 056 matchResult.setResult(MatchResult.NONTRIVIAL_MATCH); 057 return match; 058 } 059 060 matchResult.setResult(MatchResult.NONTRIVIAL_NONMATCH); 061 return null; 062 } 063 064 public String getName() { 065 return "Overlapping spans matcher"; 066 } 067 068 public String getDescription() { 069 return "Annotations match if they have their spans overlap."; 070 } 071 072 public boolean returnsTrivials() { 073 return false; 074 } 075 076 }