|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jess.ValueVector jess.Fact
A Fact is the fundamental unit of information in Jess's working memory. A Fact is stored as a list in which all the entries correspond to slots. The head or name of the fact is stored in a separate variable (available via the getName() method.)
To construct a Fact, you must specify the "head" either as a String
to the constructor, or by specifying the deftemplate to use. Then
you have to populate the slots using setSlotValue(java.lang.String, jess.Value)
. Finally, you
can add it to a Rete object's working memory using the Rete.assertFact(jess.Fact)
method.
In the following example, we create a template and assert an unordered fact that uses it.
Rete r = new Rete(); r.eval("(deftemplate point \"A 2D point\" (slot x) (slot y))"); Fact f = new Fact("point", r); f.setSlotValue("x", new Value(37, RU.INTEGER)); f.setSlotValue("y", new Value(49, RU.INTEGER)); r.assertFact(f);Constructing an Unordered Fact from Java
In this example, the template has a multislot. In Java, a
multislot is represented by a Value
of type RU.LIST
.
The Value object contains a ValueVector
containing
the fields of the multislot.
Rete r = new Rete(); r.eval("(deftemplate vector \"A named vector\" (slot name) (multislot list))"); Fact f = new Fact("vector", r); f.setSlotValue("name", new Value("Groceries", RU.SYMBOL)); ValueVector vv = new ValueVector(); vv.add(new Value("String Beans", RU.STRING)); vv.add(new Value("Milk", RU.STRING)); vv.add(new Value("Bread", RU.STRING)); f.setSlotValue("list", new Value(vv, RU.LIST)); r.assertFact(f);Constructing an Ordered Fact from Java
An ordered fact is actually represented as an unordered fact with a single slot: a multislot named __data. You don't need to create a template for an ordered fact: one will be created automatically if it doesn't already exist.
Once you assert a jess.Fact object, you no longer "own" it - it
becomes part of the Rete object's internal data structures. As such,
you must not change the values of any of the Fact's slots. If you
retract the fact, the Fact object is released and you are free to
alter it as you wish. Alternatively, you can use the method Rete.modify(jess.Fact, java.lang.String, jess.Value)
to modify a fact.
Field Summary | |
static int |
DYNAMIC
Return value from getShadowMode() that indicates a Fact is a dynamic shadow fact. |
static int |
NO
Return value from getShadowMode() that indicates a Fact is not a shadow fact. |
static int |
STATIC
Return value from getShadowMode() that indicates a Fact is a static shadow fact. |
Fields inherited from class jess.ValueVector |
m_ptr, m_v |
Constructor Summary | |
Fact(Deftemplate template)
Basic constructor. |
|
Fact(Fact f)
Create a Fact from another Fact. |
|
Fact(java.lang.String name,
Rete engine)
Basic constructor. |
Method Summary | |
java.lang.Object |
accept(Visitor v)
A proper accept() implementation should call one of the visitXXX() methods on the Visitor. |
java.lang.Object |
clone()
Make a copy of this fact |
boolean |
equals(java.lang.Object o)
Compare this Fact to another Fact to determine their equality. |
Value |
get(int i)
Returns the entry at position i in this ValueVector. |
java.lang.String |
getConstructType()
Return the String "fact". |
Deftemplate |
getDeftemplate()
Return the deftemplate for this fact. |
java.lang.String |
getDocstring()
Always returns null |
int |
getFactId()
Returns this Fact's fact-id. |
Fact |
getIcon()
Return the canonical representation of this Fact object. |
java.lang.String |
getModule()
Return the name of the module this fact is a member of. |
java.lang.String |
getName()
Returns the name or "head" of this Fact. |
int |
getShadowMode()
Indicates whether this fact is a shadow fact, and if so, what type. |
Value |
getSlotValue(java.lang.String slotname)
Return the value from the named slot. |
int |
getTime()
Return the "pseudotime" at which this Fact was asserted or last modified. |
int |
hashCode()
Return a hash code for this fact based on its name and the contents of all of its slots. |
boolean |
isShadow()
Indicates whether this Fact is a "shadow fact". |
void |
setSlotValue(java.lang.String slotname,
Value value)
Set the value in the named slot. |
java.lang.String |
toString()
Pretty-print this fact into a String. |
java.lang.String |
toStringWithParens()
Pretty-print this fact into a String. |
Methods inherited from class jess.ValueVector |
add, add, add, add, add, add, add, addAll, addAll, cloneInto, copy, remove, set, setLength, size |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NO
public static final int DYNAMIC
public static final int STATIC
Constructor Detail |
public Fact(Deftemplate template) throws JessException
template
- the deftemplate to use
JessException
- if anything goes wrongpublic Fact(java.lang.String name, Rete engine) throws JessException
name
- the head or name of the factengine
- the engine in which to find the deftemplate
JessException
- if anything goes wrongpublic Fact(Fact f) throws JessException
f
- another Fact object to copy
JessException
- if anything goes wrongMethod Detail |
public Fact getIcon()
public java.lang.String getName()
getName
in interface Named
public int getFactId()
public boolean isShadow()
public int getShadowMode()
public final Deftemplate getDeftemplate()
public final java.lang.String getModule()
getModule
in interface Modular
public int getTime()
public Value get(int i) throws JessException
ValueVector
get
in class ValueVector
i
- the 0-based index of the Value to fetch
JessException
public java.lang.Object clone()
clone
in class ValueVector
public final Value getSlotValue(java.lang.String slotname) throws JessException
slotname
- the name of a slot in this fact
JessException
- if anything goes wrongpublic final void setSlotValue(java.lang.String slotname, Value value) throws JessException
slotname
- the name of the slotvalue
- the new value for the slot
JessException
- if anything goes wrongpublic java.lang.String toString()
toString
in class ValueVector
public java.lang.String toStringWithParens()
toStringWithParens
in class ValueVector
public boolean equals(java.lang.Object o)
equals
in class ValueVector
o
- a Fact to compare to
public int hashCode()
hashCode
in class ValueVector
public final java.lang.String getConstructType()
getConstructType
in interface Named
public final java.lang.String getDocstring()
getDocstring
in interface Named
public java.lang.Object accept(Visitor v)
Visitable
accept
in interface Visitable
v
- a visitor to invoke
|
© 2007 Sandia Corporation | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |