Groovy Documentation

java.gate.yam.format
Class YamFormatter

java.lang.Object
  java.gate.yam.format.YamFormatter

class YamFormatter

Format utility for YAM based on JAPE.

author:
Niraj Aswani


Field Summary
static String EDIT_AT

Annotation type for the Edit annotations.

static String NUM_BLANK_LINES_AFTER_FEATURE_NAME

name of the feature to represent the number of lines after the Edit annotation

static String NUM_BLANK_LINES_BEFORE_FEATURE_NAME

name of the feature to represent the number of lines before the Edit annotation

static String WRAP_AT

Annotation type for the Wrap annotations

static String YAM_PARSER_XGAPP

Yam Parser xgapp file name (relative to web-app/WEB-INF/gate) used if no explicit DocumentProcessor has been provided.

private static DocumentProcessor documentProcessor

DocumentProcessor used to process the GATE document.

static Logger log

Logger

static Map spacesTable

Spaces Table used for storing desired number of min/max/normal spaces before/after the edit annotations

 
Constructor Summary
YamFormatter()

 
Method Summary
private static int calculateIndentLevel(StringBuilder content)

This method counts the indentLevel by looking for white-spaces at the start of the first line.

private static void formatDocument(gate.Document doc, StringBuilder content)

This method formats the document for its white spaces - adding more where needed and deleting where are more than desired.

private static boolean insertNL(StringBuilder content, int nlToAdd, int insertAt)

Inserts new lines (represented by nlToAdd) at the specified position (insertAt)

private static int nlsAfterAnnotation(StringBuilder content, gate.Annotation a, int insertAt)

Removes new lines where more than desired and adds where too few content of the document that should be formatted for new lines Edit annotation which contains information about new lines before and after the annotations (as counted in the original document).

private static void nlsBeforeAnnotation(StringBuilder content, gate.Annotation a, int insertAt, int nlsToPreserve)

Removes new lines where more than desired and adds where too few content of the document that should be formatted for new lines Edit annotation which contains information about new lines before and after the annotations (as counted in the original document).

static void normalise(gate.Document doc, StringBuilder content)

Normalise the spacing in an annotated YAM document.

private static boolean removeNL(StringBuilder content, int nlToRemove, int removeAt, boolean backward)

Removes new lines (represented by nlToRemove) at the specified position (removeAt) indicates if the new lines to delete are in the backward direction if this method carried out changes, false otherwise

static void setDocumentProcessor(DocumentProcessor p)

private static void setupDefaultDocumentProcessor()

Set up a default simple document processor if one has not been configured externally.

static void wrap(StringBuilder inputText, int startOffset, int endOffset, int indentLevel, int textWidth)

Wrap a range of text.

 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Field Detail

EDIT_AT

static final String EDIT_AT
Annotation type for the Edit annotations.


NUM_BLANK_LINES_AFTER_FEATURE_NAME

static final String NUM_BLANK_LINES_AFTER_FEATURE_NAME
name of the feature to represent the number of lines after the Edit annotation


NUM_BLANK_LINES_BEFORE_FEATURE_NAME

static final String NUM_BLANK_LINES_BEFORE_FEATURE_NAME
name of the feature to represent the number of lines before the Edit annotation


WRAP_AT

static final String WRAP_AT
Annotation type for the Wrap annotations


YAM_PARSER_XGAPP

static final String YAM_PARSER_XGAPP
Yam Parser xgapp file name (relative to web-app/WEB-INF/gate) used if no explicit DocumentProcessor has been provided.


documentProcessor

private static DocumentProcessor documentProcessor
DocumentProcessor used to process the GATE document.


log

static Logger log
Logger


spacesTable

static final Map spacesTable
Spaces Table used for storing desired number of min/max/normal spaces before/after the edit annotations


 
Constructor Detail

YamFormatter

YamFormatter()


 
Method Detail

calculateIndentLevel

private static int calculateIndentLevel(StringBuilder content)
This method counts the indentLevel by looking for white-spaces at the start of the first line.
param:
stOffset
param:
content
return:


formatDocument

private static void formatDocument(gate.Document doc, StringBuilder content)
This method formats the document for its white spaces - adding more where needed and deleting where are more than desired.
param:
doc
param:
content


insertNL

private static boolean insertNL(StringBuilder content, int nlToAdd, int insertAt)
Inserts new lines (represented by nlToAdd) at the specified position (insertAt)
param:
content
param:
nlToAdd
param:
insertAt
return:
true if this method carried out changes, false otherwise


nlsAfterAnnotation

private static int nlsAfterAnnotation(StringBuilder content, gate.Annotation a, int insertAt)
Removes new lines where more than desired and adds where too few
param:
content content of the document that should be formatted for new lines
param:
a Edit annotation which contains information about new lines before and after the annotations (as counted in the original document).
param:
insertAt position where the nls should be added or removed


nlsBeforeAnnotation

private static void nlsBeforeAnnotation(StringBuilder content, gate.Annotation a, int insertAt, int nlsToPreserve)
Removes new lines where more than desired and adds where too few
param:
content content of the document that should be formatted for new lines
param:
a Edit annotation which contains information about new lines before and after the annotations (as counted in the original document).
param:
insertAt position where the nls should be added or removed
param:
nlsToPreserve number of new lines must be preserved


normalise

public static void normalise(gate.Document doc, StringBuilder content)
Normalise the spacing in an annotated YAM document.
param:
doc a GATE doc that's annotated with all the YAM constituents
param:
content the content that the GATE doc was built from
return:
the StringBuilder is adapted


removeNL

private static boolean removeNL(StringBuilder content, int nlToRemove, int removeAt, boolean backward)
Removes new lines (represented by nlToRemove) at the specified position (removeAt)
param:
content
param:
nlToRemove
param:
removeAt
param:
backward indicates if the new lines to delete are in the backward direction
param:
true if this method carried out changes, false otherwise


setDocumentProcessor

public static void setDocumentProcessor(DocumentProcessor p)


setupDefaultDocumentProcessor

private static void setupDefaultDocumentProcessor()
Set up a default simple document processor if one has not been configured externally.


wrap

public static void wrap(StringBuilder inputText, int startOffset, int endOffset, int indentLevel, int textWidth)
Wrap a range of text.
param:
inputText buffer that contains a range to modify
param:
startOffset start offset of the range to wrap
param:
endOffset end offset of the range to wrap
param:
indentLevel left margin for the range
param:
textWidth wrap margin


 

Groovy Documentation