de.unidu.is.pdatalog.ds
Class Rule

java.lang.Object
  extended byde.unidu.is.pdatalog.ds.Rule
Direct Known Subclasses:
Fact

public class Rule
extends java.lang.Object

The representation of a datalog probabilistic rule. A rule has a head (an Literal), a body (one or more Literals, stored in a List) and a mapping function (which can be a linear one, which then can be defined by a probability).

Since:
2003-10-27
Version:
$Revision: 1.7 $, $Date: 2005/03/14 17:33:14 $
Author:
Henrik Nottelmann

Field Summary
protected  java.util.List body
          The body of the rule.
protected  Literal head
          The head of the rule.
 
Constructor Summary
Rule(double prob, Literal head, java.util.List body)
          Creates a new probabilistic rule.
Rule(double prob, Literal head, Literal body)
          Creates a new probabilistic rule.
Rule(Literal head, java.util.List body)
          Creates a new deterministic rule (probability is one).
Rule(Literal head, java.util.List body, Expression mapping)
          Creates a new probabilistic rule.
Rule(Literal head, Literal body)
          Creates a new deterministic rule (probability is one).
Rule(Literal head, Literal body, Expression mapping)
          Creates a new deterministic rule (probability is one).
Rule(Rule rule)
          Creates a new rule as a copy of the specified rule.
 
Method Summary
 void addLiteral(Literal literal)
          Adds the specified literal to the body of this rule.
 boolean contains(Literal literal)
          Tests if this rule contains the specified literal as the head or in the body without considering if the literal is positive or negative.
 boolean containsExactly(Literal literal)
          Tests if this rule contains exactly the specified literal as the head or in the body considering if the literal is positive or negative.
 boolean containsExactlyInBody(Literal literal)
          Tests if this rule contains exactly the specified literal in the body considering if the literal is positive or negative.
 java.util.Set getAllArguments()
          Returns a set containing all arguments (variables an constants) of the head literal and all body literals.
 Expression[] getAllArgumentsAsArray()
          Returns an array containing all arguments (variables an constants) of the head literal and all body literals.
 java.util.List getBody()
          Returns the body of this rule.
 java.util.Set getConstants()
          Returns a set containing all constants (no variables) of the head literal and all body literals.
 Literal getHead()
          Returns the head of this rule.
 Expression getMapping()
          Returns the mapping function.
static Expression getMapping(double prob)
          Returns a linear mapping function.
static Expression getMapping(java.lang.String prob)
          Returns a linear mapping function.
 java.lang.String getName()
          Returns the heads predicate name.
 java.lang.String getPredicateName()
          Returns the heads predicate name.
 java.util.Set getVariables()
          Returns a set containing all variables (no constants) of the head literal and all body literals.
 boolean isOptimizable()
          Returns the optimisable flag.
 Literal literalAt(int num)
          Returns the body literal at the specified index.
 int literalCount()
          Returns the number of body literals of this Rule.
 void putAllArguments(java.util.Set set)
          Puts all arguments (variables an constants) of the head literal and all body literals into the specified set.
 void putConstants(java.util.Set set)
          Puts all constants (no variables) of the head literal and all body literals into the specified set.
 void putVariables(java.util.Set set)
          Puts all variables (no constants) of the head literal and all body literals into the specified set.
 void removeLiteral(int literal)
          Removes the literal at the specified index from the body of this rule.
 void removeLiteral(Literal literal)
          Removes the specified literal fromo the body of this rule.
 void setHead(Literal head)
          Sets the head of this rule.
 void setLiteral(int num, Literal literal)
          Sets (replaces) the body literal at the specified index.
 void setMapping(Expression mapping)
          Sets the mapping function.
 void setOptimizable(boolean optimizable)
          Sets the optimisable flag.
 java.lang.String toString()
          Returns a datalog representation of this rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

head

protected Literal head
The head of the rule.


body

protected java.util.List body
The body of the rule. The list elements are instances of Literal.

Constructor Detail

Rule

public Rule(Literal head,
            Literal body)
Creates a new deterministic rule (probability is one).

Parameters:
head - head of the rule
body - body of the rule

Rule

public Rule(double prob,
            Literal head,
            Literal body)
Creates a new probabilistic rule.

Parameters:
prob - the probability of the rule
head - head of the rule
body - body of the rule

Rule

public Rule(Literal head,
            Literal body,
            Expression mapping)
Creates a new deterministic rule (probability is one).

Parameters:
head - head of the rule
body - body of the rule

Rule

public Rule(Literal head,
            java.util.List body)
Creates a new deterministic rule (probability is one).

Parameters:
head - head of the rule
body - body of the rule

Rule

