org.apache.ctakes.utils.xcas_comparison
Class XcasFile

java.lang.Object
  extended by org.apache.ctakes.utils.xcas_comparison.XcasFile
All Implemented Interfaces:
java.lang.Cloneable

public class XcasFile
extends java.lang.Object
implements java.lang.Cloneable

An XcasFile wraps all XcasAnnotationss in it and also contains their position information in terms of line and column numbers.

Author:
Mayo Clinic

Field Summary
protected  java.util.Hashtable<java.lang.Integer,XcasAnnotation> annotations
           
protected  java.io.File f
           
protected  java.util.Hashtable<XcasAnnotation,java.lang.String> positions
           
 
Constructor Summary
XcasFile()
          Default constructor.
XcasFile(java.io.File f)
          Constructs an XcasFile with the specified name.
XcasFile(java.lang.String f)
          Constructs an XcasFile with the specified name.
 
Method Summary
 void addAnnotation(int id, XcasAnnotation a)
          Inserts a new annotation with the specified internal id to this XcasFile.
 void addAnnotation(int id, XcasAnnotation a, int lineNum, int colNum)
          Inserts a new annotation, along with its position in the file, to this XcasFile object.
 void addAnnotation(int id, XcasAnnotation a, java.lang.String pos)
          Inserts a new annotation, along with its position in the file, to this XcasFile object.
 java.util.LinkedList<XcasAnnotation> annotationsClone()
           
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Checks whether the specified object has the same set of annotations.
 java.util.Collection<XcasAnnotation> getAllAnnotations()
           
 XcasAnnotation getAnnotation(int id)
          Returns the XcasAnnotation object associated with the specified internal id.
 java.lang.String getFileName()
           
 java.lang.String getPosition(XcasAnnotation a)
          Returns the line and column numbers of the specified XcasAnnotation.
 java.lang.String getPositionOther(XcasAnnotation a)
          Finds an XcasAnnotation with the same attributes as specified, and returns its line and column numbers.
 java.lang.String getPositionOwn(int id)
          Returns the line and column numbers of the XcasAnnotation, specified by the original XCAS internal _id field.
 java.lang.String getPositionOwn(XcasAnnotation a)
          Returns the line and column numbers of the specified XcasAnnotation, which is included in this XcasFile object.
 java.lang.String getPositionSimilar(XcasAnnotation a)
          Finds an XcasAnnotation of the same type as specified, and a same text span, then returns its line and column number.
 boolean hasAnnotation(int id)
          Checks whether this XCAS file has an annotation with the specified id.
 boolean hasAnnotation(XcasAnnotation a)
          Checks whether this XCAS file has the specified XcasAnnotation.
static XcasFile process(java.lang.String f)
          Creates a new XcasFile object from the specified file.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

f

protected java.io.File f

annotations

protected java.util.Hashtable<java.lang.Integer,XcasAnnotation> annotations

positions

protected java.util.Hashtable<XcasAnnotation,java.lang.String> positions
Constructor Detail

XcasFile

public XcasFile()
Default constructor.


XcasFile

public XcasFile(java.lang.String f)
Constructs an XcasFile with the specified name.

Parameters:
f - File name.

XcasFile

public XcasFile(java.io.File f)
Constructs an XcasFile with the specified name.

Parameters:
f - A File object.
Method Detail

process

public static XcasFile process(java.lang.String f)
Creates a new XcasFile object from the specified file. Avoid using this method if you plan to parse multiple files, as this method creates an anonymous XcasProcessor instance each time called, which could be used to parse multiple files.

Parameters:
f - A string containing the XCAS file name.
Returns:
A parsed XcasFile object.

addAnnotation

public void addAnnotation(int id,
                          XcasAnnotation a)
Inserts a new annotation with the specified internal id to this XcasFile.

Parameters:
id - UIMA CAS internal _id.
a - An XcasAnnotation object to add.
See Also:
addAnnotation(int, XcasAnnotation, String), addAnnotation(int, XcasAnnotation, int, int)

addAnnotation

public void addAnnotation(int id,
                          XcasAnnotation a,
                          java.lang.String pos)
