use crate::{entity::ShortFloat, global::Float, symbols::*, util::ToDisplayAndBrief};
use nar_dev_utils::join;
use narsese::lexical::Truth as LexicalTruth;
pub trait Truth: ToDisplayAndBrief {
fn frequency(&self) -> ShortFloat;
fn frequency_mut(&mut self) -> &mut ShortFloat;
fn confidence(&self) -> ShortFloat;
fn confidence_mut(&mut self) -> &mut ShortFloat;
fn fc(&self) -> [ShortFloat; 2] {
[self.frequency(), self.confidence()]
}
fn fc_with(&self, other: &impl Truth) -> ([ShortFloat; 2], [ShortFloat; 2]) {
(self.fc(), other.fc())
}
fn is_analytic(&self) -> bool;
fn set_analytic(&mut self);
fn expectation(&self) -> Float {
self.confidence().value() * (self.frequency().value() - 0.5) + 0.5
}
#[doc(alias = "get_exp_dif_abs")]
#[doc(alias = "expectation_absolute_difference")]
fn expectation_abs_dif(&self, other: &impl Truth) -> Float {
(self.expectation() - other.expectation()).abs()
}
fn is_negative(&self) -> bool {
self.frequency() < ShortFloat::HALF
}
#[inline]
fn is_positive(&self) -> bool {
!self.is_negative()
}
fn truth_eq(&self, other: &impl Truth) -> bool {
self.frequency() == other.frequency() && self.confidence() == other.frequency()
}
fn truth_to_display(&self) -> String {
join!(
=> MARK.to_string()
=> self.frequency().to_display()
=> SEPARATOR
=> self.confidence().to_display()
=> MARK
)
}
fn truth_to_display_brief(&self) -> String {
MARK.to_string()
+ &self.frequency().to_display_brief()
+ SEPARATOR
+ &self.confidence().to_display_brief()
+ MARK
}
fn truth_to_lexical(&self) -> LexicalTruth {
vec![self.frequency().to_string(), self.confidence().to_string()]
}
}
const MARK: &str = TRUTH_VALUE_MARK;
const SEPARATOR: &str = VALUE_SEPARATOR;