Class ArithmeticOperators

java.lang.Object
org.projog.core.math.ArithmeticOperators

public final class ArithmeticOperators extends Object
Maintains a collection of ArithmeticOperator instances.

This class provides a mechanism for "plugging in" or "injecting" implementations of ArithmeticOperator at runtime. This mechanism provides an easy way to configure and extend the arithmetic operations supported by Projog.

Each KnowledgeBase has a single unique ArithmeticOperators instance.

  • Constructor Details

    • ArithmeticOperators

      public ArithmeticOperators(KnowledgeBase kb)
  • Method Details

    • addArithmeticOperator

      public void addArithmeticOperator(PredicateKey key, ArithmeticOperator operator)
      Associates a ArithmeticOperator with this KnowledgeBase.
      Parameters:
      key - The name and arity to associate the ArithmeticOperator with.
      operator - The instance of ArithmeticOperator to be associated with key.
      Throws:
      ProjogException - if there is already a ArithmeticOperator associated with the PredicateKey
    • addArithmeticOperator

      public void addArithmeticOperator(PredicateKey key, String operatorClassName)
      Associates a ArithmeticOperator with this KnowledgeBase.
      Parameters:
      key - The name and arity to associate the ArithmeticOperator with.
      operatorClassName - The class name of the ArithmeticOperator to be associated with key.
      Throws:
      ProjogException - if there is already a ArithmeticOperator associated with the PredicateKey
    • getNumeric

      public Numeric getNumeric(Term t)
      Returns the result of evaluating the specified arithmetic expression.
      Parameters:
      t - a Term that can be evaluated as an arithmetic expression (e.g. a Structure of the form +(1,2) or a Numeric)
      Returns:
      the result of evaluating the specified arithmetic expression
      Throws:
      ProjogException - if the specified term does not represent an arithmetic expression
    • getPreprocessedArithmeticOperator

      public ArithmeticOperator getPreprocessedArithmeticOperator(Term argument)
      Returns:
      placeholder if argument is not numeric, atom or term
    • getArithmeticOperator

      public ArithmeticOperator getArithmeticOperator(PredicateKey key)
      Throws:
      ProjogException - if not found
    • placeholder

      public ArithmeticOperator placeholder()