## org.opencyc.constraintsolver
Class Rule

    java.lang.Object
      |
      +--org.opencyc.constraintsolver.Rule

public class Rule
extends java.lang.Object

`Rule` object to model the attributes and behavior of a constraint rule.

Author:
  Stephen L. Reed

  Copyright 2001 OpenCyc.org, license is open source GNU LGPL.

  the license

  www.opencyc.org

  OpenCyc at SourceForge

  THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

See Also:
  `UnitTest.testRule()`

Field Summary
`protected CycList` `rule` The constraint rule formula as an OpenCyc query.
`protected java.util.ArrayList` `variables` The collection of `CycVariables` used in the rule.

Constructor Summary
`Rule(CycList rule)` Constructs a new `Rule` object from a `CycList`.

Method Summary
`java.lang.String` `cyclify()` Returns a cyclified string representation of the rule's formula.
`boolean` `equals(java.lang.Object object)` Returns `true` if the object equals this object.
`int` `getArity()` Gets the rule's arity, which is the number of variables in this `Rule`.
`java.lang.Object` `getPredicate()` Returns the predicate of this `Rule` object.
`CycList` `getRule()` Gets the rule's formula.
`java.util.ArrayList` `getVariables()` Gets the rule's variables.
`boolean` `isVariableDomainPopulatingRule()` Returns `true` if this is a variable domain populating `Rule`.
`static java.util.ArrayList` `simplifyRuleExpression(CycList cycList)` Simplifies a rule expression.
`java.lang.String` `toString()` Returns a string representation of the `Rule`.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### rule

    protected CycList rule

  The constraint rule formula as an OpenCyc query.

### variables

    protected java.util.ArrayList variables

  The collection of `CycVariables` used in the rule. There should be at least one, because if there are no variables, then the rule is either always true or always false and has no effect on the constraint problem's solution.

Constructor Detail

### Rule

    public Rule(CycList rule)

  Constructs a new `Rule` object from a `CycList`.

        String ruleAsString = "(#$isa ?x #$Cathedral)";
        Rule rule1 = new Rule (new CycList(ruleAsString));

  Parameters:
    `rule` - the rule's formula, which must be a well formed OpenCyc query represented by a `CycList`.

Method Detail

### simplifyRuleExpression

    public static java.util.ArrayList simplifyRuleExpression(CycList cycList)

  Simplifies a rule expression.

  (#$and (<rule1> <rule2> ... <ruleN>) becomes <rule1> <rule2> ... <ruleN>

  Returns:
    an `ArrayList` of `Rule` objects.
  See Also:
    `UnitTest.testRule()`

### getRule

    public CycList getRule()

  Gets the rule's formula.
  Returns:
    a `CycList` which is the rule's formula.

### getVariables

    public java.util.ArrayList getVariables()

  Gets the rule's variables.
  Returns:
    the `ArrayList` which lists the unique `CycVariables` that are used in the rule's formula.

### getArity

    public int getArity()

  Gets the rule's arity, which is the number of variables in this `Rule`.
  Returns:
    an `int` which is the number of `CycVariables` in the rule's formula.

### equals

    public boolean equals(java.lang.Object object)

  Returns `true` if the object equals this object.
  Overrides:
    `equals` in class `java.lang.Object`
  Returns:
    `boolean` indicating equality of an object with this object.

### getPredicate

    public java.lang.Object getPredicate()

  Returns the predicate of this `Rule` object.
  Returns:
    the predicate `CycConstant` or `CycSymbol` of this `Rule` object

### isVariableDomainPopulatingRule

    public boolean isVariableDomainPopulatingRule()

  Returns `true` if this is a variable domain populating `Rule`.
  Returns:
    `boolean` indicating if this is a variable domain populating `Rule`.

### toString

    public java.lang.String toString()

  Returns a string representation of the `Rule`.
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    the rule's formula formated as a `String`.

### cyclify

    public java.lang.String cyclify()

  Returns a cyclified string representation of the rule's formula. Embedded constants are prefixed with ""#$".
  Returns:
    a cyclified `String`.