org.deri.iris.builtins
Class FunctionalBuiltin

java.lang.Object
  extended by org.deri.iris.builtins.AbstractBuiltin
      extended by org.deri.iris.builtins.FunctionalBuiltin
All Implemented Interfaces:
Comparable<IAtom>, IAtom, IBuiltinAtom
Direct Known Subclasses:
ConversionBuiltin, DayFromDateBuiltin, DayFromDateTimeBuiltin, DayPartBuiltin, DaysFromDurationBuiltin, HourPartBuiltin, HoursFromDateTimeBuiltin, HoursFromDurationBuiltin, HoursFromTimeBuiltin, LangFromPlainLiteralBuiltin, MinutePartBuiltin, MinutesFromDateTimeBuiltin, MinutesFromDurationBuiltin, MinutesFromTimeBuiltin, MonthFromDateBuiltin, MonthFromDateTimeBuiltin, MonthPartBuiltin, MonthsFromDurationBuiltin, PlainLiteralCompareBuiltin, PlainLiteralFromStringBuiltin, PlainLiteralFromStringLangBuiltin, PlainLiteralLengthBuiltin, SecondPartBuiltin, SecondsFromDateTimeBuiltin, SecondsFromDurationBuiltin, SecondsFromTimeBuiltin, StringCompareBuiltin, StringConcatBuiltin, StringEscapeHtmlUriBuiltin, StringFromPlainLiteralBuiltin, StringIriToUriBuiltin, StringJoinBuiltin, StringLengthBuiltin, StringReplaceBuiltin, StringReplaceWithoutFlagsBuiltin, StringSubstringAfterBuiltin, StringSubstringAfterWithoutCollationBuiltin, StringSubstringBeforeBuiltin, StringSubstringBeforeWithoutCollationBuiltin, StringSubstringBuiltin, StringSubstringUntilEndBuiltin, StringToLowerBuiltin, StringToUpperBuiltin, StringUriEncodeBuiltin, TimezoneFromDateBuiltin, TimezoneFromDateTimeBuiltin, TimezoneFromTimeBuiltin, TimezonePartBuiltin, YearFromDateBuiltin, YearFromDateTimeBuiltin, YearPartBuiltin, YearsFromDurationBuiltin

public abstract class FunctionalBuiltin
extends AbstractBuiltin

Base class of functional built-in predicates. For this kind of built-in, the following properties must hold:

  1. Can have any arity.
  2. Can be evaluated with up to 1 unknown variable.
  3. The unknown variable only occurs at the last position of the tuple.
  4. If all terms are known at evaluation time, the given term is checked against the computed term to indicate true or false .


Field Summary
 
Fields inherited from class org.deri.iris.builtins.AbstractBuiltin
EMPTY_TERM
 
Constructor Summary
FunctionalBuiltin(IPredicate predicate, ITerm... terms)
          Creates a new functional builtin.
 
Method Summary
protected abstract  ITerm computeResult(ITerm[] terms)
          Computes the result when all terms but the term at the last position are known.
protected  ITerm evaluateTerms(ITerm[] terms, int[] variableIndexes)
          Evaluate the predicate once the terms and variable indexes have been found.
 int maxUnknownVariables()
          The maximum number of unknown variables allowed such that the predicate can still be evaluated.
protected  boolean testForEquality(ITerm term1, ITerm term2)
          Tests for equality of two terms.
 
Methods inherited from class org.deri.iris.builtins.AbstractBuiltin
compareTo, equals, evaluate, getPredicate, getTuple, hashCode, isBuiltin, isGround, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FunctionalBuiltin

public FunctionalBuiltin(IPredicate predicate,
                         ITerm... terms)
Creates a new functional builtin.

Parameters:
predicate - The predicate that identifies this built-in.
terms - The terms of the instance.
Method Detail

evaluateTerms

protected ITerm evaluateTerms(ITerm[] terms,
                              int[] variableIndexes)
                       throws EvaluationException
Description copied from class: AbstractBuiltin
Evaluate the predicate once the terms and variable indexes have been found.

Overrides:
evaluateTerms in class AbstractBuiltin
Parameters:
terms - The array of all terms for this evaluation.
variableIndexes - the indexes of the terms which should be computed (starting at 0)
Returns:
The result of the evaluation.
Throws:
EvaluationException

testForEquality

protected boolean testForEquality(ITerm term1,
                                  ITerm term2)
Tests for equality of two terms.

Parameters:
term1 - The first term.
term2 - The second term.
Returns:
true if both terms are equal, false otherwise.

computeResult

protected abstract ITerm computeResult(ITerm[] terms)
                                throws EvaluationException
Computes the result when all terms but the term at the last position are known.

Parameters:
terms - The terms, where the terms at the last position is a variable representing the result.
Returns:
The computed term, or null if the operation is unsuccessful.
Throws:
EvaluationException - If an error occurs.

maxUnknownVariables

public int maxUnknownVariables()
Description copied from interface: IBuiltinAtom
The maximum number of unknown variables allowed such that the predicate can still be evaluated.

Specified by:
maxUnknownVariables in interface IBuiltinAtom
Overrides:
maxUnknownVariables in class AbstractBuiltin
Returns:
The maximum number of unknown variables.