23 #include <opencog/atomspace/atom_types.h>
32 using namespace opencog;
37 :
FreeLink(EVALUATION_LINK, oset, tv, av)
39 if ((2 != oset.size()) or
40 (LIST_LINK != oset[1]->
getType()))
42 throw RuntimeException(TRACE_INFO,
43 "EvaluationLink must have predicate and args!");
50 :
FreeLink(EVALUATION_LINK, schema, args, tv, av)
52 if (LIST_LINK != args->
getType()) {
53 throw RuntimeException(TRACE_INFO,
54 "EvaluationLink must have args in a ListLink!");
62 if (EVALUATION_LINK != tscope) {
63 throw RuntimeException(TRACE_INFO,
64 "Expecting an EvaluationLink");
71 if (2 != ll->getArity())
72 throw RuntimeException(TRACE_INFO,
73 "GreaterThankLink expects two arguments");
74 Handle h1(ll->getOutgoingAtom(0));
75 Handle h2(ll->getOutgoingAtom(1));
79 if (NUMBER_NODE != h1->getType())
82 if (NUMBER_NODE != h2->getType())
88 if (NULL == n1 or NULL == n2)
89 throw RuntimeException(TRACE_INFO,
90 "Expecting c++:greater arguments to be NumberNode's! Got:\n%s\n",
91 (h1==NULL)?
"(invalid handle)" : h1->toShortString().c_str(),
92 (h2==NULL)?
"(invalid handle)" : h2->toShortString().c_str());
94 if (n1->get_value() > n2->get_value())
102 const HandleSeq& oset = ll->getOutgoingSet();
103 if (2 != oset.size())
104 throw RuntimeException(TRACE_INFO,
105 "EqualLink expects two arguments");
106 if (oset[0] == oset[1])
130 if (EVALUATION_LINK == t)
135 else if (EQUAL_LINK == t)
139 else if (GREATER_THAN_LINK == t)
143 else if (NOT_LINK == t)
148 1.0 - tv->getMean(), tv->getCount());
150 throw RuntimeException(TRACE_INFO,
"Expecting to get an EvaluationLink!");
164 throw RuntimeException(TRACE_INFO,
165 "Incorrect arity for an EvaluationLink!");
178 if (GROUNDED_PREDICATE_NODE != gsn->
getType())
180 throw RuntimeException(TRACE_INFO,
"Expecting GroundedPredicateNode!");
182 if (LIST_LINK != args->
getType())
184 throw RuntimeException(TRACE_INFO,
"Expecting arguments to EvaluationLink!");
188 const std::string& schema =
NodeCast(gsn)->getName();
194 if (0 == schema.compare(
"c++:greater"))
202 if (0 == schema.compare(
"c++:exclusive"))
205 Arity sz = ll->getArity();
206 for (
Arity i=0; i<sz-1; i++) {
207 Handle h1(ll->getOutgoingAtom(i));
208 for (
Arity j=i+1; j<sz; j++) {
209 Handle h2(ll->getOutgoingAtom(j));
217 if (0 == schema.compare(0,4,
"scm:", 4))
222 while (
' ' == schema[pos]) pos++;
227 throw RuntimeException(TRACE_INFO,
228 "Cannot evaluate scheme GroundedPredicateNode!");
232 if (0 == schema.compare(0, 3,
"py:", 3))
237 while (
' ' == schema[pos]) pos++;
243 throw RuntimeException(TRACE_INFO,
244 "Cannot evaluate python GroundedPredicateNode!");
249 throw RuntimeException(TRACE_INFO,
250 "Cannot evaluate unknown GroundedPredicateNode: %s",
static TruthValuePtr do_evaluate(AtomSpace *, Handle)
EvaluationLink(const HandleSeq &oset, TruthValuePtr tv=TruthValue::NULL_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
std::vector< Handle > HandleSeq
a list of handles
static TruthValuePtr TRUE_TV()
std::shared_ptr< TruthValue > TruthValuePtr
std::shared_ptr< AttentionValue > AttentionValuePtr
std::shared_ptr< Link > LinkPtr
static NodePtr NodeCast(const Handle &h)
std::shared_ptr< NumberNode > NumberNodePtr
static PythonEval & instance(AtomSpace *atomspace=NULL)
static SchemeEval * get_evaluator(AtomSpace *=NULL)
static Handle do_execute(AtomSpace *, const Handle &)
static TruthValuePtr createTV(strength_t mean, count_t count)
static TruthValuePtr FALSE_TV()
static LinkPtr LinkCast(const Handle &h)
static NumberNodePtr NumberNodeCast(const Handle &h)
TruthValuePtr apply_tv(const std::string &func, Handle varargs)
static TruthValuePtr greater(AtomSpace *as, LinkPtr ll)
unsigned short Type
type of Atoms, represented as short integer (16 bits)
TruthValuePtr apply_tv(AtomSpace *, const std::string &func, Handle varargs)
unsigned short Arity
arity of Links, represented as short integer (16 bits)
static TruthValuePtr equal(AtomSpace *as, LinkPtr ll)