Inserts a new annotation, along with its position in the file, to this XcasFile object.

Parameters:
id - UIMA CAS internal _id.
a - An XcasAnnotation object to add.
pos - Line and column number of the specified annotation, in the form of line_number:column_number.

addAnnotation

public void addAnnotation(int id,
                          XcasAnnotation a,
                          int lineNum,
                          int colNum)
Inserts a new annotation, along with its position in the file, to this XcasFile object.

Parameters:
id - UIMA CAS internal _id.
a - An XcasAnnotation object to add.
lineNum - Line number of the specified annotation.
colNum - Column number of the specified annotation.

getAnnotation

public XcasAnnotation getAnnotation(int id)
Returns the XcasAnnotation object associated with the specified internal id.

Parameters:
id - UIMA CAS internal _id.
Returns:
The XcasAnnotation with the specified id.

getAllAnnotations

public java.util.Collection<XcasAnnotation> getAllAnnotations()

getFileName

public java.lang.String getFileName()

getPositionOwn

public java.lang.String getPositionOwn(XcasAnnotation a)
Returns the line and column numbers of the specified XcasAnnotation, which is included in this XcasFile object.

Returns:
A string containing the line and column numbers of the specified object, in the form of line_number:column_number.
See Also:
getPositionOwn(int), getPositionOther(XcasAnnotation)

getPositionOwn

public java.lang.String getPositionOwn(int id)
Returns the line and column numbers of the XcasAnnotation, specified by the original XCAS internal _id field.

Parameters:
id - UIMA CAS internal _id.
Returns:
A string containing the line and column numbers of the specified object, in the form of line_number:column_number.
See Also:
getPositionOwn(XcasAnnotation), getPositionOther(XcasAnnotation)

getPositionOther

public java.lang.String getPositionOther(XcasAnnotation a)
Finds an XcasAnnotation with the same attributes as specified, and returns its line and column numbers.

Returns:
A string containing the line and column numbers of the specified object, in the form of line_number:column_number.
See Also:
getPositionOwn(int), getPositionOwn(XcasAnnotation)

getPosition

public java.lang.String getPosition(XcasAnnotation a)
Returns the line and column numbers of the specified XcasAnnotation.

Do not use this method if you know the specified XcasAnnotation object is in this XcasFile. Instead, use getPositionOwn(XcasAnnotation), which is faster.

Parameters:
a - An
Returns:
A string containing the line and column numbers of the specified object, in the form of line_number:column_number.
See Also:
getPositionOwn(XcasAnnotation), getPositionOther(XcasAnnotation)

getPositionSimilar

public java.lang.String getPositionSimilar(XcasAnnotation a)
Finds an XcasAnnotation of the same type as specified, and a same text span, then returns its line and column number.

Parameters:
a - An XcasAnnotation against which a similar XcasAnnotation in this XcasFile is to be matched.
Returns:
A string containing the line and column numbers of the specified object, in the form of line_number:column_number.
See Also:
getPositionOther(XcasAnnotation)

hasAnnotation

public boolean hasAnnotation(int id)
Checks whether this XCAS file has an annotation with the specified id.

Parameters:
id - UIMA CAS internal _id.
Returns:
true if file has an annotation with the specified id, false otherwise.

hasAnnotation

public boolean hasAnnotation(XcasAnnotation a)
Checks whether this XCAS file has the specified XcasAnnotation. If there is an XcasAnnotation object that has exactly the same type, attributes, and references, return true.

Parameters:
a - An XcasAnnotation to check.
Returns:
true if there is one XcasAnnotation equals the specified one, false otherwise.
See Also:
XcasAnnotation.equals(Object)

equals

public boolean equals(java.lang.Object obj)
Checks whether the specified object has the same set of annotations. First check whether the specified is an XcasFile object. If so, check whether its annotation set is of the same size as in this XcasFile, then check whether these two sets are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - An object to compare to.
Returns:
true if the specified object is an XcasFile object and has a same set of XcasAnnotations, false otherwise.

annotationsClone

public java.util.LinkedList<XcasAnnotation> annotationsClone()

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object