def __init__(self): self.parser = gen_parser() self.function_registry = FunctionRegistry() self.unnamed_operator_counter = 0 self.twitter_td = twitter_tuple_descriptor()
from tweeql.field_descriptor import ReturnType from tweeql.function_registry import FunctionInformation, FunctionRegistry from tweeql.query_runner import QueryRunner class Url(): return_type = ReturnType.STRING @staticmethod def factory(): return Url().get_url def get_url(self, tuple_data, val): tuple_data['screen_name'] = tuple_data['author'].screen_name return 'http://twitter.com/%(screen_name)s/status/%(id)s' % tuple_data fr = FunctionRegistry() fr.register("url", FunctionInformation(Url.factory, Url.return_type)) class Entities(): return_type = ReturnType.STRING @staticmethod def factory(): return Entities().get_entities def get_entities(self, tuple_data, val): values = tuple_data['entities'] value = values[val] if val == 'hashtags': return ','.join(list(set([v['text'].lower() for v in value]))) elif val == 'user_mentions':
def register_default_functions(): fr = FunctionRegistry() fr.register("temperatureF", FunctionInformation(Temperature.factory, Temperature.return_type)) fr.register("tweetLatLng", FunctionInformation(Location.factory, Location.return_type)) fr.register("floor", FunctionInformation(Rounding.factory, Rounding.return_type)) fr.register("strlen", FunctionInformation(StringLength.factory, StringLength.return_type)) fr.register("meanDevs", FunctionInformation(MeanOutliers.factory, MeanOutliers.return_type)) fr.register("sentiment", FunctionInformation(Sentiment.factory, Sentiment.return_type))
from tweeql.exceptions import TweeQLException from tweeql.field_descriptor import ReturnType from tweeql.function_registry import FunctionInformation, FunctionRegistry from tweeql.query_runner import QueryRunner class StringLength(): return_type = ReturnType.INTEGER @staticmethod def factory(): return StringLength().strlen def strlen(self, tuple_data, val): """ Returns the length of val, which is a string """ return len(val) fr = FunctionRegistry() fr.register( "stringlength", FunctionInformation(StringLength.factory, StringLength.return_type)) runner = QueryRunner() runner.run_query("SELECT stringlength(text) AS len FROM twitter_sample;", False)
from tweeql.exceptions import TweeQLException from tweeql.field_descriptor import ReturnType from tweeql.function_registry import FunctionInformation, FunctionRegistry from tweeql.query_runner import QueryRunner class StringLength(): return_type = ReturnType.INTEGER @staticmethod def factory(): return StringLength().strlen def strlen(self, tuple_data, val): """ Returns the length of val, which is a string """ return len(val) fr = FunctionRegistry() fr.register("stringlength", FunctionInformation(StringLength.factory, StringLength.return_type)) runner = QueryRunner() runner.run_query("SELECT stringlength(text) AS len FROM twitter_sample;", False)