at.ofai.gate
Class JAPEUtils

java.lang.Object
  extended by at.ofai.gate.JAPEUtils

public class JAPEUtils
extends java.lang.Object

This class makes it easier to access and handle document features and annotations from within the Java code in a JAPE RHS. Remember that the following variables are usable in the Java code present in the RHS:

Document doc
that is being processed
java.util.Map bindings
the label bindings created in the LHS
AnnotationSet annotations
the annotations
AnnotationSet inputAS, outputAS
the input and output annotation sets
Ontology ontology
the ontology, if one is used. If yes, the equality operator will work differently on any annotation feature that is called "class"
In order to use the functions defined in here, the ofai plugin must be loaded and the JAPE rule RHS must call each function with its full package and class name, for example: at.ofai.gate.JAPEUtils.addToFeatureInt(doc,"myFeature",3);


Constructor Summary
JAPEUtils()
           
 
Method Summary
static void addToFeatureDouble(gate.Document doc, java.lang.String theKey, double byThis)
          Increments a document feature of type double.
static void addToFeatureLong(gate.Document doc, java.lang.String theKey, long byThis)
          Increments the value of a document feature of type long by a specific amount.
static java.lang.String annotationString(gate.Document doc, gate.Annotation annotation)
          Returns the string of the annotation.
static int annotationStringLength(gate.Document doc, gate.Annotation annotation)
          Returns the string length of the annotation.
static void appendToFeatureString(gate.Document doc, java.lang.String theKey, java.lang.String appendThis)
          Appends a string to a feature of type string.
static int countAnnotationNums(gate.Document doc, gate.Annotation annotation)
          Returns the count of all numbers in the annotation.
static gate.Annotation getAnnotation4Binding(java.util.Map bindings, java.lang.String bindingname)
          Returns an annotation for a JAPE rule binding.
static double getFeatureDouble(gate.Document doc, java.lang.String theKey)
          Gets the value of a document feature of type double.
static java.lang.Long getFeatureLong(gate.Document doc, java.lang.String theKey)
          Gets the value of a document feature of type long.
static java.lang.String getFeatureString(gate.Document doc, java.lang.String theKey)
          Gets the value of a feature of type string.
static void removeAnnotationsFromAnnotation(gate.Document doc, gate.AnnotationSet inset, gate.Annotation annotation, java.lang.String sInside, java.lang.String sRemove)
          Removes Annotations inside an Annotation
static void removeFeature(gate.Document doc, java.lang.String name)
           
static void setFeatureDouble(gate.Document doc, java.lang.String theKey, double theValue)
          Sets the value of a document feature of type double.
static void setFeatureLong(gate.Document doc, java.lang.String theKey, long theValue)
          Sets the value of a document feature of type long.
static void setFeatureString(gate.Document doc, java.lang.String theKey, java.lang.String theValue)
          Sets the value of a feature of type string.
static java.lang.String toXML(java.lang.String tagName, java.lang.String theValue)
          Formats a string as XML.
static java.lang.String toXMLAnnotationAnnotations(gate.Document doc, gate.AnnotationSet inset, gate.Annotation annotation, java.lang.String namelist)
          Formats annotations within an annotation as XML.
static java.lang.String toXMLAnnotationFeatures(gate.Annotation annotation)
          Creates a XML chunk for an annotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JAPEUtils

public JAPEUtils()
Method Detail

addToFeatureLong

public static void addToFeatureLong(gate.Document doc,
                                    java.lang.String theKey,
                                    long byThis)
Increments the value of a document feature of type long by a specific amount.

If the feature does not exist yet, it will be created and assumed to be 0.

Example: at.ofai.gate.JAPEUtils.addToFeatureInt(doc,"myFeature",12);

Parameters:
doc - the document that contains the feature
theKey - the name of the feature
byThis - the integer value by which to increment the original value.

setFeatureLong

public static void setFeatureLong(gate.Document doc,
                                  java.lang.String theKey,
                                  long theValue)
Sets the value of a document feature of type long.

Parameters:
doc - the document for which the feature is being set
theKey - the name of the feature
theValue - the value to which the feature is set

getFeatureLong

public static java.lang.Long getFeatureLong(gate.Document doc,
                                            java.lang.String theKey)
Gets the value of a document feature of type long.

Parameters:
doc - the document that contains the feature
theKey - the name of the feature

addToFeatureDouble

public static void addToFeatureDouble(gate.Document doc,
                                      java.lang.String theKey,
                                      double byThis)
Increments a document feature of type double.

Parameters:
doc - the document for which to set the feature
theKey - the name of the feature
byThis - the increment value

setFeatureDouble

