gate.jape
Class Constraint

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

public class Constraint
extends Object
implements JapeConstants, ANNIEConstants, Serializable, Cloneable

A set of predicates/expressions that apply to a single Annotation type. 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.

Matching Logic:The matching function of a non-negated constraint can be defined as, "There exists an annotation for which all of the predicates are true." Thus, given a collection of annotations, only a single annotation must meet all of the predicates of the constraint in order for the match to be successful.

Negation: A negated constraint means strictly the opposite - "There does not exist an annotation for which any of these predicates are true." Negation does not mean "There exists an annotation for which all of these predicates are false." Thus, negation makes more intuitive sense when thought of as applying to a set of annotations rather than to an individual annotation.

See Also:
Serialized Form

Field Summary
protected  FeatureMap ontFeatureMap
          FeatureMap that may contain ontology-related features and values pulled from any predicates that operate on those features
protected  ConstraintPredicate ontLookupClassPred
          Predicate that acts on class feature, if one is set.
 
Fields inherited from interface gate.jape.JapeConstants
ALL_STYLE, APPELT_STYLE, BRILL_STYLE, DEFAULT_PRIORITY, FIRST_STYLE, INDENT_PADDING, KLEENE_PLUS, KLEENE_QUERY, KLEENE_STAR, MULTI_SPAN_BINDING, NO_BINDING, NO_KLEENE_OP, ONCE_STYLE, SINGLE_SPAN_BINDING
 
Fields inherited from interface gate.creole.ANNIEConstants
ANNOTATION_COREF_FEATURE_NAME, DATE_ANNOTATION_TYPE, DATE_POSTED_ANNOTATION_TYPE, DEFAULT_FILE, 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, PLUGIN_DIR, 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(String annotType)
          Construction from annot type string
Constraint(String annotType, FeatureMap attrs)
          Construction from annot type and FeatureMap.
Constraint(String annotType, List<JdmAttribute> attrsArray)
          Deprecated. JdmAttributes are no longer used. Use ConstraintPredicates instead.
 
Method Summary
 void addAttribute(ConstraintPredicate attr)
          Add an attribute.
 void addAttribute(JdmAttribute attr)
          Deprecated.  
 void addAttribute(String name, Object value)
          Create and add an attribute.
 void addAttributes(Collection<ConstraintPredicate> attrs)
          Add all predicates from the given collection to this object.
 void changeSign()
          Change the sign of the negation flag.
 Object clone()
          Need cloning for processing of macro references.
 boolean equals(Object other)
          Returns a boolean value indicating whether this Constraint is equivalent to the given Constraint.
 void finish()
          Finish: replace dynamic data structures with Java arrays; called after parsing.
 String getAnnotType()
          Get the type of annotation we're looking for.
 List<ConstraintPredicate> getAttributeSeq()
          Get the attributes that must be present on the matched annotation.
 String getAttributesString()
          Returns string representation of all the attributes that is appropriate for display.
 String getDisplayString(String prefix)
          Create a string representation of the object.
protected  FeatureMap getOntFeatureMap()
          Generate a FeatureMap to perform ontology-related compare.
 int hashCode()
          Returns an integer hash code for this object.
 boolean isNegated()
          Access to negation flag.
 boolean matches(Annotation annot, AnnotationSet context)
          Test if an annotation is of the proper type for this constraint and if it complies with the ConstraintPredicates of this constraint.
 boolean matches(Annotation annot, Ontology ontologyLR, AnnotationSet context)
          Test if an annotation is of the proper type for this constraint and if it complies with the ConstraintPredicates of this constraint.
 List<Annotation> matches(Collection<Annotation> annots, Ontology ontology, AnnotationSet context)
          Invoke #matches(Annotation, Ontology, Object) on all provided annotations.
 void negate()
          Set negation.
 String shortDesc()
           
 String toString()
          Create a string representation of the object.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ontLookupClassPred

protected ConstraintPredicate ontLookupClassPred
Predicate that acts on class feature, if one is set.


ontFeatureMap

protected FeatureMap ontFeatureMap
FeatureMap that may contain ontology-related features and values pulled from any predicates that operate on those features

Constructor Detail

Constraint

public Constraint(String annotType)
Construction from annot type string


Constraint

public Constraint(String annotType,
                  FeatureMap attrs)
Construction from annot type and FeatureMap. Creates EqualPredicates for each feature in the map


Constraint

@Deprecated
public Constraint(String annotType,
                             List<JdmAttribute> attrsArray)
Deprecated. JdmAttributes are no longer used. Use ConstraintPredicates instead.

Construction from annot type and array of JdmAttributes.

Method Detail

negate

public void negate()
Set negation.


changeSign

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


isNegated

public boolean isNegated()
Access to negation flag.


getAnnotType

public String getAnnotType()
Get the type of annotation we're looking for.


getAttributeSeq

public List<ConstraintPredicate> getAttributeSeq()
Get the attributes that must be present on the matched annotation.


addAttribute

public void addAttribute(ConstraintPredicate attr)
Add an attribute.


getOntFeatureMap

protected FeatureMap getOntFeatureMap()
Generate a FeatureMap to perform ontology-related compare.

Returns:

addAttribute

public void addAttribute(JdmAttribute attr)
Deprecated. 

Legacy support for adding an attribute using a jdm attribute.

Parameters:
attr -

addAttribute

public void addAttribute(String name,
                         Object value)
Create and add an attribute.


addAttributes

public void addAttributes(Collection<ConstraintPredicate> attrs)
Add all predicates from the given collection to this object. Does not remove or replace any existing predicates.

Parameters:
attrs -

clone

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

Overrides:
clone in class Object

equals

public boolean equals(Object other)
Returns a boolean value indicating whether this Constraint is equivalent to the given Constraint. If the given object is not a Constraint, compares the two objects using Object.equals().

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns an integer hash code for this object.

Overrides:
hashCode in class Object

finish

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


toString

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

Overrides:
toString in class Object

getDisplayString

public String getDisplayString(String prefix)
Create a string representation of the object.


getAttributesString

public String getAttributesString()
Returns string representation of all the attributes that is appropriate for display.

Returns:

shortDesc

public String shortDesc()

matches

public List<Annotation> matches(Collection<Annotation> annots,
                                Ontology ontology,
                                AnnotationSet context)
Invoke #matches(Annotation, Ontology, Object) on all provided annotations.

Parameters:
annots - collection of Annotations to test
ontology - optional Ontology to compare ont-specific features
Returns:
Collection of annotations which matches successfully against predicates.

matches

public final boolean matches(Annotation annot,
                             Ontology ontologyLR,
                             AnnotationSet context)
Test if an annotation is of the proper type for this constraint and if it complies with the ConstraintPredicates of this constraint.

Parameters:
annot - an Annotation
ontologyLR - optional ontology to use when comparing ont-related features
Returns:
true if the annotation is of the proper type and matches all predicates. If the constraint is negated, an annotation need only match a single predicate to return true.

matches

public boolean matches(Annotation annot,
                       AnnotationSet context)
Test if an annotation is of the proper type for this constraint and if it complies with the ConstraintPredicates of this constraint.

Parameters:
annot - a Annotation
Returns:
true if the annotation is of the proper type and matches all predicates. If the constraint is negated, an annotation need only match a single predicate to return true.