OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <VariableList.h>
Public Member Functions | |
VariableList (const HandleSeq &vardecls, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
VariableList (Link &) | |
const Variables & | get_variables (void) const |
bool | is_type (const Handle &) const |
bool | is_type (const HandleSeq &) const |
Handle | substitute (const Handle &tree, const HandleSeq &vals) const |
![]() | |
Link (Type t, const HandleSeq &oset, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
Link (Type t, const Handle &h, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
Link (Type t, const Handle &ha, const Handle &hb, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
Link (Type t, const Handle &ha, const Handle &hb, const Handle &hc, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
Link (Type t, const Handle &ha, const Handle &hb, const Handle &hc, const Handle &hd, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
Link (Link &l) | |
~Link () | |
Arity | getArity () const |
const HandleSeq & | getOutgoingSet () const |
Handle | getOutgoingAtom (Arity pos) const throw (RuntimeException) |
template<class T > | |
bool | foreach_outgoing (bool(T::*cb)(const Handle &), T *data) |
std::string | toString (std::string indent="") |
std::string | toShortString (std::string indent="") |
bool | isSource (Handle) const throw (InvalidParamException) |
bool | isSource (size_t) const throw (IndexErrorException, InvalidParamException) |
bool | isTarget (Handle) const throw (InvalidParamException) |
bool | isTarget (size_t) const throw (IndexErrorException, InvalidParamException) |
virtual bool | operator== (const Atom &) const |
virtual bool | operator!= (const Atom &) const |
![]() | |
virtual | ~Atom () |
Type | getType () const |
bool | isType (Type t, bool subclass) const |
Handle | getHandle () |
AttentionValuePtr | getAttentionValue () |
void | setAttentionValue (AttentionValuePtr) |
Sets the AttentionValue object of the atom. More... | |
AttentionValue::sti_t | getSTI () |
Handy-dandy convenience getters for attention values. More... | |
AttentionValue::lti_t | getLTI () |
AttentionValue::vlti_t | getVLTI () |
void | setSTI (AttentionValue::sti_t stiValue) |
void | setLTI (AttentionValue::lti_t ltiValue) |
void | incVLTI () |
void | decVLTI () |
TruthValuePtr | getTruthValue () |
void | setTruthValue (TruthValuePtr) |
Sets the TruthValue object of the atom. More... | |
void | merge (TruthValuePtr) |
Handle | tvmerge (TruthValuePtr tv) |
size_t | getIncomingSetSize () |
Get the size of the incoming set. More... | |
IncomingSet | getIncomingSet () |
template<typename OutputIterator > | |
OutputIterator | getIncomingSet (OutputIterator result) |
template<class T > | |
bool | foreach_incoming (bool(T::*cb)(const Handle &), T *data) |
template<typename OutputIterator > | |
OutputIterator | getIncomingSetByType (OutputIterator result, Type type, bool subclass=false) |
IncomingSet | getIncomingSetByType (Type type, bool subclass=false) |
Protected Member Functions | |
void | get_vartype (const Handle &) |
void | validate_vardecl (const Handle &) |
void | validate_vardecl (const HandleSeq &) |
VariableList (Type, const HandleSeq &, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
void | build_index (void) |
Handle | substitute_nocheck (const Handle &, const HandleSeq &) const |
![]() | |
Atom (Type t, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV()) | |
void | keep_incoming_set () |
void | drop_incoming_set () |
void | insert_atom (LinkPtr) |
Add an atom to the incoming set. More... | |
void | remove_atom (LinkPtr) |
Remove an atom from the incoming set. More... | |
Protected Attributes | |
Variables | _varlist |
Unbundled variables and types for them. More... | |
![]() | |
HandleSeq | _outgoing |
![]() | |
UUID | _uuid |
AtomTable * | _atomTable |
Type | _type |
char | _flags |
TruthValuePtr | _truthValue |
AttentionValuePtr | _attentionValue |
std::mutex | _mtx |
InSetPtr | _incoming_set |
Additional Inherited Members | |
![]() | |
typedef std::shared_ptr< InSet > | InSetPtr |
The VariableList class records it's outgoing set in various ways that make it easier and faster to work with in C++. It implements a substitute method that will replace all variables in a tree by the corresponding atoms that it is given. See the .cc file for more info.
The constructors make sure that the contents of the variable list are syntactically correct; i.e that it actually contains variables. Otherwise, it throws an error on bad syntax. Thus, bad VariableLists cannot be inserted into the atomspace.
Definition at line 48 of file VariableList.h.
|
protected |
Definition at line 62 of file VariableList.cc.
References validate_vardecl().
VariableList::VariableList | ( | const HandleSeq & | vardecls, |
TruthValuePtr | tv = TruthValue::DEFAULT_TV() , |
||
AttentionValuePtr | av = AttentionValue::DEFAULT_AV() |
||
) |
Definition at line 55 of file VariableList.cc.
References validate_vardecl().
VariableList::VariableList | ( | Link & | l | ) |
Definition at line 71 of file VariableList.cc.
References opencog::Link::_outgoing, opencog::classserver(), opencog::Atom::getType(), opencog::ClassServer::getTypeName(), and validate_vardecl().
|
protected |
Build the index from variable name, to its ordinal number. The index is needed for variable substitution, i.e. for the substitute method below. The specific sequence order of the variables is essential for making substitution work.
Definition at line 292 of file VariableList.cc.
References _varlist, opencog::Variables::index, and opencog::Variables::varseq.
|
inline |
Definition at line 75 of file VariableList.h.
References _varlist.
|
protected |
Extract the variable type(s) from a TypedVariableLink
The call is expecting htypelink to point to one of the two following structures:
TypedVariableLink VariableNode "$some_var_name" TypeNode "ConceptNode"
or
TypedVariableLink VariableNode "$some_var_name" TypeChoice TypeNode "ConceptNode" TypeNode "NumberNode" TypeNode "WordNode"
In either case, the variable itself is appended to "vset", and the list of allowed types are associated with the variable via the map "typemap".
Definition at line 114 of file VariableList.cc.
References _varlist, opencog::classserver(), opencog::Atom::getType(), opencog::LinkCast(), python.undocumented.blocksworld::t, opencog::Variables::typemap, opencog::TypeNodeCast(), opencog::Variables::varseq, and opencog::Variables::varset.
bool VariableList::is_type | ( | const Handle & | h | ) | const |
Simple type checker.
Returns true/false if the indicated handle is of the type that we have memoized. If this typelist contians more than one type in it, then clearly, there is a mismatch. If there are no type restrictions, then it is trivially a match. Otherwise, there must be a TypeChoice, and so the handle must be one of the types in the TypeChoice.
Definition at line 233 of file VariableList.cc.
References _varlist, opencog::Atom::getType(), opencog::Variables::typemap, opencog::Variables::varseq, and opencog::Variables::varset.
bool VariableList::is_type | ( | const HandleSeq & | hseq | ) | const |
Very simple type checker.
Returns true/false if the indicated handles are of the type that we have memoized.
XXX TODO this does not currently handle type equations, as outlined on the wiki; We would need the general pattern matcher to do type checking, in that situation.
Definition at line 262 of file VariableList.cc.
References _varlist, opencog::Variables::typemap, opencog::Variables::varseq, and opencog::Variables::varset.
Substitute variables in tree with the indicated values. This is a lot like applying the function fun to the argument list args, except that no actual evaluation is performed; only substitution. The resulting tree is NOT placed into any atomspace, either. If you want that, you must do it youself. If you want evaluation or execution to happen during sustitution, use either the EvaluationLink, the ExecutionOutputLink, or the Instantiator.
So, for example, if this VariableList contains:
VariableList VariableNode $a VariableNode $b
and func is the template:
EvaluationLink PredicateNode "something" ListLink VariableNode $b ; note the reversed order VariableNode $a
and the args is a list
ConceptNode "one" NumberNode 2.0000
then the returned value will be
EvaluationLink PredicateNode "something" ListLink NumberNode 2.0000 ; note reversed order here, also ConceptNode "one"
That is, the values "one" and 2.0 were substituted for $a and $b.
The func can be, for example, a single variable name(!) In this case, the corresponding arg is returned. So, for example, if the func was simple $b, then 2.0 would be returned.
Type checking is performed before subsitution; if the args fail to satisfy the type constraints, an exception is thrown.
Again, only a substitution is performed, there is no evaluation. Note also that the resulting tree is NOT placed into any atomspace!
Definition at line 351 of file VariableList.cc.
References _varlist, is_type(), substitute_nocheck(), and opencog::Variables::varseq.
|
protected |
Definition at line 366 of file VariableList.cc.
References _varlist, createLink, opencog::Atom::getType(), opencog::Atom::Handle, opencog::Variables::index, and opencog::LinkCast().
|
protected |
Validate variable declarations for syntax correctness.
This will check to make sure that a set of variable declarations are of a reasonable form. Thus, for example, a structure similar to the below is expected.
VariableList VariableNode "$var0" VariableNode "$var1" TypedVariableLink VariableNode "$var2" TypeNode "ConceptNode" TypedVariableLink VariableNode "$var3" TypeChoice TypeNode "PredicateNode" TypeNode "GroundedPredicateNode"
As a side-effect, the variables and type restrictions are unpacked.
Definition at line 192 of file VariableList.cc.
References _varlist, build_index(), get_vartype(), opencog::Atom::getType(), opencog::LinkCast(), opencog::NodeCast(), opencog::Variables::varseq, and opencog::Variables::varset.
|
protected |
Definition at line 33 of file VariableList.cc.
References _varlist, build_index(), opencog::classserver(), get_vartype(), python.undocumented.blocksworld::t, opencog::Variables::varseq, and opencog::Variables::varset.
|
protected |
Unbundled variables and types for them.
Definition at line 52 of file VariableList.h.