gate.annotation
Class AnnotationDiff

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--gate.creole.AbstractVisualResource
                                |
                                +--gate.annotation.AnnotationDiff
All Implemented Interfaces:
Accessible, FeatureBearer, ImageObserver, MenuContainer, Resource, Serializable, VisualResource

public class AnnotationDiff
extends AbstractVisualResource

This class compare two annotation sets on annotation type given by the AnnotationSchema object. It also deals with graphic representation of the result.

See Also:
Serialized Form

Inner Class Summary
 class AnnotationDiff.AnnotationDiffCellRenderer
          This class defines a Cell renderer for the AnnotationDiff table
protected  class AnnotationDiff.AnnotationDiffTableModel
          A custom table model used to render a table containing the two annotation sets.
(package private)  class AnnotationDiff.AnnotationSetComparator
           
protected  class AnnotationDiff.DiffSetElement
          This class is used for internal purposes.
 
Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent, JComponent.ActionStandin, JComponent.IntVector, JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.AWTTreeLock
 
Field Summary
private  AnnotationSchema annotationSchema
          The annotation schema object used to get the annotation name
private  String annotationTypeForFalsePositive
          This string represents the type of annotations used to play the roll of total number of words needed to calculate the False Positive.
private  Color BLACK
           
private  Color BLUE
           
private  Color[] colors
           
 int CORRECT_TYPE
           
private static boolean DEBUG
          Debug flag
 int DEFAULT_TYPE
           
private  Set diffSet
          Used to represent the result of diff.
private  XJTable diffTable
          The components that will stay into diffPanel
private  double falsePositiveAverage
           
private  double falsePositiveLenient
           
private  double falsePositiveStrict
          The False positive (see NLP Information Extraction)
private  double fMeasureAverage
           
private  double fMeasureLenient
           
private  double fMeasureStrict
          The F-measure and weight (see NLP Information Extraction)
protected static NumberFormat formatter
          A number formater for displaying precision and recall
private  Color GREEN
           
private  List keyAnnotList
          This lists are created from keyAnnotationSet and responseAnnotationSet
private  Document keyDocument
          This document contains the key annotation set which is taken as reference in comparison
private  Set keyPartiallySet
          These fields are used in doDiff() and detectKey(Response)Type()
 int MAX_TYPES
          Fields used to describe the type of annotations
 int MISSING_TYPE
           
 int NULL_TYPE
           
 int PARTIALLY_CORRECT_TYPE
           
private  double precisionAverage
           
private  double precisionLenient
           
private  double precisionStrict
          The Precision value (see NLP Information Extraction)
private  double recallAverage
           
private  double recallLenient
           
private  double recallStrict
          The Recall value (see NLP Information Extraction)
private  Color RED
           
private  List responseAnnotList
           
private  Document responseDocument
          This document contains the response annotation set which is being compared against the key annotation set.
private  Set responsePartiallySet
           
(package private)  JScrollPane scrollPane
           
 int SPURIOUS_TYPE
           
private  int[] typeCounter
          Used to store the no.
static double weight
           
private  Color WHITE
           
private  Color YELLOW
           
 
Fields inherited from class gate.creole.AbstractVisualResource
features
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AnnotationDiff()
          Constructs a AnnotationDif
 
Method Summary
private  void addToDiffset(AnnotationDiff.DiffSetElement aDiffSetElement)
          This method add an DiffsetElement to the DiffSet and also counts the number of compatible, partialCompatible, Incorect and Missing annotations.
protected  void arangeAllComponents()
          This method creates the graphic components and aranges them on this JPanel
private  int detectKeyType(Annotation anAnnot)
          Decide what type is the keyAnnotation (DEFAULT_TYPE, MISSING or NULL_TYPE) This method must be applied only on annotation from key set.
private  int detectResponseType(Annotation anAnnot)
          Decide what type is the responseAnnotation (PARTIALLY_CORRECT_TYPE, SPURIOUS or NULL_TYPE) This method must be applied only on annotation from response set.
protected  void doDiff(List aKeyAnnotList, List aResponseAnnotList)
          This method is the brain of the AnnotationSet diff and creates a set with diffSetElement objects.
 AnnotationSchema getAnnotationSchema()
           
 String getAnnotationTypeForFalsePositive()
          Gets the annotation type needed to calculate the falsePossitive measure
 double getFalsePositiveAverage()
           
 double getFalsePositiveLenient()
           
 double getFalsePositiveStrict()
           
 double getFMeasureAverage()
           
 double getFMeasureLenient()
           
 double getFMeasureStrict()
           
 Document getKeyDocument()
           
 double getPrecisionAverage()
           
 double getPrecisionLenient()
           
 double getPrecisionStrict()
           
 double getRecallAverage()
           
 double getRecallLenient()
           
 double getRecallStrict()
           
 Resource init()
          This method does the diff, Precision,Recall,FalsePositive calculation and so on.
protected  void printStructure(Set aDiffSet)
          Used internally for debugging
 void setAnnotationSchema(AnnotationSchema anAnnotationSchema)
           
 void setAnnotationTypeForFalsePositive(String anAnnotType)
          Sets the annotation type needed to calculate the falsePossitive measure
 void setKeyDocument(Document aKeyDocument)
          Sets the keyDocument in AnnotDiff
 void setResponseDocument(Document aResponseDocument)
           
 
Methods inherited from class gate.creole.AbstractVisualResource
getFeatures, setFeatures
 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface gate.util.FeatureBearer
getName, setName
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

keyDocument

private Document keyDocument
This document contains the key annotation set which is taken as reference in comparison

responseDocument

private Document responseDocument
This document contains the response annotation set which is being compared against the key annotation set.

annotationSchema

private AnnotationSchema annotationSchema
The annotation schema object used to get the annotation name

precisionStrict

private double precisionStrict
The Precision value (see NLP Information Extraction)

precisionLenient

private double precisionLenient

precisionAverage

private double precisionAverage

recallStrict

private double recallStrict
The Recall value (see NLP Information Extraction)

recallLenient

private double recallLenient

recallAverage

private double recallAverage

falsePositiveStrict

private double falsePositiveStrict
The False positive (see NLP Information Extraction)

falsePositiveLenient

private double falsePositiveLenient

falsePositiveAverage

private double falsePositiveAverage

fMeasureStrict

private double fMeasureStrict
The F-measure and weight (see NLP Information Extraction)

fMeasureLenient

private double fMeasureLenient

fMeasureAverage

private double fMeasureAverage

weight

public static double weight

annotationTypeForFalsePositive

private String annotationTypeForFalsePositive
This string represents the type of annotations used to play the roll of total number of words needed to calculate the False Positive.

formatter

protected static NumberFormat formatter
A number formater for displaying precision and recall

diffTable

private XJTable diffTable
The components that will stay into diffPanel

diffSet

private Set diffSet
Used to represent the result of diff. See DiffSetElement class.

keyPartiallySet

private Set keyPartiallySet
These fields are used in doDiff() and detectKey(Response)Type()

responsePartiallySet

private Set responsePartiallySet

keyAnnotList

private List keyAnnotList
This lists are created from keyAnnotationSet and responseAnnotationSet

responseAnnotList

private List responseAnnotList

MAX_TYPES

public final int MAX_TYPES
Fields used to describe the type of annotations

NULL_TYPE

public final int NULL_TYPE

DEFAULT_TYPE

public final int DEFAULT_TYPE

CORRECT_TYPE

public final int CORRECT_TYPE

PARTIALLY_CORRECT_TYPE

public final int PARTIALLY_CORRECT_TYPE

SPURIOUS_TYPE

public final int SPURIOUS_TYPE

MISSING_TYPE

public final int MISSING_TYPE

RED

private final Color RED

GREEN

private final Color GREEN

WHITE

private final Color WHITE

BLUE

private final Color BLUE

YELLOW

private final Color YELLOW

BLACK

private final Color BLACK

colors

private Color[] colors

scrollPane

JScrollPane scrollPane

typeCounter

private int[] typeCounter
Used to store the no. of annotations from response,identified as belonging to one of the previous types.
Constructor Detail

AnnotationDiff

public AnnotationDiff()
Constructs a AnnotationDif
Method Detail

setAnnotationTypeForFalsePositive

