def identify_question(question): st = RSLPStemmer() wrds = [] for token in question.lower().split(): wrds.append(st.stem(token)) types = { 'time': ['quant', 'temp', 'dem', 'esper', 'long', 'pert', 'lev'], 'location' : ['cad', 'ond', 'est', 'aven' 'rua'] } best_result = None last_test = 0 for key, value in types.iteritems(): filtered = filter(set(value).__contains__, wrds) if len(filtered) > last_test: last_test = len(filtered) best_result = key return best_result
def setup(self, channel, direction, pull_up_down=_GPIO.PUD_OFF, initial=None): """ Set up a GPIO channel or list of channels with a direction and (optional) pull/up down control. Note that if channel is a list, all of direction, pull_up_down and initial must be lists (or tuples) **of the same length**. Failure to meet this requirement will throw an exception and this class will not be usable for your entire session! This can possibly cause some confusing errors later if you trap and ignore the exception from this method (setup). :param channel: Either board pin number or BCM number depending on which mode is set. Can be either an int, tuple or list of ints. Note that if this param is a list or tuple type, then all of direction, pull_up_down and initial may also be list or tuple types! This means you can quite effectively initialize ALL your GPIO I/O in ONE setup() call (i.e., this function, NOT the RPi.GPIO!) This class handles it all for you. :type channel: Int, Tuple or List :param direction: IN or OUT :type direction: Int, Tuple or List :param pull_up_down: PUD_OFF (default), PUD_UP or PUD_DOWN :type pull_up_down: Int, Tuple or List :param initial: Initial value(s) for an output channel :type initial: Int, Tuple or List """ logging.debug( 'gpio.setup(channel={0}, direction={1}, pull_up_down={2}, initial={3})' .format(channel, direction, pull_up_down, initial)) if type(channel) in [types.ListType, types.TupleType]: for n in range(0, len(channel)): ch = channel[n] d = None d = direction if type(direction) in (types.TupleType, types.ListType): d = direction[n] pud = pull_up_down if type(pull_up_down) in (types.TupleType, types.ListType): pud = pull_up_down[n] init = initial if type(initial) in (types.TupleType, types.ListType): init = initial[n] self._setup(ch, d, pud, init) else: if type(channel) in [types.DictionaryType, types.DictType]: # Assume we have values for gpiox as key=extended port, val = [gpioport, <_GPIO.IN or _GPIO.OUT>] for key, val in types.iteritems(): if isinstance(val, gpiox): self.ports[key] = val else: if isinstance(val, types.ListType): x = gpiox(key, val[0], val[1], val[3]) self.ports[key] = x self._setup(x.gpio, x.mode, x.pud) else: self._setup(channel, direction, pull_up_down, initial)
def setup(self, channel, direction, pull_up_down=_GPIO.PUD_OFF, initial=None): """ Set up a GPIO channel or list of channels with a direction and (optional) pull/up down control. Note that if channel is a list, all of direction, pull_up_down and initial must be lists (or tuples) **of the same length**. Failure to meet this requirement will throw an exception and this class will not be usable for your entire session! This can possibly cause some confusing errors later if you trap and ignore the exception from this method (setup). :param channel: Either board pin number or BCM number depending on which mode is set. Can be either an int, tuple or list of ints. Note that if this param is a list or tuple type, then all of direction, pull_up_down and initial may also be list or tuple types! This means you can quite effectively initialize ALL your GPIO I/O in ONE setup() call (i.e., this function, NOT the RPi.GPIO!) This class handles it all for you. :type channel: Int, Tuple or List :param direction: IN or OUT :type direction: Int, Tuple or List :param pull_up_down: PUD_OFF (default), PUD_UP or PUD_DOWN :type pull_up_down: Int, Tuple or List :param initial: Initial value(s) for an output channel :type initial: Int, Tuple or List """ logging.debug('gpio.setup(channel={0}, direction={1}, pull_up_down={2}, initial={3})'. format(channel, direction, pull_up_down, initial)) if type(channel) in [types.ListType, types.TupleType]: for n in range(0, len(channel)): ch = channel[n] d = None d = direction if type(direction) in (types.TupleType, types.ListType): d = direction[n] pud = pull_up_down if type(pull_up_down) in (types.TupleType, types.ListType): pud = pull_up_down[n] init = initial if type(initial) in (types.TupleType, types.ListType): init = initial[n] self._setup(ch, d, pud, init) else: if type(channel) in [types.DictionaryType, types.DictType]: # Assume we have values for gpiox as key=extended port, val = [gpioport, <_GPIO.IN or _GPIO.OUT>] for key, val in types.iteritems(): if isinstance(val, gpiox): self.ports[key] = val else: if isinstance(val, types.ListType): x = gpiox(key, val[0], val[1], val[3]) self.ports[key] = x self._setup(x.gpio, x.mode, x.pud) else: self._setup(channel, direction, pull_up_down, initial)
'wraps all (Types)attrs into valuedefs' def __init__( me, types): me.__types = types def __getattr__( me, k): t = getattr( me.__types, k) return Types.valuedef( t, typename= k) if 0: #XXX this gymnastics if _types is not a module but a func #def _types(): # ... # return locals().copy() class Types: pass _functype = type( _types) _types = _types() Types.__dict__.update( (k, isinstance(v,_functype) and staticmethod(v) or v) for k,v in _types.iteritems() ) del _types def optional( type, default_value =None): v = Types.valuedef.convert( type) return v.optional( default_value) class Method( object): _returns = None #_inputs = None name = None _doc = '' def __init__( me, **ka): me._inputs = me._convert_dict( ka) or {} #None me._features = []