at.ofai.gate.jape
Class Constraint

java.lang.Object
  extended by at.ofai.gate.jape.Constraint
All Implemented Interfaces:
JapeConstants, gate.creole.ANNIEConstants, java.io.Serializable, java.lang.Cloneable

public class Constraint
extends java.lang.Object
implements JapeConstants, gate.creole.ANNIEConstants, java.io.Serializable, java.lang.Cloneable

An individual annotation/attributes/values/operator expression. It doesn't extend PatternElement, even though it has to "match", because a set of Constraint must be applied together in order to avoid doing separate selectAnnotations calls for each one.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface at.ofai.gate.jape.JapeConstants
APPELT_STYLE, BRILL_STYLE, DEFAULT_PRIORITY, EQUAL, FIRST_STYLE, GREATER, GREATER_OR_EQUAL, INDENT_PADDING, KLEENE_PLUS, KLEENE_QUERY, KLEENE_STAR, LESSER, LESSER_OR_EQUAL, MULTI_SPAN_BINDING, NO_BINDING, NO_KLEENE_OP, NOT_EQUAL, NOT_REGEXP, ONCE_STYLE, REGEXP, SINGLE_SPAN_BINDING
 
Fields inherited from interface gate.creole.ANNIEConstants
ANNOTATION_COREF_FEATURE_NAME, DATE_ANNOTATION_TYPE, DATE_POSTED_ANNOTATION_TYPE, DOCUMENT_COREF_FEATURE_NAME, JOB_ID_ANNOTATION_TYPE, LOCATION_ANNOTATION_TYPE, LOOKUP_ANNOTATION_TYPE, LOOKUP_CLASS_FEATURE_NAME, LOOKUP_INSTANCE_FEATURE_NAME, LOOKUP_LANGUAGE_FEATURE_NAME, LOOKUP_MAJOR_TYPE_FEATURE_NAME, LOOKUP_MINOR_TYPE_FEATURE_NAME, LOOKUP_ONTOLOGY_FEATURE_NAME, MONEY_ANNOTATION_TYPE, ORGANIZATION_ANNOTATION_TYPE, PERSON_ANNOTATION_TYPE, PERSON_GENDER_FEATURE_NAME, PR_NAMES, SENTENCE_ANNOTATION_TYPE, SPACE_TOKEN_ANNOTATION_TYPE, TOKEN_ANNOTATION_TYPE, TOKEN_CATEGORY_FEATURE_NAME, TOKEN_KIND_FEATURE_NAME, TOKEN_LENGTH_FEATURE_NAME, TOKEN_ORTH_FEATURE_NAME, TOKEN_STRING_FEATURE_NAME
 
Constructor Summary
Constraint(java.lang.String annotType)
          Construction from annot type string
 
Method Summary
 void addAttribute(JdmAttribute attr)
          Add an attribute.
 void changeSign()
          Change the sign of the negation flag.
 java.lang.Object clone()
          Need cloning for processing of macro references.
 void finish()
          Finish: replace dynamic data structures with Java arrays; called after parsing.
 java.lang.String getAnnotType()
          Get the type of annnotation we're looking for.
 JdmAttribute[] getAttributeArray()
          Get the attributes that must be present on the matched annotation.
 java.util.LinkedList getAttributeSeq()
          Get the list of attributes that must match the annotation features.
 boolean isNegated()
          Access to negation flag.
 void negate()
          Set negation.
 java.lang.String shortDesc()
           
 boolean subsumes(gate.Document doc, gate.Annotation annot)
          Test if an annotation complies with all features and comparison operators of this constraint's attributes.
 boolean subsumesOne(gate.Document doc, gate.Annotation annot)
          Test if an annotation complies with at least one feature and comparison operators of this constraint's attributes.
protected  boolean subsumesOneOrAll(gate.Document doc, gate.Annotation annot, boolean anded)
          Test if an annotation complies with the features and comparison operators of this constraint's attributes.
 java.lang.String toString()
          Create a string representation of the object.
 java.lang.String toString(java.lang.String pad)
          Create a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constraint

public Constraint(java.lang.String annotType)
Construction from annot type string

Method Detail

negate

public void negate()
Set negation.


isNegated

public boolean isNegated()
Access to negation flag.


changeSign

public void changeSign()
Change the sign of the negation flag.


getAnnotType

public java.lang.String getAnnotType()
Get the type of annnotation we're looking for.


getAttributeSeq

public java.util.LinkedList getAttributeSeq()
Get the list of attributes that must match the annotation features. Attributes are JdmAttribute objects.


getAttributeArray

public JdmAttribute[] getAttributeArray()
Get the attributes that must be present on the matched annotation.


addAttribute

public void addAttribute(JdmAttribute attr)
Add an attribute.


clone

public java.lang.Object clone()
Need cloning for processing of macro references. See comments on PatternElement.clone()

Overrides:
clone in class java.lang.Object

finish

public void finish()
Finish: replace dynamic data structures with Java arrays; called after parsing.


toString

public java.lang.String toString()
Create a string representation of the object.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String pad)
Create a string representation of the object.


shortDesc

public java.lang.String shortDesc()

subsumesOne

public boolean subsumesOne(gate.Document doc,
                           gate.Annotation annot)
Test if an annotation complies with at least one feature and comparison operators of this constraint's attributes.

Parameters:
annot - an annotation
Returns:
true if the annotation tests successfully with the values and operators of at least one attribute of this constraint and false if not.

subsumes

public boolean subsumes(gate.Document doc,
                        gate.Annotation annot)
Test if an annotation complies with all features and comparison operators of this constraint's attributes.

Parameters:
annot - an annotation
Returns:
true if the annotation tests successfully with the values and operators from every attribute of this constraint and false if not.

subsumesOneOrAll

protected boolean subsumesOneOrAll(gate.Document doc,
                                   gate.Annotation annot,
                                   boolean anded)
Test if an annotation complies with the features and comparison operators of this constraint's attributes. Each feature is tested and then a big AND can be done if anded=true, or a big OR if anded=false.

If the constraint is one of the two special cases "@DOCBEGIN" or "@DOCEND" we just check whether the annotation is of the same name (we rely on the document containing an annotation of type "@DOCBEGIN" at offset 0 and "@DOCEND" at the last offset)

Parameters:
annot - an annotation
anded - true: all features must match. false: at least one feature must match.
Returns:
true if the annotation tests successfully with the values and operators from the attribute of this constraint and false if not.