Class TermPartition

java.lang.Object
fr.inria.rules.integraal.model.partition.Partition<Term>
fr.inria.rules.integraal.model.partition.TermPartition
All Implemented Interfaces:
Substitutable<TermPartition>

public class TermPartition extends Partition<Term> implements Substitutable<TermPartition>
Partition specialized for terms, with utilities tied to substitutions and rule validity.
Author:
Guillaume Pérution-Kihli, Florent Tornil
  • Constructor Details

    • TermPartition

      public TermPartition()
      Creates a new empty TermPartition
    • TermPartition

      public TermPartition(Set<Term> initialElements)
      Creates a new TermPartition with the given elements, each in its own class
      Parameters:
      initialElements - the initial elements of this partition
    • TermPartition

      public TermPartition(Collection<Set<Term>> partition)
      Creates a new TermPartition with the given classes
      Parameters:
      partition - the initial elements represented as multiple partitions
    • TermPartition

      public TermPartition(Substitution substitution)
      Creates the TermPartition induced by a substitution I.e., foreach variable v mapped to a term t through the substitution, v and t are in the same class, and the partition is the finest for this property
      Parameters:
      substitution - the substitution to transform into a partition
    • TermPartition

      public TermPartition(Partition<Term> toCopy)
      Creates a new TermPartition, copying the given one
      Parameters:
      toCopy - partition to copy
  • Method Details

    • isValid

      public boolean isValid(Rule rule)
      Checks whether this partition is valid for the supplied rule.
      Parameters:
      rule - a rule
      Returns:
      false iff a class of the receiving partition contains two constants, or contains two existential variable of R, or contains a constant and an existential variable of R, or contains an existential variable of R and a frontier variable of R
    • isValid

      public boolean isValid(Rule rule, FOQuery<?> context)
      Takes into account answer variables of a context query, preventing them to be associated with an existential variable of the rule
      Parameters:
      rule - a rule
      context - the query in which to test the validity
      Returns:
      false iff a class of the receiving partition contains two constants, or contains two existential variable of R, or contains a constant and an existential variable of R, or contains an existential variable of R and a frontier variable of R, or an existential and an answer variable of the context
    • getSeparatingStickyVariables

      public Set<Variable> getSeparatingStickyVariables(Set<Variable> sep, Rule rule)
      Returns the separating sticky variables induced by this partition.
      Parameters:
      sep - the set of separating variables
      rule - a rule
      Returns:
      the subset of sep containing variables that are in the same class as an existential variable of rule.
    • existsSeparatingStickyVariables

      public boolean existsSeparatingStickyVariables(Set<Variable> sep, Rule rule)
      Checks whether this partition contains a separating sticky variable.
      Parameters:
      sep - the set of separating variables
      rule - a rule
      Returns:
      a boolean that is true iff there exists at least one separating sticky variable.
    • getAssociatedSubstitution

      public Optional<Substitution> getAssociatedSubstitution(FOQuery<?> context)
      Compute the substitution associated with this partition. This method computes a substitution by choosing one representative term by class. The representative is chosen for each class as : 1. The constant (if any) 2. The answer variable of the context (if any) 3. The variables of the context (if any) 4. A random term of the class
      Return an empty optional if the partition contain two constants in the same class
      Parameters:
      context - a query for context (answer variables)
      Returns:
      the substitution associated with this partition in the given context
    • createImageWith

      public TermPartition createImageWith(Substitution s)
      Applies a substitution to every class of this partition.
      Parameters:
      s - a substitution
      Returns:
      a new partition that represents this partition on which the given substitution have been applied
    • getSubstitution

      public Optional<Substitution> getSubstitution()
      Get a substitution from variables of a class to their representative, if the term partition does not contain multiple constants in the same class
      Returns:
      an optional containing a substitution that represents the partition
    • eraseMemoizedValues

      protected void eraseMemoizedValues()
      Description copied from class: Partition
      Erase the memoized values
      Overrides:
      eraseMemoizedValues in class Partition<Term>
    • getTermPartitionRestrictedToVariables

      public TermPartition getTermPartitionRestrictedToVariables(Set<Variable> variables)
      Get a new term partition that contains all terms of this partition except the variables that are not from the set of variables in parameter. If there are compound terms, they will be in the partition only if their nested variables are in the set.
      Parameters:
      variables - the variables to keep in the restricted partition
      Returns:
      a new term partition that contains all terms except the variable not in the set
    • applySubstitution

      public TermPartition applySubstitution(Substitution substitution, boolean evaluate)
      Description copied from interface: Substitutable
      Applies the given substitution to this object.
      Specified by:
      applySubstitution in interface Substitutable<TermPartition>
      Parameters:
      substitution - the substitution to apply
      evaluate - whether evaluable subterms should be forced
      Returns:
      a new instance with the substitution applied