The KnownSpace Datamanager
"Halfway To Anywhere"

Writing Constraints

Interface Constraint specifies only one abstract method, accepts(). It has one special implementing inner class (not described in the API) which is used to create a singleton instance inside the kernel to serve as the typesafe value of Constraint.NONE.

A constraint describes a set of entities. It also, in some sense, describes a type of entity. An application writer needs to know two things about entity sets:

For the first function, application writers will use your new constraint's constructor. Your constructor may take an entity, or something related to entities like a String for their name, or even a set of entities. It then constructs a way to describe entities of that type.

Alternately, your constraint may be a combinator. These take an n-tuple of constraints of a particular type (for example, AndConstraint and OrConstraint take constraint tuples, while NotConstraint, AttributeExistsConstraint, and BaseExistsConstraint all take singleton constraints, but you may add other combinators taking other sets of constraints) and again produces a constraint describing entities of that type.

So, in either case, your new constraint's constructor must produce a description of a set of entities.

For the second function, the application writer wants to know whether a particular constraint (which describes a particular set of entities) can be satisfied by a particular entity. To handle that case your new constraint must implement an accepts() method. This takes an entity and returns a boolean specifying whether or not the given entity is one of those described by your new constraint.

In sum, to create a constraint you must implement interface Constraint, define a constructor for it, and implement a public boolean accepts(Entity) method.

There is no limit on the kinds of attributes, and therefore constraints, that developers can introduce into the system. For example, here is a possible constraint:

are you older than 5 days?
are you bigger than 2 megs?
do you contain the string "terry jones"? (case unimportant)
do you contain the partial email address "jones@cliffs"?
do you contain the string "here's the design"?
do you reference images?
do you contain a webpage?
are you email?
do you have more than 50 attributes?
do you belong to more than 10 clusters?
does the user visit you relatively often?
have you been hit in searches more than 5 times?

Note that some attributes are intrinsic and unchanging (content strings, for example), some are dynamic and user-based (number of user visits, for example), and some are dynamic and system-derived (containing more than 50 attributes, for example). Developers can add any new kind of constraint they wish.