Formula Parser¶
This module provides a parser for Logical Neural Networks (LNN) formulas. It utilizes the Lark library to transform logical expressions into a parse tree, supporting standard logic gates, temporal operators, and weighted expressions.
- class jlnn.symbolic.parser.FormulaParser[source]¶
Bases:
objectA wrapper class for the Lark LALR parser configured with LNN grammar.
This parser handles operator precedence and associativity for logical operators, including support for weighted implications and temporal logic operators like Always (G), Eventually (F), and Next (X).
- parse(formula: str)[source]¶
Parses a string representation of a logical formula into a Lark Tree.
- Parameters:
formula (str) – The logical expression to be parsed (e.g., “A & B -> C”).
- Returns:
A parse tree representing the hierarchical structure of the formula.
- Return type:
lark.Tree
- Raises:
ValueError – If the input formula does not conform to the LNN grammar rules.
This module uses the Lark library to transform string definitions of rules into syntactic trees (CST).
LNN Grammar¶
Supports complex logical expressions including:
* The weight of facts: 0.8::A (setting prior truth value).
* Weighted rules: A & B ->[0.9] C (setting the weight of implication).
* Temporal operators: G (Always), F (Eventually), X (Next).