de.unidu.is.pdatalog
Class RelationBase

java.lang.Object
  extended byde.unidu.is.pdatalog.RelationBase

public class RelationBase
extends java.lang.Object

A collection of pDatalog++ relations together with methods for inserting facts and applying rules, using a RDBMS system.

Since:
2003-10-07
Version:
$Revision: 1.28 $, $Date: 2005/03/18 22:01:39 $
Author:
Henrik Nottelmann

Field Summary
protected  PropertyMap config
          PDatalog++ configuration.
protected  org.apache.log4j.Logger factsLogger
          Logger for facts.
protected  org.apache.log4j.Logger rulesLogger
          Logger for rules.
 
Constructor Summary
RelationBase(DB db)
          Creates a new, empty relation base.
 
Method Summary
 void add(Fact fact)
          Adds the specified fact to the knowledge base.
 void add(Relation relation)
          Adds (and initialises) the specified relation to this relation base.
 void add(Relation relation, boolean create)
          Adds (and initialises, if specified by the Boolean parameter) the specified relation to this relation base.
 void addIndex(Relation relation)
          Adds indexes to the specified relation.
 void clear()
          Removes all relations.
 void clear(java.lang.String name)
          Clears the relation, i.e. it removes all facts.
 void close(java.sql.ResultSet rs)
          Closes the specified ResultSet.
 void compute(IDBRelation relation, java.util.Collection rules)
          Computes the result of the specified rules (all corresponding to the specified derived relation).
 void compute(IDBRelation relation, Rule rule)
          Compute the relation by evaluating the single rule.
 void compute(IDBRelation relation, Rule rule, boolean addIndex)
          Compute the relation by evaluating the single rule.
 void computeDisjoint(IDBRelation relation, java.util.Collection rules)
          Computes the result of the specified rules (all corresponding to the specified derived relation).
 void computeRecursively(IDBRelation rel, Rule rule)
          Compute the specified rule recursively, applying the naive evaluation.
 boolean containsRelation(java.lang.String name)
          Tests whether this relation base contains the relation defined by the specified name.
 void dump(Relation relation)
          Dumps the content of the relation.
 boolean equals(java.lang.Object obj)
           
 boolean existsRelation(java.lang.String relation)
          Retutns true iff the relation physically exists.
 Relation get(java.lang.String name)
          Returns the relation defined by the specified name.
 int getTupleCount(Relation rel)
          Returns the number of tuples in the relation.
 int hashCode()
           
 boolean isEmpty()
          Tests whether this relation base is empty, which means it does not contain any relation.
 java.util.Iterator names()
          Returns an iterator over all relation names.
 void perform(SQL sql)
          Performs a SQL insert statement.
 java.sql.ResultSet performQuery(SQL sql)
          Performs a SQL insert statement.
 java.util.List query(java.lang.String query)
          Queries the relation base.
 java.util.List queryRelation(Relation relation)
          Returns all tuples in the specified relation.
 java.util.List queryRelation(java.lang.String relation, int arity)
          Returns all tuples in the specified relation.
 java.util.Collection relations()
          Returns a collection containing all relations.
 void remove(java.lang.String name)
          Removes the relation defined by the specified name.
 int size()
          Returns the size of this relation base, which means the number of relations in it.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

config

protected PropertyMap config
PDatalog++ configuration.


rulesLogger

protected org.apache.log4j.Logger rulesLogger
Logger for rules.


factsLogger

protected org.apache.log4j.Logger factsLogger
Logger for facts.

Constructor Detail

RelationBase

public RelationBase(DB db)
Creates a new, empty relation base.

Parameters:
db - DB parameters
Method Detail

add

public void add(Fact fact)
Adds the specified fact to the knowledge base.

Parameters:
fact - fact to be added

compute

public void compute(IDBRelation relation,
                    java.util.Collection rules)
Computes the result of the specified rules (all corresponding to the specified derived relation).

Parameters:
relation - target relation
rules - collection of rules for target relation

compute

