diff --git a/opencog/atoms/atom_types/atom_types.script b/opencog/atoms/atom_types/atom_types.script index 9605ee2775..35f6a51a00 100644 --- a/opencog/atoms/atom_types/atom_types.script +++ b/opencog/atoms/atom_types/atom_types.script @@ -402,7 +402,8 @@ SATISFYING_LINK <- PATTERN_LINK // Both return SetLinks holding the results. // QueryLink is identical to BindLink, except it returns a LinkValue // holding the result, instead of a SetLink. (Less atomspace pollution). -GET_LINK <- SATISFYING_LINK // Finds all groundings, returns them +MEET_LINK <- SATISFYING_LINK // Finds all groundings, returns them +GET_LINK <- MEET_LINK // Finds all groundings, returns them QUERY_LINK <- SATISFYING_LINK // Finds all groundings, substitutes. BIND_LINK <- QUERY_LINK // Finds all groundings, substitutes. diff --git a/opencog/atoms/pattern/CMakeLists.txt b/opencog/atoms/pattern/CMakeLists.txt index 61dac4f281..8ecf2bdbe7 100644 --- a/opencog/atoms/pattern/CMakeLists.txt +++ b/opencog/atoms/pattern/CMakeLists.txt @@ -6,6 +6,7 @@ ADD_LIBRARY (lambda BindLink.cc DualLink.cc GetLink.cc + MeetLink.cc PatternLink.cc PatternTerm.cc PatternUtils.cc @@ -32,6 +33,7 @@ INSTALL (FILES BindLink.h DualLink.h GetLink.h + MeetLink.h PatternLink.h Pattern.h PatternTerm.h diff --git a/opencog/atoms/pattern/GetLink.cc b/opencog/atoms/pattern/GetLink.cc index eaf4650a9b..b7f2c0c3a8 100644 --- a/opencog/atoms/pattern/GetLink.cc +++ b/opencog/atoms/pattern/GetLink.cc @@ -40,26 +40,16 @@ void GetLink::init(void) } GetLink::GetLink(const HandleSeq&& hseq, Type t) - : PatternLink(std::move(hseq), t) + : MeetLink(std::move(hseq), t) { init(); } /* ================================================================= */ -QueueValuePtr GetLink::do_execute(AtomSpace* as, bool silent) -{ - if (nullptr == as) as = _atom_space; - - SatisfyingSet sater(as); - this->satisfy(sater); - - return sater.get_result_queue(); -} - ValuePtr GetLink::execute(AtomSpace* as, bool silent) { - QueueValuePtr qv(do_execute(as, silent)); + QueueValuePtr qv(MeetLink::do_execute(as, silent)); OC_ASSERT(qv->is_closed(), "Unexpected queue state!"); HandleSeq hs(qv->to_handle_seq()); diff --git a/opencog/atoms/pattern/GetLink.h b/opencog/atoms/pattern/GetLink.h index 3bf58aa65b..3dd6030ac2 100644 --- a/opencog/atoms/pattern/GetLink.h +++ b/opencog/atoms/pattern/GetLink.h @@ -22,18 +22,17 @@ #ifndef _OPENCOG_GET_LINK_H #define _OPENCOG_GET_LINK_H -#include +#include namespace opencog { /** \addtogroup grp_atomspace * @{ */ -class GetLink : public PatternLink +class GetLink : public MeetLink { protected: void init(void); - virtual QueueValuePtr do_execute(AtomSpace*, bool silent); public: GetLink(const HandleSeq&&, Type=GET_LINK); @@ -41,7 +40,6 @@ class GetLink : public PatternLink GetLink(const GetLink&) = delete; GetLink operator=(const GetLink&) = delete; - virtual bool is_executable() const { return true; } virtual ValuePtr execute(AtomSpace*, bool silent=false); static Handle factory(const Handle&); diff --git a/opencog/atoms/pattern/MeetLink.cc b/opencog/atoms/pattern/MeetLink.cc new file mode 100644 index 0000000000..0638d0ab80 --- /dev/null +++ b/opencog/atoms/pattern/MeetLink.cc @@ -0,0 +1,67 @@ +/* + * MeetLink.cc + * + * Copyright (C) 2019 Linas Vepstas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License v3 as + * published by the Free Software Foundation and including the + * exceptions at http://opencog.org/wiki/Licenses + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program; if not, write to: + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +#include "MeetLink.h" + +using namespace opencog; + +void MeetLink::init(void) +{ + Type t = get_type(); + if (not nameserver().isA(t, MEET_LINK)) + { + const std::string& tname = nameserver().getTypeName(t); + throw InvalidParamException(TRACE_INFO, + "Expecting a MeetLink, got %s", tname.c_str()); + } +} + +MeetLink::MeetLink(const HandleSeq&& hseq, Type t) + : PatternLink(std::move(hseq), t) +{ + init(); +} + +/* ================================================================= */ + +QueueValuePtr MeetLink::do_execute(AtomSpace* as, bool silent) +{ + if (nullptr == as) as = _atom_space; + + SatisfyingSet sater(as); + this->satisfy(sater); + + return sater.get_result_queue(); +} + +ValuePtr MeetLink::execute(AtomSpace* as, bool silent) +{ + return do_execute(as, silent); +} + +DEFINE_LINK_FACTORY(MeetLink, MEET_LINK) + +/* ===================== END OF FILE ===================== */ diff --git a/opencog/atoms/pattern/MeetLink.h b/opencog/atoms/pattern/MeetLink.h new file mode 100644 index 0000000000..40aaa8dea0 --- /dev/null +++ b/opencog/atoms/pattern/MeetLink.h @@ -0,0 +1,61 @@ +/* + * opencog/atoms/pattern/MeetLink.h + * + * Copyright (C) 2019 Linas Vepstas + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License v3 as + * published by the Free Software Foundation and including the exceptions + * at http://opencog.org/wiki/Licenses + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program; if not, write to: + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef _OPENCOG_MEET_LINK_H +#define _OPENCOG_MEET_LINK_H + +#include + +namespace opencog +{ +/** \addtogroup grp_atomspace + * @{ + */ +class MeetLink : public PatternLink +{ +protected: + void init(void); + virtual QueueValuePtr do_execute(AtomSpace*, bool silent); + +public: + MeetLink(const HandleSeq&&, Type=MEET_LINK); + + MeetLink(const MeetLink&) = delete; + MeetLink operator=(const MeetLink&) = delete; + + virtual bool is_executable() const { return true; } + virtual ValuePtr execute(AtomSpace*, bool silent=false); + + static Handle factory(const Handle&); +}; + +typedef std::shared_ptr MeetLinkPtr; +static inline MeetLinkPtr MeetLinkCast(const Handle& h) + { AtomPtr a(h); return std::dynamic_pointer_cast(a); } +static inline MeetLinkPtr MeetLinkCast(AtomPtr a) + { return std::dynamic_pointer_cast(a); } + +#define createMeetLink std::make_shared + +/** @}*/ +} + +#endif // _OPENCOG_MEET_LINK_H