edu.udo.cs.ie.cowbots.logic
Class ELPAtom

Package class diagram package ELPAtom
java.lang.Object
  extended by edu.udo.cs.ie.cowbots.logic.ELPAtom
All Implemented Interfaces:
ELPLiteral
Direct Known Subclasses:
AggregatePredicate, ArithmeticPredicate, DLPAtom, IntPredicate, RelationPredicate

public class ELPAtom
extends java.lang.Object
implements ELPLiteral

this class models an atom, a common element for building literals and rules in extended logic programs. it allows textual representation of an atom compatible with dlv or lparse.


Field Summary
(package private)  java.lang.String pred
           
(package private)  java.lang.String[] terms
           
 
Constructor Summary
ELPAtom(ELPAtom other)
          default copy constructor
ELPAtom(java.lang.String[] symbols, int nterm)
          create a new atom from a given list of string symbols.
ELPAtom(java.lang.String predicate, int arity)
          instantiates a new atom with a predicate of given arity, but does not set any terms.
ELPAtom(java.lang.String predicate, java.lang.String... terms)
          creates a new atom
 
Method Summary
static ELPAtom Aggregate(java.lang.String pred, java.lang.String lguard, java.lang.String lgop, java.lang.String rguard, java.lang.String rgop, SymbolicSet symset)
          factory method to create a guarded builtin aggregate fact like "1 < #count{X:a(A)} < 3"
static ELPAtom Aggregate(java.lang.String pred, SymbolicSet symset, java.lang.String rightoperator, java.lang.String rightguard)
          factory method to create a builtin aggregate fact like "#max{X:a(A)} = Y"
static ELPAtom Equal(java.lang.String lefthand, java.lang.String righthand)
          factory method to create an equality relation
 boolean equals(java.lang.Object o)
           
 int getArity()
          returns the arity of the predicate
 ELPAtom getAtom()
          returns the atom of this literal
 ELPLiteral getLiteral()
          returns a possibly nested literal, or the object itself if this literal is not (strict or default) negated.
 java.lang.String getPredicate()
          returns the predicate symbol of this atom
 java.lang.String getTerm(int i)
          returns a term at a given index
 int getTermAsInt(int i)
          returns a term as an integer value
 java.lang.String[] getTerms()
           
 java.lang.String getType()
          returns the predicate symbol and the arity.
static ELPAtom Gtr(java.lang.String lefthand, java.lang.String righthand)
          factory method to create a greater relation literal
static ELPAtom GtrEq(java.lang.String lefthand, java.lang.String righthand)
          factory method to create a greater equal relation
 int hashCode()
           
 ELPAtom instantiate(java.lang.String... terms)
          create an atom based on this objects predicate symbol and number of terms.
static ELPAtom Int(java.lang.String value)
          factory method to create #int predicates
 boolean isArithmetic()
          deprecated, use isPredicate instead !
 boolean isAtom()
           
 boolean isDefaultNegated()
           
 boolean isPredicate()
          this method indicates if the literal appearing in a program is a build-in or external dlv predicate
 boolean isStrictNegated()
           
static ELPAtom Less(java.lang.String lefthand, java.lang.String righthand)
          factory method to create a greater relation literal
static ELPAtom LessEq(java.lang.String lefthand, java.lang.String righthand)
          factory method to create a less equal relation
static ELPAtom Mul(java.lang.String op1, java.lang.String op2, java.lang.String result)
          factory method to create an arithmetic mul literal
static ELPAtom Plus(java.lang.String op1, java.lang.String op2, java.lang.String result)
          factory method to create an arithmetic plus literal
 void setTerm(int i, java.lang.String s)
          assigns the i-th term to given argument. this method does not check i against violating predicate arity.
 void setTerms(ELPAtom other)
           
 java.lang.String toString()
          translates the atom into a human readable string.
static ELPAtom UnEq(java.lang.String lefthand, java.lang.String righthand)
          factory method to create an unequality relation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pred

java.lang.String pred

terms

java.lang.String[] terms
Constructor Detail

ELPAtom

public ELPAtom(ELPAtom other)
default copy constructor


ELPAtom

public ELPAtom(java.lang.String predicate,
               int arity)
instantiates a new atom with a predicate of given arity, but does not set any terms.

Parameters:
predicate - predicate symbol
arity - arity of the predicate

ELPAtom

public ELPAtom(java.lang.String predicate,
               java.lang.String... terms)
creates a new atom

Parameters:
predicate - predicate symbol
terms - optional term symbol

ELPAtom

public ELPAtom(java.lang.String[] symbols,
               int nterm)
create a new atom from a given list of string symbols.

Parameters:
symbols - source strings
nterm - number of strings to read from symbols
Method Detail

getPredicate

public java.lang.String getPredicate()
returns the predicate symbol of this atom

Returns:
predicate symbol (as string)

getArity

public int getArity()
returns the arity of the predicate

