def test_estimated_country_original(): failed = [] for code, latitude, longitude in country.COUNTRIES: result = country.estimated_country(float(latitude), float(longitude)) if result != code: failed.append(code) assert not failed
def _process_twitter(self, twitter_results): """Classify each tweet returned by Twitter.""" results = [] if self.geo: country_geo = collections.defaultdict(list) for tweet in twitter_results: result = self.process_query(normalize_text(tweet.text)) result = (tweet, ) + result[1:] results.append(result) if self.geo: label, probability = result[2], result[3] location = tweet.geo['coordinates'] country = estimated_country(*location) if label == 'negative': probability = 1 - probability elif label == 'neutral': continue country_geo[country].append(probability) if self.sort: order = self.sort != 'ascending' # Default descending. results.sort(key=operator.itemgetter(3), reverse=order) if self.geo: self.geo = country_geo self._on_results(results)
def test_estimated_country_samples(): assert 'US' == country.estimated_country(38.058576, -97.3472717) assert 'NL' == country.estimated_country(51.658927, 5.611267)