Esempio n. 1
0
def whom(state, now, when) :
	whom = list()
	for who in state :
		if 'e' not in state[who] or 's' not in state[who] :
			continue

		if when <= state[who]['e'] and state[who]['s'] <= when :
			whom.append(who)
	whom.sort()
	plural = len(whom) > 1

	if len(whom) > 2 :
		whom = ', '.join(whom[:-1]) + ', and ' + whom[-1]
	elif len(whom) == 2 :
		whom = '%s and %s' % (whom[0], whom[1])
	elif len(whom) == 0 :
		whom = 'nobody'
	else :
		whom = whom[0]

	if now == when :
		temporal = 'now'
		if plural :
			verbal = 'are'
		else :
			verbal = 'is'
	else :
		temporal = 'in %s' % datediff.differ(when - now)
		verbal = 'will be'

	return '%s %s here %s.' % (whom, verbal, temporal)
Esempio n. 2
0
 def emit_events_english(tskeys, ev):
     already_mentioned = set()
     for ts in tskeys:
         for e in ev[ts]:
             person, event = e
             if person not in already_mentioned:
                 already_mentioned.add(person)
                 yield phrases[tense(ts)][event] % (person, datediff.differ(abs(ts - now)))
Esempio n. 3
0
def whom(state, now, when, nv=None):
    # determine present macs if possible to find & also relevant
    present_macs = None
    if (now == when) and (nv is not None) and nv.synced:
        present_macs = set([n[0] for n in nv.net])

    whomset = set()
    for who in state:
        period_set = ('e' in state[who] and 's' in state[who])
        mac_set = 'macs' in state[who]

        if period_set:
            if when <= state[who]['e'] and state[who]['s'] <= when:
                whomset.add(who)

        # if mac presence is relevant, and this person has a mac set... check it
        if mac_set and present_macs:
            ms = set(state[who]['macs'])
            if ms.intersection(present_macs):
                whomset.add(who)

    whom = list(whomset)
    whom.sort()
    plural = len(whom) > 1

    if len(whom) > 2:
        whom = ', '.join(whom[:-1]) + ', and ' + whom[-1]
    elif len(whom) == 2:
        whom = '%s and %s' % (whom[0], whom[1])
    elif len(whom) == 0:
        whom = 'nobody'
    else:
        whom = whom[0]

    if now == when:
        temporal = 'now'
        if plural:
            verbal = 'are'
        else:
            verbal = 'is'
    else:
        temporal = 'in %s' % datediff.differ(when - now)
        verbal = 'will be'

    return '%s %s here %s.' % (whom, verbal, temporal)