org.openanzo.glitter.expression
Class FunctionBase

java.lang.Object
  extended by org.openanzo.glitter.expression.FunctionBase
All Implemented Interfaces:
Function
Direct Known Subclasses:
BinaryFunction, RegEx, UnaryFunction

public abstract class FunctionBase
extends java.lang.Object
implements Function

Base class for SPARQL functions. Provides a standard configuration for operatesOnValues() (true) and for operatesOnTypeErrors() (false). Also provides a set of utility methods to perform -1/0/1 comparison functions on RDFTerms for booleans, numerics, datetimes, and strings.

Author:
lee

Constructor Summary
FunctionBase()
           
 
Method Summary
static int compareBooleans(RDFTerm arg1, RDFTerm arg2)
          Compares two boolean RDF terms
static int compareBooleans(RDFTerm arg1, RDFTerm arg2, boolean convert)
          Compares two boolean RDF terms
static int compareDateTimes(RDFTerm arg1, RDFTerm arg2)
          Compares two datetime RDF terms.
static int compareNumerics(RDFTerm arg1, RDFTerm arg2)
          Compares two numeric RDF terms
static int compareStringLiterals(RDFTerm arg1, RDFTerm arg2)
          Compares two string RDF terms
 boolean operatesOnTypeErrors()
           
 boolean operatesOnValues()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openanzo.glitter.expression.Function
getIdentifier
 

Constructor Detail

FunctionBase

public FunctionBase()
Method Detail

operatesOnValues

public boolean operatesOnValues()
Specified by:
operatesOnValues in interface Function
Returns:
true if this function's arguments should be values evaluated in the context of the environment created from each set of bindings (solution); false if the function operates directly on the surface term (e.g. a hypothetical function isVariable would operate on terms and return false)

operatesOnTypeErrors

public boolean operatesOnTypeErrors()
Specified by:
operatesOnTypeErrors in interface Function
Returns:
true if the function can process type errors as arguments; false if the function simply propagates type errors

compareNumerics

public static int compareNumerics(RDFTerm arg1,
                                  RDFTerm arg2)
                           throws ExpressionEvaluationException
Compares two numeric RDF terms

Parameters:
arg1 - First term
arg2 - Second term
Returns:
-1 if arg1 < arg2; 0 if arg1 == arg2; 1 if arg1 > arg2
Throws:
ExpressionEvaluationException - If either argument is not numeric

compareBooleans

public static int compareBooleans(RDFTerm arg1,
                                  RDFTerm arg2)
                           throws ExpressionEvaluationException
Compares two boolean RDF terms

Parameters:
arg1 - First term
arg2 - Second term
Returns:
-1 if arg1 is false and arg2 is true; 1 if the other way around; 0 if both terms are the same boolean value
Throws:
ExpressionEvaluationException - if either arguments is not a boolean

compareBooleans

public static int compareBooleans(RDFTerm arg1,
                                  RDFTerm arg2,
                                  boolean convert)
                           throws ExpressionEvaluationException
Compares two boolean RDF terms

Parameters:
arg1 - First term
arg2 - Second term
convert - Should the effective boolean value rules be applied to derive boolean values from non-boolean arguments?
Returns:
-1 if arg1 is false and arg2 is true; 1 if the other way around; 0 if both terms are the same boolean value
Throws:
ExpressionEvaluationException - if either arguments is not a boolean and either convert is false or there are no rules for finding the EBV of an argument

compareDateTimes

public static int compareDateTimes(RDFTerm arg1,
                                   RDFTerm arg2)
                            throws ExpressionEvaluationException
Compares two datetime RDF terms. Note that the current implementation of this method uses Calendar.compareTo(Calendar) for the comparison, which may or may not agree with http://www.w3.org/TR/xpath-functions/#xmlschema-2, the required functionality.

Parameters:
arg1 - First term
arg2 - Second term
Returns:
-1 if arg1 < arg2; 0 if arg1 == arg2; 1 if arg1 > arg2
Throws:
ExpressionEvaluationException - if either arguments is not a xsd:dateTime

compareStringLiterals

public static int compareStringLiterals(RDFTerm arg1,
                                        RDFTerm arg2)
                                 throws ExpressionEvaluationException
Compares two string RDF terms

Parameters:
arg1 - First term
arg2 - Second term
Returns:
-1 if arg1 < arg2; 0 if arg1 == arg2; 1 if arg1 > arg2
Throws:
ExpressionEvaluationException - if either argument is not an xsd:string or a plain literal with no language tag


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.