OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-ure commits / cec5509

Remove usage of obsolete API
cec5509762fac3c20046fff7d29284e4ef07fdde
by Linas Vepštas <linasvepstas@gmail.com> · 2025-09-24T00:04:52.000Z

Changed files (8) +32 -32

opencog/ure/MixtureModel.cc +5 -5
……@@ -45,7 +45,7 @@ TruthValuePtr MixtureModel::operator()() const
4545{
4646 // Don't bother mixing if there's only one TV
4747 if (models.size() == 1)
48 return (*models.begin())->getTruthValue();
48 return TruthValueCast((*models.begin())->getValue(truth_key()));
4949
5050 std::vector<TruthValuePtr> tvs;
5151 std::vector<double> weights;
……@@ -53,7 +53,7 @@ TruthValuePtr MixtureModel::operator()() const
5353 double weight = prior_estimate(model) * beta_factor(model);
5454 LAZY_URE_LOG_FINE << "MixtureModel::operator model = " << model->id_to_string()
5555 << ", weight = " << weight;
56 tvs.push_back(model->getTruthValue());
56 tvs.push_back(TruthValueCast(model->getValue(truth_key())));
5757 weights.push_back(weight);
5858 }
5959 return weighted_average(tvs, weights);
……@@ -95,7 +95,7 @@ TruthValuePtr MixtureModel::weighted_average(const std::vector<TruthValuePtr>& t
9595
9696double MixtureModel::beta_factor(const Handle& model) const
9797{
98 BetaDistribution beta_dist(model->getTruthValue());
98 BetaDistribution beta_dist(TruthValueCast(model->getValue(truth_key())));
9999 double factor = boost::math::beta(beta_dist.alpha(), beta_dist.beta());
100100 LAZY_URE_LOG_FINE << "MixtureModel::beta_factor factor = " << factor;
101101 return factor;
……@@ -107,7 +107,7 @@ double MixtureModel::prior_estimate(const Handle& model) const
107107
108108 HandleSet all_atoms(get_all_uniq_atoms(model));
109109 double partial_length = all_atoms.size(),
110 remain_data_size = data_set_size - model->getTruthValue()->get_count(),
110 remain_data_size = data_set_size - TruthValueCast(model->getValue(truth_key()))->get_count(),
111111 kestimate = kolmogorov_estimate(remain_data_size);
112112
113113 LAZY_URE_LOG_FINE << "MixtureModel::prior_estimate "
……@@ -135,6 +135,6 @@ double MixtureModel::infer_data_set_size() const
135135{
136136 double max_count = 0.0;
137137 for (const Handle& model : models)
138 max_count = std::max(max_count, model->getTruthValue()->get_count());
138 max_count = std::max(max_count, TruthValueCast(model->getValue(truth_key()))->get_count());
139139 return max_count;
140140}
opencog/ure/Rule.cc +1 -1
……@@ -219,7 +219,7 @@ void Rule::init(const Handle& rule_alias, const Handle& rule, const Handle& rbs)
219219 _rbs = rbs;
220220 AtomSpace& as = *rule_alias->getAtomSpace();
221221 Handle ml = as.add_link(MEMBER_LINK, rule_alias, rbs);
222 _tv = ml->getTruthValue();
222 _tv = TruthValueCast(ml->getValue(truth_key()));
223223
224224 verify_rule();
225225}
opencog/ure/UREConfig.cc +1 -1
……@@ -310,7 +310,7 @@ bool UREConfig::fetch_bool_param(const string& pred_name,
310310 Handle eval = _as.get_link(EVALUATION_LINK,
311311 std::move(HandleSeq({pred, input})));
312312 if (eval) {
313 bool value = eval->getTruthValue()->get_mean() > 0.5;
313 bool value = TruthValueCast(eval->getValue(truth_key()))->get_mean() > 0.5;
314314 log_param_value(input, pred_name, value);
315315 return value;
316316 }
opencog/ure/backwardchainer/Fitness.cc +1 -1
……@@ -33,7 +33,7 @@ BITNodeFitness::BITNodeFitness(FitnessType ft) : type(ft)
3333 switch(type) {
3434 case (MaximizeConfidence):
3535 function = [](const BITNode& bitnode) {
36 return bitnode.body->getTruthValue()->get_confidence();
36 return TruthValueCast(bitnode.body->getValue(truth_key()))->get_confidence();
3737 };
3838 lower = 0;
3939 upper = 1;
opencog/ure/backwardchainer/TraceRecorder.cc +3 -3
……@@ -99,7 +99,7 @@ void TraceRecorder::proof(const Handle& andbit_fcs, const Handle& target_result)
9999{
100100 add_evaluation(_proof_predicate,
101101 dont_exec(andbit_fcs), target_result,
102 target_result->getTruthValue());
102 TruthValueCast(target_result->getValue(truth_key())));
103103}
104104
105105Handle TraceRecorder::dont_exec(const Handle& h)
……@@ -118,7 +118,7 @@ Handle TraceRecorder::add_execution(const Handle& schema,
118118 return Handle::UNDEFINED;
119119
120120 Handle execution = _trace_as->add_link(EXECUTION_LINK, schema, input, output);
121 execution->setTruthValue(tv);
121 execution->setValue(truth_key(), tv);
122122 return execution;
123123}
124124
……@@ -144,7 +144,7 @@ Handle TraceRecorder::add_evaluation(const Handle& predicate,
144144 return Handle::UNDEFINED;
145145
146146 Handle evaluation = _trace_as->add_link(EVALUATION_LINK, predicate, argument);
147 evaluation->setTruthValue(tv);
147 evaluation->setValue(truth_key(), tv);
148148 return evaluation;
149149}
150150
opencog/ure/forwardchainer/SourceSet.cc +1 -1
……@@ -48,7 +48,7 @@ double calculate_weight(const Handle& bdy, double cpx_fctr)
4848 // TODO:
4949 // 1. Support more fitness functions
5050 // 2. Explicitely turn the fitness into a probability of success
51 TruthValuePtr tv = bdy->getTruthValue();
51 TruthValuePtr tv = TruthValueCast(bdy->getValue(truth_key()));
5252 double fitness = tv->get_mean() * tv->get_confidence();
5353 return std::max(1e-16, cpx_fctr * fitness);
5454}
tests/ure/backwardchainer/BackwardChainerUTest.cxxtest +18 -18
……@@ -237,8 +237,8 @@ void BackwardChainerUTest::test_deduction_tv_query()
237237 bc.get_config().set_maximum_iterations(10);
238238 bc.do_chain();
239239
240 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10);
241 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10);
240 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10);
241 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10);
242242}
243243
244244void BackwardChainerUTest::test_modus_ponens_tv_query()
……@@ -257,8 +257,8 @@ void BackwardChainerUTest::test_modus_ponens_tv_query()
257257 bc.get_config().set_maximum_iterations(40);
258258 bc.do_chain();
259259
260 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10);
261 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10);
260 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10);
261 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10);
262262}
263263
264264void BackwardChainerUTest::test_conjunction_fuzzy_evaluation_tv_query()
……@@ -285,8 +285,8 @@ void BackwardChainerUTest::test_conjunction_fuzzy_evaluation_tv_query()
285285 bc.get_config().set_maximum_iterations(2);
286286 bc.do_chain();
287287
288 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 0.4, 1e-6);
289 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 0.2, 1e-6);
288 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 0.4, 1e-6);
289 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 0.2, 1e-6);
290290}
291291
292292void BackwardChainerUTest::test_conditional_instantiation_1()
……@@ -385,8 +385,8 @@ void BackwardChainerUTest::test_conditional_instantiation_tv_query()
385385 bc.get_config().set_maximum_iterations(20);
386386 bc.do_chain();
387387
388 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, .1);
389 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, .1);
388 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, .1);
389 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, .1);
390390}
391391
392392// This test is for rules that requires the pattern matcher to look
……@@ -474,8 +474,8 @@ void BackwardChainerUTest::test_conditional_partial_instantiation()
474474 bc.get_config().set_maximum_iterations(5);
475475 bc.do_chain();
476476
477 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10);
478 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10);
477 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10);
478 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10);
479479}
480480
481481void BackwardChainerUTest::test_impossible_criminal()
……@@ -553,8 +553,8 @@ void BackwardChainerUTest::test_criminal()
553553 logger().debug() << "expected = " << oc_to_string(expected);
554554
555555 TS_ASSERT_EQUALS(results, expected);
556 TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_mean());
557 TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_confidence());
556 TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_mean());
557 TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_confidence());
558558
559559 // Extract traces and return the backward chainer with these
560560 // traces, which should greatly speed it up.
……@@ -610,8 +610,8 @@ void BackwardChainerUTest::test_criminal()
610610 logger().debug() << "expected = " << oc_to_string(expected);
611611
612612 TS_ASSERT_EQUALS(results, expected);
613 TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_mean());
614 TS_ASSERT_LESS_THAN(0.9, expected_target->getTruthValue()->get_confidence());
613 TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_mean());
614 TS_ASSERT_LESS_THAN(0.9, expected_TruthValueCast(target->getValue(truth_key()))->get_confidence());
615615}
616616
617617// Test showing we no longer need the ExecutionOutputLink
……@@ -668,8 +668,8 @@ void BackwardChainerUTest::xtest_green_balls()
668668
669669 logger().debug() << "results = " << oc_to_string(results);
670670
671 TS_ASSERT_LESS_THAN(0.9, top_result->getTruthValue()->get_mean());
672 TS_ASSERT_LESS_THAN(0.9, top_result->getTruthValue()->get_confidence());
671 TS_ASSERT_LESS_THAN(0.9, TruthValueCast(top_result->getValue(truth_key()))->get_mean());
672 TS_ASSERT_LESS_THAN(0.9, TruthValueCast(top_result->getValue(truth_key()))->get_confidence());
673673}
674674
675675void BackwardChainerUTest::xtest_induction()
……@@ -694,10 +694,10 @@ void BackwardChainerUTest::xtest_induction()
694694 bc.do_chain();
695695
696696 // TODO: fixme, for that we need to support BIT expansion over meta rule
697 TS_ASSERT_DELTA(target->getTruthValue()->get_mean(), 1, 1e-10);
697 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_mean(), 1, 1e-10);
698698 // TODO: determine the expected confidence, which depends on the
699699 // number of instances the induction is based on
700 TS_ASSERT_DELTA(target->getTruthValue()->get_confidence(), 1, 1e-10);
700 TS_ASSERT_DELTA(TruthValueCast(target->getValue(truth_key()))->get_confidence(), 1, 1e-10);
701701}
702702
703703void BackwardChainerUTest::xtest_focus_set()
tests/ure/backwardchainer/GradientUTest.cxxtest +2 -2
……@@ -186,11 +186,11 @@ void GradientUTest::set_rbs()
186186 // Assign GradientSum and its weight to rbs
187187 TruthValuePtr stv = SimpleTruthValue::createTV(0.4, 1.0);
188188 Handle GSM = L(MEMBER_LINK, GradientSum, rbs);
189 GSM->setTruthValue(stv);
189 GSM->setValue(truth_key(), stv);
190190
191191 // Assign GradientAny and its weight to rbs
192192 Handle GAM = L(MEMBER_LINK, GradientAny, rbs);
193 GAM->setTruthValue(stv);
193 GAM->setValue(truth_key(), stv);
194194}
195195
196196void GradientUTest::setUp()