public class Constraint extends Object implements JapeConstants, ANNIEConstants, Serializable, Cloneable
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.
Modifier and Type | Field and Description |
---|---|
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.
|
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
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, 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 and Description |
---|
Constraint(String annotType)
Construction from annot type string
|
Constraint(String annotType,
FeatureMap attrs)
Construction from annot type and FeatureMap.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(ConstraintPredicate attr)
Add an attribute.
|
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
ConstraintPredicate s 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
ConstraintPredicate s of this
constraint. |
List<Annotation> |
matches(Collection<Annotation> annots,
Ontology ontology,
AnnotationSet context)
Invoke
matches(Annotation, Ontology, AnnotationSet) on all provided
annotations. |
void |
negate()
Set negation.
|
String |
shortDesc() |
String |
toString()
Create a string representation of the object.
|
protected ConstraintPredicate ontLookupClassPred
protected FeatureMap ontFeatureMap
public Constraint(String annotType)
public Constraint(String annotType, FeatureMap attrs)
EqualPredicate
s for each feature in the mappublic void negate()
public void changeSign()
public boolean isNegated()
public String getAnnotType()
public List<ConstraintPredicate> getAttributeSeq()
public void addAttribute(ConstraintPredicate attr)
protected FeatureMap getOntFeatureMap()
public void addAttribute(String name, Object value)
public void addAttributes(Collection<ConstraintPredicate> attrs)
attrs
- public Object clone()
PatternElement.clone()
public boolean equals(Object other)
Object.equals()
.public int hashCode()
public void finish()
public String getDisplayString(String prefix)
public String getAttributesString()
public List<Annotation> matches(Collection<Annotation> annots, Ontology ontology, AnnotationSet context)
matches(Annotation, Ontology, AnnotationSet)
on all provided
annotations.annots
- collection of Annotations to testontology
- optional Ontology to compare ont-specific featurespublic final boolean matches(Annotation annot, Ontology ontologyLR, AnnotationSet context)
ConstraintPredicate
s of this
constraint.annot
- an AnnotationontologyLR
- optional ontology to use when comparing
ont-related featurestrue
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.public boolean matches(Annotation annot, AnnotationSet context)
ConstraintPredicate
s of this
constraint.annot
- a Annotationtrue
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.