diff --git a/opencog/rule-engine/URECommons.cc b/opencog/rule-engine/URECommons.cc index 6203d5d894..6e567420e6 100644 --- a/opencog/rule-engine/URECommons.cc +++ b/opencog/rule-engine/URECommons.cc @@ -37,22 +37,6 @@ URECommons::~URECommons() { } -Handle URECommons::create_quoted(Handle himplicant) -{ - Handle hquoted; - if (LinkCast(himplicant)) { - HandleSeq hs = as_->getOutgoing(himplicant); - HandleSeq hs_new; - for (Handle h : hs) - hs_new.push_back(create_quoted(h)); - hquoted = as_->addLink(as_->getType(himplicant), hs_new); - } else if (as_->getType(himplicant) == VARIABLE_NODE) - hquoted = as_->addLink(QUOTE_LINK, himplicant); - else - hquoted = himplicant; - return hquoted; -} - Handle URECommons::create_bindLink(Handle himplicant, bool vnode_is_typedv) throw (opencog::InvalidParamException) { @@ -107,67 +91,6 @@ bool URECommons::exists_in(Handle& hlink, Handle& h) } } -void URECommons::clean_up_bind_link(Handle& hbind_link) - throw (opencog::InvalidParamException) -{ - if (as_->getType(hbind_link) != BIND_LINK) { - throw InvalidParamException(TRACE_INFO, - "Input must be a BIND_LINK type"); - } - remove_vnode_containing_links(hbind_link); -} - -void URECommons::remove_vnode_containing_links(Handle& h) -{ - if (LinkCast(h)) { - auto vnodes = get_outgoing_nodes(h, {VARIABLE_NODE}); - if (not vnodes.empty()) { - HandleSeq outgoings = as_->getOutgoing(h); - as_->removeAtom(h); - for (Handle h : outgoings) - remove_vnode_containing_links(h); - } - } else if (NodeCast(h)) - if (as_->getType(h) == VARIABLE_NODE) - as_->removeAtom(h); - -} - -void URECommons::clean_up_implication_link(Handle& himplication_link) - throw (opencog::InvalidParamException) -{ - if (as_->getType(himplication_link) != IMPLICATION_LINK) - throw InvalidParamException(TRACE_INFO, - "Input must be an ImplicationLink type "); - remove_vnode_containing_links(himplication_link); -} - -string URECommons::get_unique_name(Handle& h) -{ -//xxx temporary implementation. need to be replaced by uuid generation for making sure name is always unique - string name = as_->getName(h); - HandleSeq hs = as_->getIncoming(h); - if (!hs.empty()) - name.append(to_string(hs[0].value())); - name.append("-bcgen"); - return name; -} - -Handle URECommons::replace_nodes_with_varnode(Handle& handle, - Type t /*=VARIABLE_NODE*/) -{ - UnorderedHandleSet hvars; - if (t == NODE) - hvars = get_outgoing_nodes(handle); // Get every node - else - hvars = get_outgoing_nodes(handle, {t}); - map node_unique_var_map; - for (Handle h : hvars) - node_unique_var_map[h] = as_->addNode(VARIABLE_NODE, - get_unique_name(h)); //TODO get_uuid is not implemented - return change_node_types(handle, node_unique_var_map); -} - Handle URECommons::change_node_types(Handle& h, map& replacement_map) { diff --git a/opencog/rule-engine/URECommons.h b/opencog/rule-engine/URECommons.h index 73e62d066a..9dd8ffd621 100644 --- a/opencog/rule-engine/URECommons.h +++ b/opencog/rule-engine/URECommons.h @@ -58,44 +58,18 @@ class URECommons { * checks if a handle already exists in a HandleSeq */ bool exists_in(Handle& hlink, Handle& h); - /** - *wraps all variables of the input handle in a QuoteLink. TODO adding flexibility for wrapping particular variables only - *@param himplicant a Handle containing variables - *@param as the atomspase containing himplicant - */ - Handle create_quoted(Handle himplicant); - /** - * Remove created bind link and quote links inf exist - * @param hbindLink a reference to the bindLink to be removed - */ - void clean_up_bind_link(Handle& hbindLink) - throw (opencog::InvalidParamException); - /** - * Remove implication link created with unique vars - */ - void clean_up_implication_link(Handle& himplication_link) - throw (opencog::InvalidParamException); - /** - * Remove a variable node. All the incoming sets are also removed - * in a recursive manner. - * - * @param h a var node to be deleted - */ - void remove_vnode_containing_links(Handle& h); + /** * create a copy of the given implicatoin link with unique variables */ Handle replace_nodes_with_varnode(Handle& himplication_link, Type t = VARIABLE_NODE); - /* - * Generate UUID - */ - string get_unique_name(Handle& h); //TODO implement this /** * create a copy of the handle with a different variable name passed in @param var_uniq_var map input */ Handle change_node_types(Handle& h, map& replacement_map); + /** * Get top level parent of the handle * @return a Link or Handle::UNDEFINED if there is no