public void compute(IDBRelation relation,
                    Rule rule)
Compute the relation by evaluating the single rule.

Parameters:
relation - IDB relation
rule - rule to be evaluated

compute

public void compute(IDBRelation relation,
                    Rule rule,
                    boolean addIndex)
Compute the relation by evaluating the single rule.

Parameters:
relation - IDB relation
rule - rule to be evaluated
addIndex - if true, an DB index is added

computeDisjoint

public void computeDisjoint(IDBRelation relation,
                            java.util.Collection rules)
Computes the result of the specified rules (all corresponding to the specified derived relation). The results from the single rules are considered to be disjoint.

Parameters:
relation - target relation
rules - collection of rules for target relation

dump

public void dump(Relation relation)
Dumps the content of the relation.

Parameters:
relation - target relation

clear

public void clear()
Removes all relations.


containsRelation

public boolean containsRelation(java.lang.String name)
Tests whether this relation base contains the relation defined by the specified name.

Parameters:
name - relation name
Returns:
true iff the relation base contains the specified relation

equals

public boolean equals(java.lang.Object obj)

get

public Relation get(java.lang.String name)
Returns the relation defined by the specified name.

Parameters:
name - relation name
Returns:
relation defined by the specified name

hashCode

public int hashCode()

isEmpty

public boolean isEmpty()
Tests whether this relation base is empty, which means it does not contain any relation.

Returns:
true iff this relation base is empty

names

public java.util.Iterator names()
Returns an iterator over all relation names.

Returns:
iterator over all relation names

add

public void add(Relation relation)
Adds (and initialises) the specified relation to this relation base.

Parameters:
relation - relation to be stored

add

public void add(Relation relation,
                boolean create)
Adds (and initialises, if specified by the Boolean parameter) the specified relation to this relation base.

Parameters:
relation - relation to be stored
create - if true, the relation is physically created

remove

public void remove(java.lang.String name)
Removes the relation defined by the specified name.

Parameters:
name - relation name

clear

public void clear(java.lang.String name)
Clears the relation, i.e. it removes all facts.

Parameters:
name - relation name

size

public int size()
Returns the size of this relation base, which means the number of relations in it.

Returns:
size of this relation base

toString

public java.lang.String toString()

relations

public java.util.Collection relations()
Returns a collection containing all relations.

Returns:
collection containing all relations

perform

public void perform(SQL sql)
Performs a SQL insert statement.

Parameters:
sql - SQL statement

performQuery

public java.sql.ResultSet performQuery(SQL sql)
                                throws java.sql.SQLException
Performs a SQL insert statement.

Parameters:
sql - SQL statement
Throws:
java.sql.SQLException

close

public void close(java.sql.ResultSet rs)
Closes the specified ResultSet.

Parameters:
rs - result set

addIndex

public void addIndex(Relation relation)
Adds indexes to the specified relation.

Parameters:
relation - reation

existsRelation

public boolean existsRelation(java.lang.String relation)
Retutns true iff the relation physically exists.

Parameters:
relation - relation name
Returns:
true iff the relation physically exists

query

public java.util.List query(java.lang.String query)
Queries the relation base.

Parameters:
query - pDatalog++ query
Returns:
list of Fact instances

queryRelation

public java.util.List queryRelation(Relation relation)
Returns all tuples in the specified relation.

Parameters:
relation - relation
Returns:
all tuples in the specified relation

queryRelation

public java.util.List queryRelation(java.lang.String relation,
                                    int arity)
Returns all tuples in the specified relation.

Parameters:
relation - relation name
arity - relation arity
Returns:
all tuples in the specified relation

computeRecursively

public void computeRecursively(IDBRelation rel,
                               Rule rule)
Compute the specified rule recursively, applying the naive evaluation.

Future implementation will use a more efficient method.

Parameters:
rel - relation name
rule - rule

getTupleCount

public int getTupleCount(Relation rel)
Returns the number of tuples in the relation.

Parameters:
rel - relation
Returns:
number of tuples in the relation