OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
opencog::FindAtoms Class Reference

#include <FindUtils.h>

Public Member Functions

 FindAtoms (Type t, bool subclass=false)
 
 if (subclass)
 
 FindAtoms (Type ta, Type tb, bool subclass=false)
 
 _target_types ()
 
 _target_atoms ()
 
 FindAtoms (const std::set< Handle > &selection)
 
void search_set (const Handle &h)
 
void search_set (const std::vector< Handle > &hlist)
 

Public Attributes

bool stop_at_quote
 
std::set< Handlevarset
 
std::set< Handleholders
 
std::set< Handleleast_holders
 

Private Types

enum  Loco { NOPE, YEP, IMM }
 

Private Member Functions

Loco find_rec (const Handle &h)
 

Private Attributes

std::set< Type_target_types
 
std::set< Handle_target_atoms
 

Detailed Description

There are two different types of utilities in this file: those that tell you if some target atom or target atom type occurs in some tree, returning a simple yes/no answer, and another utility, telling you exactly where it occurs. We start with the more complicated one first. Otherwise, skip down to get at the simpler ones. The FindAtoms class is used to locate atoms of a given type or target that occur inside some clause. The target is specified in the constructor, the clause to be searched is given with the 'search_set()' method. Aftr the search has been done, the targets are available in the various public members.

Find a "target atom", or find all atoms of a given "target type", and all of the links that hold that target, that occur in a clause (an expression tree formed by the outgoing set.) This is typically used to find all variables in an expression, but it can be used for any purpose.

After search_set() is called, the set of target atoms that were found can be retreived from the public member varset. The set of links that had one of these targets occuring somewhere, anywhere, within them is in the public member holders. This includes the holders of holders, etc, all the way up to the very top. The least_holders member will contain only those links that contain a target in their immediate outgoing set. That is, the least_holders are the smallest links that contain the target.

A "target" is defined in one of two ways: It is either a specified target type, or it is any one of the given set of specific target atoms. When only the type is given, it will typically be VARIABLE_NODE, GROUNDED_PREDICATE_NODE or GROUNDED_SCHEMA_NODE, COMPOSE_LINK, or something like that, and so this just finds these atom types if they occur in the clause(s). Alternately, if a set of specific atoms is given, then this finds the subset of that set that actually occurs in the given clause(s). That is, it computes the intersection between the set of given atoms, and the set of all atoms that occur in the clauses.

Note that anything occuring below a QUOTE_LINK is not explored. Thus, a quote acts like a cut, halting recursion.

Definition at line 84 of file FindUtils.h.

Member Enumeration Documentation

Enumerator
NOPE 
YEP 
IMM 

Definition at line 138 of file FindUtils.h.

Constructor & Destructor Documentation

opencog::FindAtoms::FindAtoms ( Type  t,
bool  subclass = false 
)
inline

Definition at line 92 of file FindUtils.h.

opencog::FindAtoms::FindAtoms ( Type  ta,
Type  tb,
bool  subclass = false 
)
inline

Definition at line 101 of file FindUtils.h.

opencog::FindAtoms::FindAtoms ( const std::set< Handle > &  selection)
inline

Definition at line 117 of file FindUtils.h.

Member Function Documentation

opencog::FindAtoms::_target_atoms ( )
inline

Definition at line 114 of file FindUtils.h.

+ Here is the caller graph for this function:

opencog::FindAtoms::_target_types ( )

+ Here is the caller graph for this function:

Loco opencog::FindAtoms::find_rec ( const Handle h)
inlineprivate

Don't explore link-typed vars!

Definition at line 145 of file FindUtils.h.

References _target_atoms(), _target_types(), opencog::Atom::getType(), holders, IMM, least_holders, opencog::LinkCast(), NOPE, stop_at_quote, python.undocumented.blocksworld::t, varset, and YEP.

+ Here is the caller graph for this function:

opencog::FindAtoms::if ( subclass  )
inline
void opencog::FindAtoms::search_set ( const Handle h)
inline

Given a handle to be searched, create a set of all of the target atoms/types that lie in the outgoing set of the handle (recursively).

Definition at line 128 of file FindUtils.h.

References find_rec().

+ Here is the caller graph for this function:

void opencog::FindAtoms::search_set ( const std::vector< Handle > &  hlist)
inline

Definition at line 133 of file FindUtils.h.

References find_rec().

Member Data Documentation

std::set<Handle> opencog::FindAtoms::_target_atoms
private

Definition at line 179 of file FindUtils.h.

std::set<Type> opencog::FindAtoms::_target_types
private

Definition at line 178 of file FindUtils.h.

std::set<Handle> opencog::FindAtoms::holders

Definition at line 89 of file FindUtils.h.

std::set<Handle> opencog::FindAtoms::least_holders

Definition at line 90 of file FindUtils.h.

bool opencog::FindAtoms::stop_at_quote

Definition at line 87 of file FindUtils.h.

std::set<Handle> opencog::FindAtoms::varset

Definition at line 88 of file FindUtils.h.


The documentation for this class was generated from the following file: