UNPKG

human-logic

Version:
175 lines (174 loc) 6.33 kB
/** * Fuzzy Common Sense Logic * * Human Logic (also known as “common sense”) is based on five categories: * - `true` = certainly positive * - `false` = certainly negative * - `maybe` = uncertain (could be either positive or negative) * - `never` = impossible (neither positive nor negative) * - `undefined` = totally unknown * * In Fuzzy Common Sense Logic the value is five-dimensional unit vector. * Each vector component is a fuzzy value (between 0.0 and 1.0 inclusive) * of respective `true`, `false`, `maybe`, `never` or `undefined` category. * @module */ /** @hidden */ import { Fuzzy } from './Fuzzy'; /** @hidden */ import { Category, UNDEF, FALSE, NEVER, MAYBE, TRUE } from './Category'; /** * Object-like hash to provide and receive Fuzzy Common Sense logical values where {@link Category} * values are used as keys. */ export interface LogicValues { [UNDEF]: Fuzzy; [FALSE]: Fuzzy; [NEVER]: Fuzzy; [MAYBE]: Fuzzy; [TRUE]: Fuzzy; } /** * Main Fuzzy Common Sense Logic Class */ export declare class Logic { private values; /** * Basic constructor. See {@link fromCategory}, {@link fromArray} and {@link fromValues} * for more convenient instantiation methods. */ constructor(_undef?: Fuzzy, _false?: Fuzzy, _never?: Fuzzy, _maybe?: Fuzzy, _true?: Fuzzy); /** * Creates new {@link Logic} instance with {@link Fuzzy.FUZZY_TRUE} value for the specified `category` * (and {@link Fuzzy.FUZZY_FALSE} for all other categories). */ static fromCategory(category: Category): Logic; /** * Creates new {@link Logic} instance from array of {@link Fuzzy} values. * @param fuzzy The categories order in array is: {@link Category.UNDEF}, {@link Category.FALSE}, * {@link Category.NEVER}, {@link Category.MAYBE}, {@link Category.TRUE}. */ static fromArray(fuzzy: Fuzzy[]): Logic; /** * Creates new {@link Logic} instance from {@link LogicValues}. */ static fromValues(fuzzy: LogicValues): Logic; /** * Retrieves an array of {@link Fuzzy} values. * @return The categories order in array is: {@link Category.UNDEF}, {@link Category.FALSE}, * {@link Category.NEVER}, {@link Category.MAYBE}, {@link Category.TRUE}. */ asArray(): Fuzzy[]; /** * Dominating {@link Category} or `undefined` if none of the categories * has a value greater than {@link Fuzzy.FUZZY_FALSE}. */ asCategory(): Category | undefined; /** * Retrieves a copy of {@link LogicValues}. * @return A clone, a new instance of {@link LogicValues} created from the values kept internally. */ asValues(): LogicValues; protected getValues(): LogicValues; /** * Creates a deep copy (a clone) of a current instance. */ clone(): Logic; /** * String representation of five-dimensional vector of {@link Fuzzy} values. * The categories order is: {@link Category.UNDEF}, {@link Category.FALSE}, {@link Category.NEVER}, * {@link Category.MAYBE}, {@link Category.TRUE}. */ toString(): string; /** * Returns {@link Fuzzy} value of the specified category of this {@link Logic} object. */ get(category: Category): Fuzzy; protected scalar(): number; protected normalizer(): number; /** * Returns normalized {@link Fuzzy} value for the specified category. See {@link normalize} for details. */ getNormalized(category: Category): Fuzzy; /** * If original values are not normalized, returns new Logic object with normalized {@link Logic} value, * otherwise return the same object. * * The {@link Logic} value is normalized if and only if the sum of {@link Fuzzy} values of all categories * equals to `1.0` (or `0.0` if there are no categories with {@link Fuzzy} value greater than * {@link Fuzzy.FUZZY_FALSE}). */ normalize(): Logic; /** * Checks that at least one of the categories has non-zero {@link Fuzzy} value. */ isValid(): boolean; /** * Fuzzy Common Sense Logical NOT. See [README](../index.html#fuzzy-common-sense-logic) for details. */ not(): Logic; /** * Fuzzy Common Sense Logical AND. See [README](../index.html#fuzzy-common-sense-logic) for details. */ and(value: Logic): Logic; /** * Fuzzy Common Sense Logical OR. See [README](../index.html#fuzzy-common-sense-logic) for details. */ or(value: Logic): Logic; /** * Adds `value` to current value (category by category). * Useful for accumulation of fuzzy sums (usually with normalization in the end). * Mutates the current object. * @return Mutated `this` object. */ add(value: Logic): Logic; protected multiply(value: number): Logic; /** * Returns `true` if `category` is the dominating category of this object. */ eq(category: Category): boolean; /** * Returns `true` if `category` is **not** the dominating category of this object. */ ne(category: Category): boolean; } /** * Fuzzy Common Sense NOT (global function). * Allows to use different code styles, e.g.: * ```JavaScript * const valueA = value.not(); * const valueB = not(value); * ``` * See [README](../index.html#fuzzy-common-sense-logic) for details. */ export declare function not(value: Logic): Logic; /** * Fuzzy Common Sense AND (global function). * Allows to use different code styles, e.g.: * ```JavaScript * const valueA = value1.and(value2); * const valueB = and(value1, value2); * ``` * See [README](../index.html#fuzzy-common-sense-logic) for details. */ export declare function and(a: Logic, b: Logic): Logic; /** * Fuzzy Common Sense OR (global function). * Allows to use different code styles, e.g.: * ```JavaScript * const valueA = value1.or(value2); * const valueB = or(value1, value2); * ``` * See [README](../index.html#fuzzy-common-sense-logic) for details. */ export declare function or(a: Logic, b: Logic): Logic; /** * Fuzzy Common Sense logical value normalization (global function). * Allows to use different code styles, e.g.: * ```JavaScript * const valueA = value.normalize(); * const valueB = normalize(value); * ``` * See {@link Logic.normalize} for details. */ export declare function normalize(value: Logic): Logic;