<s> """<STR_LIT>""" <EOL> from nltk . sem . logic import * <EOL> def compute_type_raised_semantics ( semantics ) : <EOL> core = semantics <EOL> parent = None <EOL> while isinstance ( core , LambdaExpression ) : <EOL> parent = core <EOL> core = core . term <EOL> var = Variable ( "<STR_LIT:F>" ) <EOL> while var in core . free ( ) : <EOL> var = unique_variable ( pattern = var ) <EOL> core = ApplicationExpression ( FunctionVariableExpression ( var ) , core ) <EOL> if parent is not None : <EOL> parent . term = core <EOL> else : <EOL> semantics = core <EOL> return LambdaExpression ( var , semantics ) <EOL> def compute_function_semantics ( function , argument ) : <EOL> return ApplicationExpression ( function , argument ) . simplify ( ) <EOL> def compute_composition_semantics ( function , argument ) : <EOL> assert isinstance ( argument , LambdaExpression ) , "<STR_LIT>" + str ( argument ) + "<STR_LIT>" <EOL> return LambdaExpression ( argument . variable , ApplicationExpression ( function , argument . term ) . simplify ( ) ) <EOL> def compute_substitution_semantics ( function , argument ) : <EOL> assert isinstance ( function , LambdaExpression ) and isinstance ( function . term , LambdaExpression ) , "<STR_LIT>" + str ( function ) + "<STR_LIT>" <EOL> assert isinstance ( argument , LambdaExpression ) , "<STR_LIT>" + str ( argument ) + "<STR_LIT>" <EOL> new_argument = ApplicationExpression ( argument , VariableExpression ( function . variable ) ) . simplify ( ) <EOL> new_term = ApplicationExpression ( function . term , new_argument ) . simplify ( ) <EOL> return LambdaExpression ( function . variable , new_term ) </s>
