at.ofai.gate.japebackrefs
Class ValueRef

java.lang.Object
  extended by at.ofai.gate.japebackrefs.ValueRef
All Implemented Interfaces:
gate.jape.constraint.ConstraintPredicate, Serializable

public class ValueRef
extends Object
implements gate.jape.constraint.ConstraintPredicate

A ConstraintPredicate that makes it possible to use value back-references in JAPE rules.

To use this, add the full name of this class to the list for the operators initialisation parameter or use the JAPEBackRefs PR that comes with this plugin.

In the JAPE grammer, use the valueref operator like this:

{Token valueref {Token.string == "refname"}}
This will either assign the current value of the string feature to the reference name "refname" or if a value is already assigned, check that the value of the feature is identical to what is already assigned. If the reference name does not have a value assigned yet, the match will always succeed. If a value is already assigned, the match will only succeed if the feature value is identical (equals) the value stored for the reference name. A reference remains stored between rules, phases and even documents until it is explicitly reset using the "!=" operator instead of "==" like this:
{Token valueref {Token.string != "refname"}}
This will first make sure that any previous value for "refname" is removed and then assign the value for the feature string to the reference name.

The following example will match sequences of two tokens where the string and pos features are identical between both:

{Token valueref {Token.string != "sref"}, Token valueref {Token.pos != "pref"}}
 {Token valueref {Token.string != "sref"}, Token valueref {Token.pos != "pref"}}

Note: the annotation type in the constraint to the right of "valueref" is ignored, only the annotation type to the left of "valueref" is used for accessing the feature. However, you have to specify an annotation type to make the JAPE syntax checker happy, and to minimize confusion, it is best to use the same annotation type for both left and right of "valueref".

Author:
Johann Petrak
See Also:
Serialized Form

Field Summary
protected  gate.jape.constraint.AnnotationAccessor accessor
           
protected  String featureName
           
protected  String referenceName
           
protected  boolean resetReference
           
protected  Object value
           
 
Fields inherited from interface gate.jape.constraint.ConstraintPredicate
EQUAL, GREATER, GREATER_OR_EQUAL, LESSER, LESSER_OR_EQUAL, NOT_EQUAL, NOT_REGEXP_FIND, NOT_REGEXP_MATCH, REGEXP_FIND, REGEXP_MATCH
 
Constructor Summary
ValueRef()
           
ValueRef(gate.jape.constraint.AnnotationAccessor accessor, Object value)
           
 
Method Summary
 gate.jape.constraint.AnnotationAccessor getAccessor()
           
 String getOperator()
           
 Object getValue()
           
 boolean matches(gate.Annotation annot, gate.AnnotationSet context)
           
 void setAccessor(gate.jape.constraint.AnnotationAccessor accessor)
           
 void setValue(Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

accessor

protected gate.jape.constraint.AnnotationAccessor accessor

value

protected Object value

referenceName

protected String referenceName

featureName

protected String featureName

resetReference

protected boolean resetReference
Constructor Detail

ValueRef

public ValueRef()

ValueRef

public ValueRef(gate.jape.constraint.AnnotationAccessor accessor,
                Object value)
Method Detail

matches

public boolean matches(gate.Annotation annot,
                       gate.AnnotationSet context)
                throws gate.util.GateRuntimeException
Specified by:
matches in interface gate.jape.constraint.ConstraintPredicate
Throws:
gate.util.GateRuntimeException

setAccessor

public void setAccessor(gate.jape.constraint.AnnotationAccessor accessor)
Specified by:
setAccessor in interface gate.jape.constraint.ConstraintPredicate

getAccessor

public gate.jape.constraint.AnnotationAccessor getAccessor()
Specified by:
getAccessor in interface gate.jape.constraint.ConstraintPredicate

setValue

public void setValue(Object value)
Specified by:
setValue in interface gate.jape.constraint.ConstraintPredicate

getValue

public Object getValue()
Specified by:
getValue in interface gate.jape.constraint.ConstraintPredicate

getOperator

public String getOperator()
Specified by:
getOperator in interface gate.jape.constraint.ConstraintPredicate