public static void setFeatureDouble(gate.Document doc,
                                    java.lang.String theKey,
                                    double theValue)
Sets the value of a document feature of type double.

Parameters:
doc - the document that contains the feature
theKey - the name of the feature
theValue - the value

getFeatureDouble

public static double getFeatureDouble(gate.Document doc,
                                      java.lang.String theKey)
Gets the value of a document feature of type double.

Parameters:
doc - the document that contains the feature.
theKey - the name of the feature.

appendToFeatureString

public static void appendToFeatureString(gate.Document doc,
                                         java.lang.String theKey,
                                         java.lang.String appendThis)
Appends a string to a feature of type string.

If the feature does not exist it is treated as if it would contain the empty string.

Parameters:
doc - the document that contains the feature.
theKey - the name of the feature.
appendThis - the string value that is appended to the end of the existing value.

setFeatureString

public static void setFeatureString(gate.Document doc,
                                    java.lang.String theKey,
                                    java.lang.String theValue)
Sets the value of a feature of type string.

Parameters:
doc - the document that contains the feature.
theKey - the name of the feature.
theValue - the string to be used

getFeatureString

public static java.lang.String getFeatureString(gate.Document doc,
                                                java.lang.String theKey)
Gets the value of a feature of type string.

Parameters:
doc - the document that contains the feature.
theKey - the name of the feature.

removeFeature

public static void removeFeature(gate.Document doc,
                                 java.lang.String name)

toXML

public static java.lang.String toXML(java.lang.String tagName,
                                     java.lang.String theValue)
Formats a string as XML.

Parameters:
tagName - the tagname that will enclose the string.
theValue - the string value to enclose in the tag.

toXMLAnnotationFeatures

public static java.lang.String toXMLAnnotationFeatures(gate.Annotation annotation)
Creates a XML chunk for an annotation. This returns an XML chunk that contains the values of the annotation features enclosed in tags that correspond to the feature names and that all enclosed in tags that correspond to the annotation type.

Example: the annotation Person = { firstname = "John", lastname = "Smith" } will be converted to <pre><Person><firstname>John</firstname> <lastname>Smith</lastname></Person>

Parameters:
annotation - the annotation of which the type name will be used as tagname and the features will be used as enclosed tags.

annotationStringLength

public static int annotationStringLength(gate.Document doc,
                                         gate.Annotation annotation)
Returns the string length of the annotation.

Parameters:
doc - the document that contains the annotaion.
annotation - the document for which to generate the XML.

annotationString

public static java.lang.String annotationString(gate.Document doc,
                                                gate.Annotation annotation)
Returns the string of the annotation.

Parameters:
doc - the document that contains the annotaion.
annotation - the document for which to generate the XML.

getAnnotation4Binding

public static gate.Annotation getAnnotation4Binding(java.util.Map bindings,
                                                    java.lang.String bindingname)
Returns an annotation for a JAPE rule binding.

This function takes the bindings variable and the name of the binding and returns the corresponding annotation.

Parameters:
bindings - the bindings datastructure from the JAPE rule LHS.
bindingname - the name of the binding from the JAPE rule LHS.

countAnnotationNums

public static int countAnnotationNums(gate.Document doc,
                                      gate.Annotation annotation)
Returns the count of all numbers in the annotation.

Parameters:
doc - the document that contains the annotaion.
annotation - the document for which to generate the XML.

removeAnnotationsFromAnnotation

public static void removeAnnotationsFromAnnotation(gate.Document doc,
                                                   gate.AnnotationSet inset,
                                                   gate.Annotation annotation,
                                                   java.lang.String sInside,
                                                   java.lang.String sRemove)
Removes Annotations inside an Annotation

Parameters:
doc - the document that contains the annotaion.
inset - the input annotation set - usually the variable inputAS.
annotation - the document.
sInsode - the Name of the annotation.
sRemove - a string that contains the names of those annotations that should be removed, seperated by commas (but not additional whitespace)

toXMLAnnotationAnnotations

public static java.lang.String toXMLAnnotationAnnotations(gate.Document doc,
                                                          gate.AnnotationSet inset,
                                                          gate.Annotation annotation,
                                                          java.lang.String namelist)
Formats annotations within an annotation as XML.

This returns a string formatted as XML where the outermost tag corresponds to the name of the annotation passed as a parameter. This tag encloses the string of the annotation and in addition nested tags for all contained annotations whose names are mentioned in the namelist parameter.

The XML tags are sorted the same way like the annotations are found inside the document.

Parameters:
doc - the document that contains the annotaion.
inset - the input annotation set - usually the variable inputAS.
annotation - the document for which to generate the XML.
namelist - a string that contains the names of those annotations that should be included, seperated by commas (but not additional whitespace)