36 using namespace opencog;
40 #ifdef USE_KEYWORD_LIST_NOT_USED
54 static TruthValue *get_tv_from_kvp(SCM kvp,
const char * subrname,
int pos)
56 if (!scm_is_pair(kvp))
return NULL;
60 SCM skey = SCM_CAR(kvp);
63 if (!scm_is_keyword(skey))
64 scm_wrong_type_arg_msg(subrname, pos, skey,
"keyword");
66 skey = scm_keyword_to_symbol(skey);
67 skey = scm_symbol_to_string(skey);
68 char * key = scm_to_utf8_string(skey);
72 if (!scm_is_pair(kvp))
74 scm_wrong_type_arg_msg(subrname, pos, kvp,
"value following keyword");
77 if (0 == strcmp(key,
"tv"))
79 SCM sval = SCM_CAR(kvp);
80 scm_t_bits misctype = SCM_SMOB_FLAGS(sval);
81 if (misctype != COG_SIMPLE_TV)
82 scm_wrong_type_arg_msg(subrname, pos, sval,
"opencog truth value");
92 while (scm_is_pair(kvp));
105 while (scm_is_pair(slist))
107 SCM sval = SCM_CAR(slist);
110 scm_t_bits misctype = SCM_SMOB_FLAGS(sval);
120 slist = SCM_CDR(slist);
135 std::string ret =
"";
161 snprintf(buff,
BUFLEN,
"(itv %.8g ", itv->
getL());
205 scm_remember_upto_here_1(s);
215 return take_tv(tvp->rawclone());
223 scm_gc_register_collectable_memory (tv,
224 sizeof(*tv),
"opencog tv");
228 SCM_SET_SMOB_FLAGS(smob,
COG_TV);
238 double mean = scm_to_double(smean);
239 double confidence = scm_to_double(sconfidence);
248 double mean = scm_to_double(smean);
249 double confidence = scm_to_double(sconfidence);
250 double count = scm_to_double(scount);
258 double lower = scm_to_double(slower);
259 double upper = scm_to_double(supper);
260 double confidence = scm_to_double(sconfidence);
268 double mean = scm_to_double(smean);
269 double confidence = scm_to_double(sconfidence);
270 double count = scm_to_double(scount);
278 double mean = scm_to_double(smean);
279 double confidence = scm_to_double(sconfidence);
294 scm_t_bits misctype = SCM_SMOB_FLAGS(s);
312 if (SCM_BOOL_F ==
ss_tv_p(s))
return SCM_BOOL_F;
316 scm_remember_upto_here_1(s);
317 if (wanted == tvt)
return SCM_BOOL_T;
351 scm_wrong_type_arg_msg(subrname, pos, stv,
"opencog truth value");
353 scm_t_bits misctype = SCM_SMOB_FLAGS(stv);
355 scm_wrong_type_arg_msg(subrname, pos, stv,
"opencog truth value");
373 SCM mean = scm_from_double(stv->
getMean());
375 SCM count = scm_from_double(stv->
getCount());
376 SCM smean = scm_from_utf8_symbol(
"mean");
377 SCM sconf = scm_from_utf8_symbol(
"confidence");
378 SCM scount = scm_from_utf8_symbol(
"count");
381 rc = scm_acons(sconf, conf, rc);
382 rc = scm_acons(smean, mean, rc);
383 rc = scm_acons(scount, count, rc);
384 scm_remember_upto_here_1(s);
390 SCM mean = scm_from_double(ctv->
getMean());
392 SCM cont = scm_from_double(ctv->
getCount());
393 SCM smean = scm_from_utf8_symbol(
"mean");
394 SCM sconf = scm_from_utf8_symbol(
"confidence");
395 SCM scont = scm_from_utf8_symbol(
"count");
398 rc = scm_acons(scont, cont, rc),
399 rc = scm_acons(sconf, conf, rc);
400 rc = scm_acons(smean, mean, rc);
401 scm_remember_upto_here_1(s);
407 SCM lower = scm_from_double(itv->
getL());
408 SCM upper = scm_from_double(itv->
getU());
410 SCM slower = scm_from_utf8_symbol(
"lower");
411 SCM supper = scm_from_utf8_symbol(
"upper");
412 SCM sconf = scm_from_utf8_symbol(
"confidence");
415 rc = scm_acons(sconf, conf, rc);
416 rc = scm_acons(supper, upper, rc),
417 rc = scm_acons(slower, lower, rc);
418 scm_remember_upto_here_1(s);
424 SCM mean = scm_from_double(ptv->
getMean());
426 SCM cont = scm_from_double(ptv->
getCount());
427 SCM smean = scm_from_utf8_symbol(
"mean");
428 SCM sconf = scm_from_utf8_symbol(
"confidence");
429 SCM scont = scm_from_utf8_symbol(
"count");
432 rc = scm_acons(scont, cont, rc),
433 rc = scm_acons(sconf, conf, rc);
434 rc = scm_acons(smean, mean, rc);
435 scm_remember_upto_here_1(s);
441 SCM mean = scm_from_double(ftv->
getMean());
443 SCM count = scm_from_double(ftv->
getCount());
444 SCM smean = scm_from_utf8_symbol(
"mean");
445 SCM sconf = scm_from_utf8_symbol(
"confidence");
446 SCM scount = scm_from_utf8_symbol(
"count");
449 rc = scm_acons(sconf, conf, rc);
450 rc = scm_acons(smean, mean, rc);
451 rc = scm_acons(scount, count, rc);
452 scm_remember_upto_here_1(s);
456 scm_remember_upto_here_1(s);
459 scm_remember_upto_here_1(s);
confidence_t getConfidence() const
strength_t getMean() const
a TruthValue that stores a mean and the number of observations (strength and confidence) ...
strength_t getMean() const
virtual TruthValueType getType() const =0
confidence_t getConfidence() const
std::shared_ptr< TruthValue > TruthValuePtr
virtual TruthValuePtr clone() const =0
static SCM ss_new_ptv(SCM, SCM, SCM)
static scm_t_bits cog_misc_tag
static count_t confidenceToCount(confidence_t)
static std::string tv_to_string(const TruthValue *)
static SCM tv_to_scm(TruthValuePtr)
confidence_t getConfidenceLevel() const
static SCM ss_tv_get_value(SCM)
confidence_t getConfidence() const
static SCM ss_new_ctv(SCM, SCM, SCM)
a TruthValue that stores a mean and the number of observations (strength and confidence) ...
confidence_t getConfidence() const
static count_t confidenceToCount(confidence_t)
static SCM ss_new_ftv(SCM, SCM)
static SCM take_tv(TruthValue *)
static SCM tv_p(SCM, TruthValueType)
static SCM ss_new_itv(SCM, SCM, SCM)
static TruthValue * verify_tv(SCM, const char *, int pos=1)
confidence_t getConfidence() const
static SCM ss_new_stv(SCM, SCM)
strength_t getMean() const
a TruthValue that stores a mean, a confidence and the number of observations
static TruthValuePtr to_tv(SCM)
a TruthValue that stores a mean, a confidence and the number of observations
strength_t getMean() const
static TruthValue * get_tv_from_list(SCM)