|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgate.Utils
public class Utils
Various utility methods to make often-needed tasks more easy and
using up less code. In Java code (or JAPE grammars) you may wish to
import static gate.Utils.* to access these methods without
having to qualify them with a class name. In Groovy code, this class can be
used as a category to inject each utility method into the class of its first
argument, e.g.
Document doc = // ...
Annotation ann = // ...
use(gate.Utils) {
println "Annotation has ${ann.length()} characters"
println "and covers the string \"${doc.stringFor(ann)}\""
}
| Field Summary | |
|---|---|
static OffsetComparator |
OFFSET_COMPARATOR
A single instance of OffsetComparator that can be used by any code
that requires one. |
| Constructor Summary | |
|---|---|
Utils()
|
|
| Method Summary | |
|---|---|
static DocumentContent |
contentFor(SimpleDocument doc,
AnnotationSet anns)
Return the DocumentContent covered by the given annotation set. |
static DocumentContent |
contentFor(SimpleDocument doc,
SimpleAnnotation ann)
Return the DocumentContent corresponding to the annotation. |
static Long |
end(AnnotationSet as)
Get the end offset of an annotation set. |
static Long |
end(SimpleAnnotation a)
Get the end offset of an annotation. |
static Long |
end(SimpleDocument d)
Get the end offset of a document. |
static FeatureMap |
featureMap(Object... values)
Create a feature map from an array of values. |
static AnnotationSet |
getAnnotationsAtOffset(AnnotationSet annotationSet,
Long atOffset)
Return a the subset of annotations from the given annotation set that start exactly at the given offset. |
static List<Annotation> |
inDocumentOrder(AnnotationSet as)
Return a List containing the annotations in the given annotation set, in document order (i.e. increasing order of start offset). |
static int |
length(Document doc)
Return the length of the document as an int -- if the content is too long for an int, the method will throw a GateRuntimeException. |
static int |
length(SimpleAnnotation ann)
Return the length of the document content covered by an Annotation as an int -- if the content is too long for an int, the method will throw a GateRuntimeException. |
static long |
lengthLong(Document doc)
Return the length of the document as a long. |
static long |
lengthLong(SimpleAnnotation ann)
Return the length of the document content covered by an Annotation as a long. |
static void |
logOnce(org.apache.log4j.Logger logger,
org.apache.log4j.Level level,
String message)
Issue a message to the log but only if the same message has not been logged already in the same GATE session. |
static Long |
start(AnnotationSet as)
Get the start offset of an annotation set. |
static Long |
start(SimpleAnnotation a)
Get the start offset of an annotation. |
static Long |
start(SimpleDocument d)
Get the start offset of a document (i.e. 0L). |
static String |
stringFor(Document doc,
AnnotationSet anns)
Return the document text as a String covered by the given annotation set. |
static String |
stringFor(Document doc,
SimpleAnnotation ann)
Return the document text as a String corresponding to the annotation. |
static FeatureMap |
toFeatureMap(Map map)
Create a feature map from an existing map (typically one that does not itself implement FeatureMap). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final OffsetComparator OFFSET_COMPARATOR
OffsetComparator that can be used by any code
that requires one.
| Constructor Detail |
|---|
public Utils()
| Method Detail |
|---|
public static int length(SimpleAnnotation ann)
ann - the annotation for which to determine the length
public static long lengthLong(SimpleAnnotation ann)
ann - the annotation for which to determine the length
public static int length(Document doc)
doc - the document for which to determine the length
public static long lengthLong(Document doc)
doc - the document for which to determine the length
public static DocumentContent contentFor(SimpleDocument doc,
SimpleAnnotation ann)
Note: the DocumentContent object returned will also contain the original content which can be accessed using the getOriginalContent() method.
doc - the document from which to extract the contentann - the annotation for which to return the content.
public static String stringFor(Document doc,
SimpleAnnotation ann)
doc - the document from which to extract the document textann - the annotation for which to return the text.
public static DocumentContent contentFor(SimpleDocument doc,
AnnotationSet anns)
Note: the DocumentContent object returned will also contain the original content which can be accessed using the getOriginalContent() method.
doc - the document from which to extract the contentanns - the annotation set for which to return the content.
public static String stringFor(Document doc,
AnnotationSet anns)
doc - the document from which to extract the document textanns - the annotation set for which to return the text.
public static Long start(SimpleAnnotation a)
public static Long start(AnnotationSet as)
public static Long start(SimpleDocument d)
public static Long end(SimpleAnnotation a)
public static Long end(AnnotationSet as)
public static Long end(SimpleDocument d)
public static AnnotationSet getAnnotationsAtOffset(AnnotationSet annotationSet,
Long atOffset)
annotationSet - the set of annotations from which to selectatOffset - the offset where the annoation to be returned should start
public static List<Annotation> inDocumentOrder(AnnotationSet as)
as - the annotation set
as in document
order.public static FeatureMap featureMap(Object... values)
values - an even number of items, alternating keys and values.
public static FeatureMap toFeatureMap(Map map)
map - the map to convert.
public static void logOnce(org.apache.log4j.Logger logger,
org.apache.log4j.Level level,
String message)
logger - - the logger instance to uselevel - - the severity level for the messagemessage - - the message itself
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||