<s> from . logic import LogicAdapter <EOL> from chatterbot . conversation import Statement <EOL> from chatterbot . utils . pos_tagger import POSTagger <EOL> import re <EOL> import forecastio <EOL> class WeatherLogicAdapter ( LogicAdapter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( WeatherLogicAdapter , self ) . __init__ ( ** kwargs ) <EOL> self . tagger = POSTagger ( ) <EOL> self . forecastio_api_key = kwargs . get ( "<STR_LIT>" ) <EOL> def process ( self , statement ) : <EOL> """<STR_LIT>""" <EOL> user_input = statement . text . lower ( ) <EOL> if "<STR_LIT>" not in user_input : <EOL> return <NUM_LIT:0> , Statement ( "<STR_LIT>" ) <EOL> latitude = self . get_latitude ( user_input ) <EOL> longitude = self . get_longitude ( user_input ) <EOL> if latitude is not "<STR_LIT>" and longitude is not "<STR_LIT>" : <EOL> return <NUM_LIT:1> , Statement ( "<STR_LIT>" + self . get_weather ( latitude , longitude ) ) <EOL> return <NUM_LIT:0> , Statement ( "<STR_LIT>" ) <EOL> def get_latitude ( self , user_input ) : <EOL> """<STR_LIT>""" <EOL> for token in self . tagger . tokenize ( user_input ) : <EOL> if "<STR_LIT>" in token : <EOL> return re . sub ( "<STR_LIT>" , "<STR_LIT>" , token ) <EOL> return "<STR_LIT>" <EOL> def get_longitude ( self , user_input ) : <EOL> """<STR_LIT>""" <EOL> for token in self . tagger . tokenize ( user_input ) : <EOL> if "<STR_LIT>" in token : <EOL> return re . sub ( "<STR_LIT>" , "<STR_LIT>" , token ) <EOL> return "<STR_LIT>" <EOL> def get_weather ( self , latitude , longitude ) : <EOL> """<STR_LIT>""" <EOL> forecast = forecastio . load_forecast ( self . forecastio_api_key , latitude , longitude ) <EOL> return forecast . hourly ( ) . summary </s>
