src.fol package
Submodules
src.fol.data_utils module
- class src.fol.data_utils.DataUtils(lark_path, lang_base_path, dataset_type='kandinsky', dataset='twopairs')[source]
Bases:
object
Utilities about logic.
A class of utilities about first-order logic.
- Parameters
dataset_type (str) – A dataset type (kandinsky or clevr).
dataset (str) – A dataset to be used.
- Attrs:
base_path: The base path of the dataset.
src.fol.exp_parser module
src.fol.language module
- class src.fol.language.DataType(name)[source]
Bases:
object
Data type in first-order logic.
A class of data types in first-order logic.
- Parameters
name (str) – The name of the data type.
- Attrs:
name (str): The name of the data type.
- class src.fol.language.Language(preds, funcs, consts)[source]
Bases:
object
Language of first-order logic.
A class of languages in first-order logic.
- Parameters
- Attrs:
preds (List[Predicate]): A set of predicate symbols. funcs (List[FunctionSymbol]): A set of function symbols. consts (List[Const]): A set of constants.
- get_by_dtype(dtype)[source]
Get constants that match given dtypes.
- Parameters
dtype (DataType) – The data type.
- Returns
List of constants whose data type is the given data type.
- get_by_dtype_name(dtype_name)[source]
Get constants that match given dtype name.
- Parameters
dtype_name (str) – The name of the data type to be used.
- Returns
List of constants whose datatype has the given name.
- get_const_by_name(const_name)[source]
Get the constant by its name.
- Parameters
const_name (str) – The name of the constant.
- Returns
The matched constant with the given name.
- Return type
- get_pred_by_name(pred_name)[source]
Get the predicate by its name.
- Parameters
pred_name (str) – The name of the predicate.
- Returns
The matched preicate with the given name.
- Return type
src.fol.logic module
- class src.fol.logic.Atom(pred, terms)[source]
Bases:
object
Atoms in first-oder logic.
A class of atoms: p(t1, …, tn)
- class src.fol.logic.Clause(head, body)[source]
Bases:
object
Clauses in first-oder logic.
A class of clauses in first-order logic: A :- B1, …, Bn.
- class src.fol.logic.Const(name, dtype=None)[source]
Bases:
Term
Constants in first-order logic.
A class of constants in first-oder logic.
- name
Name of the term.
- Type
str
- dtype
Data type of the term.
- Type
datatype
- class src.fol.logic.FuncSymbol(name, arity)[source]
Bases:
object
Function symbols in first-order logic.
A class of function symbols in first-oder logic.
- name
Name of the function.
- Type
str
- class src.fol.logic.FuncTerm(func_symbol, args)[source]
Bases:
Term
Term with a function symbol f(t_1, …, t_n)
A class of terms that cosist of a function symbol in first-oder logic.
- func_symbol
A function symbolc in the term.
- Type
- class src.fol.logic.NeuralPredicate(name, arity, dtypes)[source]
Bases:
Predicate
Neural predicats.
A class of neural predicates, which are associated with a differentiable function.
- name
A name of the predicate.
- Type
str
- arity
The arity of the predicate.
- Type
int
- dtypes
The data types of the arguments for the predicate.
- Type
List[DataTypes]
- class src.fol.logic.Predicate(name, arity, dtypes)[source]
Bases:
object
Predicats in first-order logic.
A class of predicates in first-order logic.
- name
A name of the predicate.
- Type
str
- arity
The arity of the predicate.
- Type
int
- dtypes
The data types of the arguments for the predicate.
- Type
List[DataTypes]
- class src.fol.logic.Term[source]
Bases:
ABC
Terms in first-order logic.
An abstract class of terms in first-oder logic.
- name
Name of the term.
- Type
str
- dtype
Data type of the term.
- Type
datatype
src.fol.logic_ops module
- src.fol.logic_ops.find_subs_term(subs_var, disagree_set)[source]
Find term where the var does not occur
Inputs
subs_var : .logic.Var disagree_set : List[.logic.Term]
- returns
flag (bool)
term (.logic.Term)
- src.fol.logic_ops.get_disagree_index(terms)[source]
get the desagreement index in the unification algorithm details in [Foundations of Inductive Logic Programming. Nienhuys-Cheng, S.-H. et.al. 1997.]
Inputs
- termsList[Term]
Term : .logic.FuncTerm .logic.Const .logic.Var list of terms
- returns
disagree_flag (bool) – flag of disagreement
disagree_index (int) – index of the disagreement term in the args of predicates
- src.fol.logic_ops.get_disagreements(terms)[source]
get desagreements in the unification algorithm details in [Foundations of Inductive Logic Programming. Nienhuys-Cheng, S.-H. et.al. 1997.]
Inputs
- temrsList[Term]
Term : .logic.FuncTerm .logic.Const .logic.Var list of terms
- returns
disagree_flag (bool) – flag of disagreement
disagree_terms (List[Term]) – Term : .logic.FuncTerm .logic.Const .logic.Var terms of disagreement
- src.fol.logic_ops.is_entailed(e, clause, facts, n)[source]
decision function of ground atom is entailed by a clause and facts by n-step inference
Inputs
- e.logic.Atom
ground atom
- clause.logic.Clause
clause
- factsList[.logic.Atom]
set of facts
- nint
infer step
- returns
flag – ${clause} cup facts models e$
- rtype
bool
- src.fol.logic_ops.is_singleton(atoms)[source]
returns whether all the input atoms are the same or not
Inputs
- atoms: List[.logic.Atom]
[a_1, a_2, …, a_n]
- returns
flag – a_1 == a_2 == … == a_n
- rtype
bool
- src.fol.logic_ops.occur_check(variable, term)[source]
occur check function details in [Foundations of Inductive Logic Programming. Nienhuys-Cheng, S.-H. et.al. 1997.]
Inputs
variable : .logic.Var term : Term
Term : .logic.FuncTerm .logic.Const .logic.Var
- returns
occur_flag – flag ofthe occurance of the variable
- rtype
bool
- src.fol.logic_ops.subs(exp, target_var, const)[source]
Substitute var = const
Inputs
- exp.logic.CLause .logic.Atom .logic.FuncTerm .logic.Const .logic.Var
logical expression atom, clause, or term
- target_var.logic.Var
target variable of the substitution
- const.logic.Const
constant to be substituted
- returns
exp – result of the substitution logical expression atom, clause, or term
- rtype
.logic.CLause .logic.Atom .logic.FuncTerm .logic.Const .logic.Var
- src.fol.logic_ops.t_p(clause, facts)[source]
T_p operator limited to clauses with one body atom
Inputs
- clause.logic.Clause
clause
- factsList[.logic.Atom]
set of facts
- returns
S – set of ground atoms entailed by one step forward-chaining inference
- rtype
List[.logic.Atom]
- src.fol.logic_ops.t_p_n(clause, facts, n)[source]
applying the T_p operator n-times taking union of results
Inputs
- clause.logic.Clause
clause
- factsList[.logic.Atom]
set of facts
- nint
infer step
- returns
G – set of ground atoms entailed by ${clause} cup facts$
- rtype
Set[.logic.Atom]
- src.fol.logic_ops.unify(atoms)[source]
Unification of first-order logic expressions details in [Foundations of Inductive Logic Programming. Nienhuys-Cheng, S.-H. et.al. 1997.]
Inputs
atoms : List[.logic.Atom]
- returns
flag (bool) – unifiable or not
unifier (List[(.logic.Var, .logic.Const)]) – unifiable - unifier (list of substitutions) not unifiable - empty list