![JAR search and dependency download from the Maven repository](/logo.png)
it.unipi.di.acube.batframework.data.Annotation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bat-framework Show documentation
Show all versions of bat-framework Show documentation
A framework to compare entity annotation systems.
The newest version!
/**
* (C) Copyright 2012-2013 A-cube lab - Università di Pisa - Dipartimento di Informatica.
* BAT-Framework is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* BAT-Framework is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with BAT-Framework. If not, see .
*/
package it.unipi.di.acube.batframework.data;
import it.unipi.di.acube.batframework.utils.AnnotationException;
import it.unipi.di.acube.batframework.utils.WikipediaInterface;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
/**
* An annotation is an association between a mention in a text and a concept.
*
*/
public class Annotation extends Tag implements Serializable, Cloneable{
private static final long serialVersionUID = 1L;
private Mention m;
public Annotation(int position, int length, int wikipediaArticle) throws AnnotationException{
super(wikipediaArticle);
this.m = new Mention(position, length);
if (position < 0) throw new AnnotationException("Annotation with negative position.");
}
public int getPosition(){
return m.getPosition();
}
public int getLength() {
return m.getLength();
}
public int getEnd() {
return m.getEnd();
}
@Override public boolean equals(Object a){
Annotation ann = (Annotation) a;
return (m.equals(ann.m) && this.getConcept() == ann.getConcept());
}
@Override public int hashCode() {
return (this.getConcept()^m.hashCode());
}
public static void prefetchRedirectList(List> annotations, WikipediaInterface api) throws IOException{
/** Prefetch redirect values */
List widsToCheck = new Vector();
for (HashSet s : annotations)
for (E a : s)
widsToCheck.add(a.getConcept());
try {
api.prefetchWids(widsToCheck);
} catch (Exception e){
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
@Override
public int compareTo(Tag o) {
if (o instanceof Annotation)
return this.getPosition() - ((Annotation)o).getPosition();
return super.compareTo(o);
}
@Override public Object clone(){
return new Annotation(this.getPosition(), this.getLength(), this.getConcept());
}
public boolean overlaps(Annotation t) {
return m.overlaps(t.m);
}
public boolean overlaps(Mention men) {
return m.overlaps(men);
}
public static HashSet deleteOverlappingAnnotations(HashSet anns) {
Vector annsList = new Vector(anns);
HashSet res = new HashSet();
Collections.sort(annsList);
for (int i=0; i%d", m.toString(), this.getConcept());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy