- java.lang.Object
-
- org.logicng.util.FormulaHelper
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SortedSet<Literal>literals(Collection<? extends Formula> formulas)Returns all literals occurring in the given formulas.static SortedSet<Literal>literals(Formula... formulas)Returns all literals occurring in the given formulas.static SortedSet<String>literals2strings(Collection<Literal> literals, String negationPrefix)Returns a list of strings from a given collection of literals.static Variable[]literalsAsVariables(Literal[] literals)Converts a literal array to a variable array.static <C extends Collection<Formula>>
Cnegate(Collection<? extends Formula> formulas, Supplier<C> collectionFactory)Returns the negation of the given formulas.static <C extends Collection<Literal>>
CnegateLiterals(Collection<? extends Literal> literals, Supplier<C> collectionFactory)Returns the negation of the given literalsstatic List<Formula>splitTopLevelAnd(Formula formula)Splits the top levelAndif possible.static SortedSet<Literal>strings2literals(Collection<String> strings, String negationPrefix, FormulaFactory f)Returns a sorted literal set from a given collection of strings and a formula factory.static SortedSet<Variable>strings2vars(Collection<String> strings, FormulaFactory f)Returns a sorted variable set from a given collection of strings which will be used as variable names and a formula factory.static SortedSet<Variable>variables(Collection<? extends Formula> formulas)Returns all variables occurring in the given formulas.static SortedSet<Variable>variables(Formula... formulas)Returns all variables occurring in the given formulas.static SortedSet<String>vars2strings(Collection<Variable> variables)Returns a list of strings from a given collection of variables.
-
-
-
Method Detail
-
variables
public static SortedSet<Variable> variables(Formula... formulas)
Returns all variables occurring in the given formulas.- Parameters:
formulas- formulas- Returns:
- all variables occurring in the given formulas
-
variables
public static SortedSet<Variable> variables(Collection<? extends Formula> formulas)
Returns all variables occurring in the given formulas.- Parameters:
formulas- formulas- Returns:
- all variables occurring in the given formulas
-
literals
public static SortedSet<Literal> literals(Formula... formulas)
Returns all literals occurring in the given formulas.- Parameters:
formulas- formulas- Returns:
- all literals occurring in the given formulas
-
literals
public static SortedSet<Literal> literals(Collection<? extends Formula> formulas)
Returns all literals occurring in the given formulas.- Parameters:
formulas- formulas- Returns:
- all literals occurring in the given formulas
-
negateLiterals
public static <C extends Collection<Literal>> C negateLiterals(Collection<? extends Literal> literals, Supplier<C> collectionFactory)
Returns the negation of the given literals- Type Parameters:
C- the type parameters of the collection- Parameters:
literals- the literalscollectionFactory- the supplier for the collection- Returns:
- the negated literals
-
negate
public static <C extends Collection<Formula>> C negate(Collection<? extends Formula> formulas, Supplier<C> collectionFactory)
Returns the negation of the given formulas.- Type Parameters:
C- the type parameters of the collection- Parameters:
formulas- the formulascollectionFactory- the supplier for the collection- Returns:
- the negated literals
-
literalsAsVariables
public static Variable[] literalsAsVariables(Literal[] literals)
Converts a literal array to a variable array.- Parameters:
literals- the literals- Returns:
- the variables
-
splitTopLevelAnd
public static List<Formula> splitTopLevelAnd(Formula formula)
Splits the top levelAndif possible.- Parameters:
formula- the formula- Returns:
- list of the operands if the formula is a
And, otherwise the formula itself
-
strings2vars
public static SortedSet<Variable> strings2vars(Collection<String> strings, FormulaFactory f)
Returns a sorted variable set from a given collection of strings which will be used as variable names and a formula factory. The given collection is treated in a null-safe manner, i.e. if the collection isnullthe collection is considered to be an empty collection.- Parameters:
strings- the collection of strings (can be empty ornullf- the formula factory which is used to generate the variables- Returns:
- the sorted set of variables from the collection of variable names
-
strings2literals
public static SortedSet<Literal> strings2literals(Collection<String> strings, String negationPrefix, FormulaFactory f)
Returns a sorted literal set from a given collection of strings and a formula factory. If a string begins with the givennegationPrefixa literal with a negative phase is created, otherwise a literal with a positive phase is created. The given collection is treated in a null-safe manner, i.e. if the collection isnullthe collection is considered to be an empty collection.- Parameters:
strings- the collection of strings (can be empty ornullnegationPrefix- the negation prefixf- the formula factory which is used to generate the variables- Returns:
- the sorted set of literals
-
vars2strings
public static SortedSet<String> vars2strings(Collection<Variable> variables)
Returns a list of strings from a given collection of variables. The strings contain the variable names. The given collection is treated in a null-safe manner, i.e. if the collection isnullthe collection is considered to be an empty collection.- Parameters:
variables- the collection of variables (can be empty ornull- Returns:
- the list of variable names
-
literals2strings
public static SortedSet<String> literals2strings(Collection<Literal> literals, String negationPrefix)
Returns a list of strings from a given collection of literals. The strings contain the variable names with a leadingnegationPrefixif the literal has a negative phase. The given collection is treated in a null-safe manner, i.e. if the collection isnullthe collection is considered to be an empty collection.- Parameters:
literals- the collection of variables (can be empty ornullnegationPrefix- the negation prefix- Returns:
- the list of literal names with a leading
negationPrefixif the phase is negative
-
-