org.deri.iris.rules.compiler
Class View

java.lang.Object
  extended by org.deri.iris.rules.compiler.View
All Implemented Interfaces:
IRelation

public class View
extends Object
implements IRelation

A view on a relation, which represents how an instance of a sub-goal interprets a relation.

Essentially, this class is an adaptor accepts tuples from a relation and attempts to term match every term in the relation with the corresponding term in the tuple in the sub-goal.

Therefore, the relation and the viewCriteria tuple must have the same arity. However, the output (a relation) will have an arity corresponding to the number of unique variables in the view criteria.

e.g. for this sub-goal: p( ?X, 'c', f(?Y), ?Y ) applied to this relation

1, 'c', f(3), 4

1, 'c', f(4), 4

2, 'b', f(5), 5

3, 'c', f(g(1)), g(1)

would filter and produce a view that appears as:

X Y

= =

1, 4

3, g(1)


Constructor Summary
View(IRelation relation, ITuple viewCriteria, IEquivalentTerms equivalentTerms, IRelationFactory relationFactory)
          Constructor.
View(IRelation relation, ITuple viewCriteria, IRelationFactory relationFactory)
          Constructor.
View(IRelation relation, ITuple viewCriteria, List<IVariable> variables, boolean simple, IEquivalentTerms equivalentTerms, IRelationFactory relationFactory)
          Kind of copy constructor.
View(IRelation relation, ITuple viewCriteria, List<IVariable> variables, boolean simple, IRelationFactory relationFactory)
          Kind of copy constructor.
 
Method Summary
 boolean add(ITuple tuple)
          Adding to a View does not make sense.
 boolean addAll(IRelation relation)
          Adding to a View does not make sense.
 boolean contains(ITuple tuple)
           
 ITuple get(int index)
          Get a tuple at a specific index.
 boolean isSimple()
          Indicates if the view is simple.
static boolean isSimpleView(ITuple viewCriteria)
          Determine of the view is simple.
 int size()
          Get the current number of tuples in this relation.
 String toString()
           
 List<IVariable> variables()
          Get the output variables in order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

View

public View(IRelation relation,
            ITuple viewCriteria,
            IRelationFactory relationFactory)
Constructor.

Parameters:
relation - The relation to create the view over.
viewCriteria - The criteria to filter with.

View

public View(IRelation relation,
            ITuple viewCriteria,
            IEquivalentTerms equivalentTerms,
            IRelationFactory relationFactory)
Constructor.

Parameters:
relation - The relation to create the view over.
viewCriteria - The criteria to filter with.
equivalentTerms - The equivalent terms.

View

public View(IRelation relation,
            ITuple viewCriteria,
            List<IVariable> variables,
            boolean simple,
            IRelationFactory relationFactory)
Kind of copy constructor.

Parameters:
relation - The viewed relation.
viewCriteria - The view criteria.
variables - The computed output variables.
simple - Indicates of the view is simple (pass thorugh)

View

public View(IRelation relation,
            ITuple viewCriteria,
            List<IVariable> variables,
            boolean simple,
            IEquivalentTerms equivalentTerms,
            IRelationFactory relationFactory)
Kind of copy constructor.

Parameters:
relation - The viewed relation.
viewCriteria - The view criteria.
variables - The computed output variables.
simple - Indicates of the view is simple (pass thorugh)
equivalentTerms - The equivalent terms.
Method Detail

isSimpleView

public static boolean isSimpleView(ITuple viewCriteria)
Determine of the view is simple. The view is simple if no filtering occurs. This only happens if every term of the view criteria is a plain variable and unique, e.g. p( ?X, ?Y, ?Z ) is simple, but p(?X, ?X ) is not.

Parameters:
viewCriteria - The vew criteria.
Returns:
true, if the view is simple.

isSimple

public boolean isSimple()
Indicates if the view is simple.

Returns:
true, if the view is simple.

variables

public List<IVariable> variables()
Get the output variables in order.

Returns:

add

public boolean add(ITuple tuple)
Adding to a View does not make sense.

Specified by:
add in interface IRelation
Parameters:
tuple - The (unique) tuple to add.
Returns:
true, if it was added, false if a tuple already exists in the relation with the same term values.
Throws:
RuntimeException - if this method is called.

addAll

public boolean addAll(IRelation relation)
Adding to a View does not make sense.

Specified by:
addAll in interface IRelation
Parameters:
relation - The relation containing tuples to add.
Returns:
true if any tuples were actually added.
Throws:
RuntimeException - if this method is called.

contains

public boolean contains(ITuple tuple)
Specified by:
contains in interface IRelation

get

public ITuple get(int index)
Description copied from interface: IRelation
Get a tuple at a specific index.

Specified by:
get in interface IRelation
Parameters:
index - The index of the tuple in the relation, 0 <= index < size().
Returns:
The tuple at the given index position.

size

public int size()
Description copied from interface: IRelation
Get the current number of tuples in this relation.

Specified by:
size in interface IRelation
Returns:
The number of tuples in the relation.

toString

public String toString()
Overrides:
toString in class Object