Returns:
arity (as integer)

getTerm

public java.lang.String getTerm(int i)
returns a term at a given index

Parameters:
i - term number i
Returns:
term i

getTermAsInt

public int getTermAsInt(int i)
returns a term as an integer value

Parameters:
i - term index i
Returns:
integer value of term i

instantiate

public ELPAtom instantiate(java.lang.String... terms)
create an atom based on this objects predicate symbol and number of terms.

Parameters:
terms - predicate arguments
Returns:
atom made of this object's predicate and given term arguments

setTerms

public void setTerms(ELPAtom other)

getTerms

public java.lang.String[] getTerms()

getType

public java.lang.String getType()
returns the predicate symbol and the arity.

Returns:
string composed of predicate name, followed by "/" and arity

toString

public java.lang.String toString()
translates the atom into a human readable string. the output conforms datalog syntax (dlv or lparse compatible).

Overrides:
toString in class java.lang.Object

isAtom

public boolean isAtom()
Specified by:
isAtom in interface ELPLiteral
Returns:
true if this literal is an atom

isDefaultNegated

public boolean isDefaultNegated()
Specified by:
isDefaultNegated in interface ELPLiteral
Returns:
true if this literal is default negated

isStrictNegated

public boolean isStrictNegated()
Specified by:
isStrictNegated in interface ELPLiteral
Returns:
true if this literal is strictly negated

getLiteral

public ELPLiteral getLiteral()
Description copied from interface: ELPLiteral
returns a possibly nested literal, or the object itself if this literal is not (strict or default) negated.

Specified by:
getLiteral in interface ELPLiteral
Returns:
nested literal

getAtom

public ELPAtom getAtom()
Description copied from interface: ELPLiteral
returns the atom of this literal

Specified by:
getAtom in interface ELPLiteral
Returns:
atom

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isArithmetic

public boolean isArithmetic()
Description copied from interface: ELPLiteral
deprecated, use isPredicate instead !

Specified by:
isArithmetic in interface ELPLiteral
Returns:
true if this objects models an arithmetic expression

setTerm

public void setTerm(int i,
                    java.lang.String s)
assigns the i-th term to given argument. this method does not check i against violating predicate arity.

Parameters:
i - index of term to set
s - term string

Plus

public static ELPAtom Plus(java.lang.String op1,
                           java.lang.String op2,
                           java.lang.String result)
factory method to create an arithmetic plus literal

Parameters:
op1 - first operand
op2 - second operand
result - destination variable
Returns:
predicate representing "RESULT = OP1 + OP2"

Mul

public static ELPAtom Mul(java.lang.String op1,
                          java.lang.String op2,
                          java.lang.String result)
factory method to create an arithmetic mul literal

Parameters:
op1 - first operand
op2 - second operand
result - destination variable
Returns:
predicate representing "RESULT = OP1 * OP2"

Gtr

public static ELPAtom Gtr(java.lang.String lefthand,
                          java.lang.String righthand)
factory method to create a greater relation literal

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND > RIGHTHAND"

Less

public static ELPAtom Less(java.lang.String lefthand,
                           java.lang.String righthand)
factory method to create a greater relation literal

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND < RIGHTHAND"

GtrEq

public static ELPAtom GtrEq(java.lang.String lefthand,
                            java.lang.String righthand)
factory method to create a greater equal relation

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND >= RIGHTHAND"

LessEq

public static ELPAtom LessEq(java.lang.String lefthand,
                             java.lang.String righthand)
factory method to create a less equal relation

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND <= RIGHTHAND"

Equal

public static ELPAtom Equal(java.lang.String lefthand,
                            java.lang.String righthand)
factory method to create an equality relation

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND == RIGHTHAND"

UnEq

public static ELPAtom UnEq(java.lang.String lefthand,
                           java.lang.String righthand)
factory method to create an unequality relation

Parameters:
lefthand - first operand
righthand - second operand
Returns:
predicate representing "LEFTHAND != RIGHTHAND"

Aggregate

public static ELPAtom Aggregate(java.lang.String pred,
                                SymbolicSet symset,
                                java.lang.String rightoperator,
                                java.lang.String rightguard)
factory method to create a builtin aggregate fact like "#max{X:a(A)} = Y"


Aggregate

public static ELPAtom Aggregate(java.lang.String pred,
                                java.lang.String lguard,
                                java.lang.String lgop,
                                java.lang.String rguard,
                                java.lang.String rgop,
                                SymbolicSet symset)
factory method to create a guarded builtin aggregate fact like "1 < #count{X:a(A)} < 3"


Int

public static ELPAtom Int(java.lang.String value)
factory method to create #int predicates


isPredicate

public boolean isPredicate()
Description copied from interface: ELPLiteral
this method indicates if the literal appearing in a program is a build-in or external dlv predicate

Specified by:
isPredicate in interface ELPLiteral
Returns:
true if this object models a dlv predicate