Class NLPProgram

All Implemented Interfaces:
Serializable, Cloneable, Iterable<NLPRule>, Collection<NLPRule>, Set<NLPRule>, BeliefBase, LogicProgram<FolFormula,FolFormula,NLPRule>

public class NLPProgram extends RuleSet<NLPRule> implements LogicProgram<FolFormula,FolFormula,NLPRule>
Represents a nested logic program (NLP) in the form of a set of rules.

The `NLPProgram` class extends `RuleSet` with rules of type `NLPRule` and implements the `LogicProgram` interface for first-order logic (FOL) formulas. It provides methods to manage facts, retrieve the minimal signature, and perform substitutions and exchanges on terms within the program.

Author:
Tim Janus
See Also:
  • Constructor Details

    • NLPProgram

      public NLPProgram()
  • Method Details

    • getFacts

      public Set<FolFormula> getFacts()
      Retrieves a set of facts from the nested logic program.

      This method iterates through all the rules in the program and collects those that are identified as facts. A fact is a rule with an empty premise, and its conclusion is considered a fact in first-order logic.

      Returns:
      a `Set` of `FolFormula` objects representing the facts in the program.
    • addFact

      public void addFact(FolFormula fact)
      Adds a fact to the nested logic program.

      This method creates a new `NLPRule` with the given fact.

      Specified by:
      addFact in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Parameters:
      fact - a `FolFormula` representing the fact to be added to the program.
    • addFacts

      public void addFacts(FolFormula... facts)
      Adds multiple facts to the nested logic program.

      This method accepts multiple facts as an array of `FolFormula` objects and adds each one to the program by calling the `addFact` method for each fact.

      Specified by:
      addFacts in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Parameters:
      facts - an array of `FolFormula` objects representing the facts to be added.
    • getMinimalSignature

      public FolSignature getMinimalSignature()
      Retrieves the minimal signature of the nested logic program.
      Specified by:
      getMinimalSignature in interface BeliefBase
      Specified by:
      getMinimalSignature in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Returns:
      a `FolSignature` object representing the minimal signature of the program.
    • substitute

      public NLPProgram substitute(Term<?> t, Term<?> v)
      Substitutes a term in all rules of the nested logic program.

      This method creates a new `NLPProgram` in which all occurrences of a specific term (`t`) in the program are replaced with another term (`v`). Each rule in the program is processed, and a substituted version of the rule is added to the new program.

      Specified by:
      substitute in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Parameters:
      t - the term to be replaced.
      v - the term to replace with.
      Returns:
      a new `NLPProgram` with the substitution applied.
    • substitute

      public NLPProgram substitute(Map<? extends Term<?>,? extends Term<?>> map) throws IllegalArgumentException
      Substitutes multiple terms in all rules of the nested logic program according to the provided map.
      Specified by:
      substitute in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Parameters:
      map - a map where the keys are the terms to be replaced and the values are the replacement terms.
      Returns:
      a new `NLPProgram` with the substitutions applied.
      Throws:
      IllegalArgumentException - if an invalid substitution is encountered.
    • exchange

      public NLPProgram exchange(Term<?> v, Term<?> t) throws IllegalArgumentException
      Exchanges two terms in all rules of the nested logic program.

      This method creates a new `NLPProgram` in which two terms (`v` and `t`) are exchanged in all rules of the program.

      Specified by:
      exchange in interface LogicProgram<FolFormula,FolFormula,NLPRule>
      Parameters:
      v - the first term involved in the exchange.
      t - the second term involved in the exchange.
      Returns:
      a new `NLPProgram` with the terms exchanged.
      Throws:
      IllegalArgumentException - if an invalid exchange is attempted.