<s> '''<STR_LIT>''' <EOL> from collections import defaultdict <EOL> from hedwig . core import UnaryPredicate , Rule , Example <EOL> from hedwig . core . settings import logger <EOL> from hedwig . stats . significance import is_redundant <EOL> from hedwig . stats . scorefunctions import interesting <EOL> class BottomUpLearner : <EOL> '''<STR_LIT>''' <EOL> Similarity = '<STR_LIT>' <EOL> Improvement = '<STR_LIT>' <EOL> Default = '<STR_LIT:default>' <EOL> def __init__ ( self , kb , n = None , min_sup = <NUM_LIT:1> , sim = <NUM_LIT:1> , depth = <NUM_LIT:4> , target = None , <EOL> use_negations = False ) : <EOL> self . kb = kb <EOL> self . n = n <EOL> self . min_sup = min_sup <EOL> self . sim = sim <EOL> self . extending = Learner . Improvement <EOL> self . depth = depth <EOL> self . use_negations = use_negations <EOL> if kb . is_discrete_target ( ) : <EOL> self . target = list ( self . kb . class_values ) [ <NUM_LIT:0> ] if not target else target <EOL> else : <EOL> self . target = None <EOL> self . pruned_subclasses = self . _pruned_subclasses ( ) <EOL> self . pruned_superclasses_closure = self . _pruned_superclasses ( ) <EOL> self . implicit_roots = self . _implicit_roots ( ) <EOL> def _pruned_subclasses ( self ) : <EOL> min_sup = lambda pred : self . kb . n_members ( pred ) >= self . min_sup <EOL> pruned_subclasses = { } <EOL> for pred in self . kb . predicates : <EOL> subclasses = self . kb . get_subclasses ( pred ) <EOL> pruned_subclasses [ pred ] = filter ( min_sup , subclasses ) <EOL> return pruned_subclasses <EOL> def _pruned_superclasses ( self ) : <EOL> min_sup = lambda pred : self . kb . n_members ( pred ) >= self . min_sup <EOL> pruned_superclasses = { } <EOL> for pred in self . kb . predicates : <EOL> superclasses = self . kb . super_classes ( pred ) <EOL> pruned_superclasses [ pred ] = filter ( min_sup , superclasses ) <EOL> return pruned_superclasses <EOL> def _implicit_roots ( self ) : <EOL> implicit_roots = set ( ) <EOL> n_examples = self . kb . n_examples ( ) <EOL> for pred in self . kb . predicates : <EOL> if self . kb . n_members ( pred ) == n_examples : <EOL> implicit_roots . add ( pred ) <EOL> return implicit_roots <EOL> def get_subclasses ( self , pred ) : <EOL> return self . pruned_subclasses [ pred . label ] <EOL> def get_superclasses ( self , pred ) : <EOL> return self . pruned_superclasses_closure [ pred ] <EOL> def is_implicit_root ( self , pred ) : <EOL> return pred in self . implicit_roots <EOL> def induce ( self ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def bottom_clause ( self ) : <EOL> pass </s>