public void setAnnotationTypeForFalsePositive(String anAnnotType)
Sets the annotation type needed to calculate the falsePossitive measure
Parameters:
anAnnotType - is the annotation type needed to calculate a special mesure called falsePossitive. Usualy the value is "token", but it can be any other string with the same semantic.

getAnnotationTypeForFalsePositive

public String getAnnotationTypeForFalsePositive()
Gets the annotation type needed to calculate the falsePossitive measure
Returns:
annotation type needed to calculate a special mesure called falsePossitive.

setKeyDocument

public void setKeyDocument(Document aKeyDocument)
Sets the keyDocument in AnnotDiff
Parameters:
aKeyDocument - The GATE document used as a key in annotation diff.

getKeyDocument

public Document getKeyDocument()
Returns:
the keyDocument used in AnnotDiff process

getPrecisionStrict

public double getPrecisionStrict()
Returns:
the precisionStrict field

getPrecisionLenient

public double getPrecisionLenient()
Returns:
the precisionLenient field

getPrecisionAverage

public double getPrecisionAverage()
Returns:
the precisionAverage field

getFMeasureStrict

public double getFMeasureStrict()
Returns:
the fMeasureStrict field

getFMeasureLenient

public double getFMeasureLenient()
Returns:
the fMeasureLenient field

getFMeasureAverage

public double getFMeasureAverage()
Returns:
the fMeasureAverage field

getRecallStrict

public double getRecallStrict()
Returns:
the recallStrict field

getRecallLenient

public double getRecallLenient()
Returns:
the recallLenient field

getRecallAverage

public double getRecallAverage()
Returns:
the recallAverage field

getFalsePositiveStrict

public double getFalsePositiveStrict()
Returns:
the falsePositiveStrict field

getFalsePositiveLenient

public double getFalsePositiveLenient()
Returns:
the falsePositiveLenient field

getFalsePositiveAverage

public double getFalsePositiveAverage()
Returns:
the falsePositiveAverage field

setResponseDocument

public void setResponseDocument(Document aResponseDocument)
Parameters:
aResponseDocument - the GATE response Document containing the annotation Set being compared against the annotation from the keyDocument.

setAnnotationSchema

public void setAnnotationSchema(AnnotationSchema anAnnotationSchema)
Parameters:
anAnnotationSchema - the annotation type being compared. This type is found in annotationSchema object as field AnnotationSchema.getAnnotationName(). If is null then AnnotDiff will throw an exception when it comes to do the diff.

getAnnotationSchema

public AnnotationSchema getAnnotationSchema()
Returns:
the annotation schema object used in annotation diff process

init

public Resource init()
              throws ResourceInstantiationException
This method does the diff, Precision,Recall,FalsePositive calculation and so on.
Overrides:
init in class AbstractVisualResource

arangeAllComponents

protected void arangeAllComponents()
This method creates the graphic components and aranges them on this JPanel

printStructure

protected void printStructure(Set aDiffSet)
Used internally for debugging

doDiff

protected void doDiff(List aKeyAnnotList,
                      List aResponseAnnotList)
This method is the brain of the AnnotationSet diff and creates a set with diffSetElement objects.
Parameters:
aKeyAnnotList - a list containing the annotations from key. If this param is null then the method will simply return and will not do a thing.
aResponseAnnotList - a list containing the annotation from response. If this param is null the method will return.

detectKeyType

private int detectKeyType(Annotation anAnnot)
Decide what type is the keyAnnotation (DEFAULT_TYPE, MISSING or NULL_TYPE) This method must be applied only on annotation from key set.
Parameters:
anAnnot - is an annotation from the key set.
Returns:
three possible value(DEFAULT_TYPE, MISSING or NULL_TYPE)

detectResponseType

private int detectResponseType(Annotation anAnnot)
Decide what type is the responseAnnotation (PARTIALLY_CORRECT_TYPE, SPURIOUS or NULL_TYPE) This method must be applied only on annotation from response set.
Parameters:
anAnnot - is an annotation from the key set.
Returns:
three possible value(PARTIALLY_CORRECT_TYPE, SPURIOUS or NULL_TYPE)

addToDiffset

private void addToDiffset(AnnotationDiff.DiffSetElement aDiffSetElement)
This method add an DiffsetElement to the DiffSet and also counts the number of compatible, partialCompatible, Incorect and Missing annotations.