public Rule(double prob,
            Literal head,
            java.util.List body)
Creates a new probabilistic rule.

Parameters:
prob - the probability of the rule
head - head of the rule
body - body of the rule

Rule

public Rule(Literal head,
            java.util.List body,
            Expression mapping)
Creates a new probabilistic rule.

Parameters:
head - head of the rule
body - body of the rule
mapping - mapping function

Rule

public Rule(Rule rule)
Creates a new rule as a copy of the specified rule.

Parameters:
rule - to be copied
Method Detail

getHead

public Literal getHead()
Returns the head of this rule.

Returns:
head of the rule

setHead

public void setHead(Literal head)
Sets the head of this rule.

Parameters:
head - head of the rule

getBody

public java.util.List getBody()
Returns the body of this rule.

Returns:
body of the rule

literalAt

public Literal literalAt(int num)
Returns the body literal at the specified index.

Parameters:
num - the index
Returns:
body literal at the specified index or null, if this literal does not exist

setLiteral

public void setLiteral(int num,
                       Literal literal)
Sets (replaces) the body literal at the specified index.

Parameters:
num - the index
literal - body literal at the specified index

literalCount

public int literalCount()
Returns the number of body literals of this Rule.

Returns:
number of body literal of this Rule

contains

public boolean contains(Literal literal)
Tests if this rule contains the specified literal as the head or in the body without considering if the literal is positive or negative.

This method can be used to test if a literal should be added to be body for spezialization.

Returns:
true if this rule contains the specified literal

containsExactly

public boolean containsExactly(Literal literal)
Tests if this rule contains exactly the specified literal as the head or in the body considering if the literal is positive or negative.

Returns:
true if this rule contains exactly the specified literal

containsExactlyInBody

public boolean containsExactlyInBody(Literal literal)
Tests if this rule contains exactly the specified literal in the body considering if the literal is positive or negative.

Returns:
true if this rule contains exactly the specified literal

addLiteral

public void addLiteral(Literal literal)
Adds the specified literal to the body of this rule. This method does not check for double occurrences of literals.

Parameters:
literal - literal to be added to the body

removeLiteral

public void removeLiteral(Literal literal)
Removes the specified literal fromo the body of this rule.

Parameters:
literal - literal to be removed to the body

removeLiteral

public void removeLiteral(int literal)
Removes the literal at the specified index from the body of this rule.

Parameters:
literal - literal to be removed to the body

putVariables

public void putVariables(java.util.Set set)
Puts all variables (no constants) of the head literal and all body literals into the specified set.

Parameters:
set - destination set for all variables

putConstants

public void putConstants(java.util.Set set)
Puts all constants (no variables) of the head literal and all body literals into the specified set.

Parameters:
set - destination set for all constants

putAllArguments

public void putAllArguments(java.util.Set set)
Puts all arguments (variables an constants) of the head literal and all body literals into the specified set.

Parameters:
set - destination set for all arguments

getVariables

public java.util.Set getVariables()
Returns a set containing all variables (no constants) of the head literal and all body literals.

Returns:
a set containing all variables (no constants)

getConstants

public java.util.Set getConstants()
Returns a set containing all constants (no variables) of the head literal and all body literals.

Returns:
a set containing all constants (no variables)

getAllArguments

public java.util.Set getAllArguments()
Returns a set containing all arguments (variables an constants) of the head literal and all body literals.

Returns:
a set containing all arguments

getAllArgumentsAsArray

public Expression[] getAllArgumentsAsArray()
Returns an array containing all arguments (variables an constants) of the head literal and all body literals.

Returns:
an array containing all arguments

getName

public java.lang.String getName()
Returns the heads predicate name.

Returns:
heads predicate name

getPredicateName

public java.lang.String getPredicateName()
Returns the heads predicate name.

Returns:
heads predicate name

toString

public java.lang.String toString()
Returns a datalog representation of this rule.

Returns:
datalog representation of this rule

getMapping

public Expression getMapping()
Returns the mapping function.

Returns:
mapping function

setMapping

public void setMapping(Expression mapping)
Sets the mapping function.

Parameters:
mapping - mapping function

isOptimizable

public boolean isOptimizable()
Returns the optimisable flag.

Returns:
optimisable flag

setOptimizable

public void setOptimizable(boolean optimizable)
Sets the optimisable flag.

Parameters:
optimizable - optimisable flag

getMapping

public static Expression getMapping(double prob)
Returns a linear mapping function.

Parameters:
prob - probability factor of the mapping function
Returns:
corresponding mapping function

getMapping

public static Expression getMapping(java.lang.String prob)
Returns a linear mapping function.

Parameters:
prob - probability factor of the mapping function
Returns:
corresponding mapping function