|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gate.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 String |
cleanString(String input)
Return a cleaned version of the input String. |
static String |
cleanStringFor(Document doc,
AnnotationSet anns)
Return the cleaned document text as a String covered by the given annotation set. |
static String |
cleanStringFor(Document doc,
Long start,
Long end)
Return the cleaned document text between the provided offsets. |
static String |
cleanStringFor(Document doc,
SimpleAnnotation ann)
Return the cleaned document text as a String corresponding to the annotation. |
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 AnnotationSet |
getContainedAnnotations(AnnotationSet sourceAnnotationSet,
Annotation containingAnnotation)
Get all the annotations from the source annotation set that lie within the range of the containing annotation. |
static AnnotationSet |
getContainedAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet containingAnnotationSet)
Get all the annotations from the source annotation set that lie within the range of the containing annotation set, i.e. within the offset range between the start of the first annotation in the containing set and the end of the last annotation in the annotation set. |
static AnnotationSet |
getContainedAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet containingAnnotationSet,
String targetType)
Get all the annotations from the source annotation set with a type equal to targetType that lie within the range of the containing annotation set, i.e. within the offset range between the start of the first annotation in the containing set and the end of the last annotation in the annotation set. |
static AnnotationSet |
getContainedAnnotations(AnnotationSet sourceAnnotationSet,
Annotation containingAnnotation,
String targetType)
Get all the annotations of type targetType from the source annotation set that lie within the range of the containing annotation. |
static AnnotationSet |
getCoveringAnnotations(AnnotationSet sourceAnnotationSet,
Annotation coveredAnnotation)
Get all the annotations from the source annotation set that cover the range of the specified annotation. |
static AnnotationSet |
getCoveringAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet coveredAnnotationSet)
Get all the annotations from the source annotation set that cover the range of the specified annotation set. |
static AnnotationSet |
getCoveringAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet coveredAnnotationSet,
String targetType)
Get all the annotations from the source annotation set with a type equal to targetType that cover the range of the specified annotation set. |
static AnnotationSet |
getCoveringAnnotations(AnnotationSet sourceAnnotationSet,
Annotation coveredAnnotation,
String targetType)
Get all the annotations of type targetType from the source annotation set that cover the range of the specified annotation. |
static AnnotationSet |
getOverlappingAnnotations(AnnotationSet sourceAnnotationSet,
Annotation overlappedAnnotation)
Get all the annotations from the source annotation set that partly or totally overlap the range of the specified annotation. |
static AnnotationSet |
getOverlappingAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet overlappedAnnotationSet)
Get all the annotations from the source annotation set that overlap the range of the specified annotation set. |
static AnnotationSet |
getOverlappingAnnotations(AnnotationSet sourceAnnotationSet,
AnnotationSet overlappedAnnotationSet,
String targetType)
Get all the annotations from the source annotation set with a type equal to targetType that partly or completely overlap the range of the specified annotation set. |
static AnnotationSet |
getOverlappingAnnotations(AnnotationSet sourceAnnotationSet,
Annotation overlappedAnnotation,
String targetType)
Get all the annotations of type targetType from the source annotation set that partly or totally overlap the range of the specified annotation. |
static RunningStrategy |
getRunningStrategy(Controller controller,
ProcessingResource pr)
Return the running strategy of the PR in the controller, if the controller is a conditional controller. |
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 boolean |
isEnabled(Controller controller,
ProcessingResource pr)
This method can be used to check if a ProcessingResource has a chance to be run in the given controller with the current settings. |
static boolean |
isLoggedOnce(String message)
Check if a message has already been logged or shown. |
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,
Long start,
Long end)
Returns the document text between the provided offsets. |
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 String cleanStringFor(Document doc, SimpleAnnotation ann)
doc
- the document from which to extract the document textann
- the annotation for which to return the text.
public static String stringFor(Document doc, Long start, Long end)
doc
- the document from which to extract the document textstart
- the start offsetend
- the end offset
public static String cleanStringFor(Document doc, Long start, Long end)
doc
- the document from which to extract the document textstart
- the start offsetend
- the end offset
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 String cleanStringFor(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 String cleanString(String input)
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 AnnotationSet getContainedAnnotations(AnnotationSet sourceAnnotationSet, Annotation containingAnnotation)
sourceAnnotationSet
- the annotation set from which to selectcontainingAnnotation
- the annotation whose range must contain the
selected annotations
public static AnnotationSet getContainedAnnotations(AnnotationSet sourceAnnotationSet, Annotation containingAnnotation, String targetType)
sourceAnnotationSet
- the annotation set from which to selectcontainingAnnotation
- the annotation whose range must contain thetargetType
- the type the selected annotations must have. If the
empty string, no filtering on type is done.
public static AnnotationSet getContainedAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet containingAnnotationSet)
sourceAnnotationSet
- the annotation set from which to selectcontainingAnnotationSet
- the annotation set whose range must contain
the selected annotations
public static AnnotationSet getContainedAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet containingAnnotationSet, String targetType)
sourceAnnotationSet
- the annotation set from which to selectcontainingAnnotationSet
- the annotation set whose range must contain
the selected annotationstargetType
- the type the selected annotations must have
public static AnnotationSet getCoveringAnnotations(AnnotationSet sourceAnnotationSet, Annotation coveredAnnotation)
sourceAnnotationSet
- the annotation set from which to selectcoveredAnnotation
- the annotation whose range must equal or lie within
the selected annotations
public static AnnotationSet getCoveringAnnotations(AnnotationSet sourceAnnotationSet, Annotation coveredAnnotation, String targetType)
sourceAnnotationSet
- the annotation set from which to selectcoveredAnnotation
- the annotation whose range must be coveredtargetType
- the type the selected annotations must have. If the
empty string, no filtering on type is done.
public static AnnotationSet getCoveringAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet coveredAnnotationSet)
sourceAnnotationSet
- the annotation set from which to selectcoveredAnnotationSet
- the annotation set whose range must be covered by
the selected annotations
public static AnnotationSet getCoveringAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet coveredAnnotationSet, String targetType)
sourceAnnotationSet
- the annotation set from which to selectcoveredAnnotationSet
- the annotation set whose range must
be covered by the selected annotationstargetType
- the type the selected annotations must have
public static AnnotationSet getOverlappingAnnotations(AnnotationSet sourceAnnotationSet, Annotation overlappedAnnotation)
sourceAnnotationSet
- the annotation set from which to selectoverlappedAnnotation
- the annotation whose range the selected
annotations must overlap
public static AnnotationSet getOverlappingAnnotations(AnnotationSet sourceAnnotationSet, Annotation overlappedAnnotation, String targetType)
sourceAnnotationSet
- the annotation set from which to selectoverlappedAnnotation
- the annotation whose range the selected
annotations must overlaptargetType
- the type the selected annotations must have. If the
empty string, no filtering on type is done.
public static AnnotationSet getOverlappingAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet overlappedAnnotationSet)
sourceAnnotationSet
- the annotation set from which to selectoverlappedAnnotationSet
- the annotation set whose range must
be overlapped by the selected annotations
public static AnnotationSet getOverlappingAnnotations(AnnotationSet sourceAnnotationSet, AnnotationSet overlappedAnnotationSet, String targetType)
sourceAnnotationSet
- the annotation set from which to selectoverlappedAnnotationSet
- the annotation set whose range must
be overlapped by the selected annotationstargetType
- the type the selected annotations must have
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 boolean isEnabled(Controller controller, ProcessingResource pr)
That means that for a non-conditional controller, the method will return true if the PR is part of the controller. For a conditional controller, the method will return true if it is part of the controller and at least once (if the same PR is contained multiple times) it is not disabled.
controller
- pr
-
public static RunningStrategy getRunningStrategy(Controller controller, ProcessingResource pr)
controller
- pr
-
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 itselfpublic static boolean isLoggedOnce(String message)
message
- - the message that should only be logged or shown once
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |