Exemplo n.º 1
0
Arquivo: st.py Projeto: gkchai/planus
 def update_users(self, users):
   # update ppl, free, busy from current database
   for user in users:
     if user['email'] not in self.all:
       p = person(user['email'], user['first_name'])
       self.all.add(user['email'])
       self.meta['new'].add(user['email'])
       self.update_metas_helper(p)
Exemplo n.º 2
0
Arquivo: st.py Projeto: gkchai/planus
 def update_users(self, users):
     # update ppl, free, busy from current database
     for user in users:
         if user['email'] not in self.all:
             p = person(user['email'], user['first_name'])
             self.all.add(user['email'])
             self.meta['new'].add(user['email'])
             self.update_metas_helper(p)
Exemplo n.º 3
0
Arquivo: st.py Projeto: gkchai/planus
  def update_state(self, d_act):
    info = {'d_act': d_act}
    if len(self.all)==0:
      # this is the first time program is being called, so set the organizer for this meeting
      self.org = d_act['from']['email']
      self.meta['busy'].add(self.org)
      self.meta['ppl'][self.org] = person(self.org, d_act['from']['first_name'], 'busy')

    self.retrieve_users()
    users = d_act['to']+[d_act['from']]
    self.update_users(users)

    if len(d_act['nlu']['outcomes'])>1:
      print 'More than 1 outcome! chk this case..'
      pdb.set_trace()

    #TODO: what happens when wit.ai's output is empty? handle the error cases
    for outcome in d_act['nlu']['outcomes']:
      # Ideally each location should also have an associated preference as should datetime
      if 'location' in outcome['entities']:
        for loc in outcome['entities']['location']:
          self.loc.append({'val': loc['value'], 'from': d_act['from']['email'], 'turn': len(self.turns)})

      if 'local_search_query' in outcome['entities']:
        for loc in outcome['entities']['local_search_query']:
          self.loc.append({'val': loc['value'], 'from': d_act['from']['email'], 'turn': len(self.turns)})

      # TODO: ideally each object in the state's datetime list should have a preference. What if the person says in the subsequent conversation, that
        # "Oh, actually 6p might work better, but if not I can happily meet at 4. ". An extended version of preference could also be dispreference -
        # changing his mind. for instance, "actually, I can only do 6p, sorry."
      if 'datetime' in outcome['entities']:
        for dt in outcome['entities']['datetime']:
          for i, dt_interpret in enumerate(dt['values']):
            dtval = dateutil.parser.parse(dt_interpret['value'])
            wit_ai_bug = False
            if i>0:
              tmpdtval = dateutil.parser.parse(dt['values'][0]['value'])
              if dtval-tmpdtval > datetime.timedelta(days=365):
                wit_ai_bug = True
            if not wit_ai_bug:
              self.update_dt_avail(d_act['from']['email'], dt_interpret)
              # self.s['dt'].append(dt_interpret)
              # self.s['dt'].add(((dt_interpret['value'], ), user_email, preference)


            # in the following attempt, 'grain' information about datetime will be lost.
            # so we cannot distinguish betwn 'tomorrow' and 'tomorrow at 12am'
            # if dt_interpret['type'] == 'value':
            #   from_dt = dateutil.parser.parse(dt_interpret['value'])
            #   self.s['dt'].append((from_dt, ))
            # elif dt_interpret['type'] == 'interval':
            #   from_dt = dateutil.parser.parse(dt_interpret['from']['value'])
            #   to_dt = dateutil.parser.parse(dt_interpret['from']['value'])
            #   self.s['dt'].append((from_dt, to_dt))

      if 'duration' in outcome['entities']:
        for dur in outcome['entities']['duration']:
          self.dur.append({'val': dur, 'from': d_act['from']['email'], 'turn': len(self.turns)})
          # self.s['duration'].append(dur)

    self.turns.append(info)
Exemplo n.º 4
0
Arquivo: st.py Projeto: gkchai/planus
 def retrieve_users(self):
   for user_email in self.all:
     p = person(user_email)
     self.update_metas_helper(p)
Exemplo n.º 5
0
Arquivo: st.py Projeto: gkchai/planus
    def update_state(self, d_act):
        info = {'d_act': d_act}
        if len(self.all) == 0:
            # this is the first time program is being called, so set the organizer for this meeting
            self.org = d_act['from']['email']
            self.meta['busy'].add(self.org)
            self.meta['ppl'][self.org] = person(self.org,
                                                d_act['from']['first_name'],
                                                'busy')

        self.retrieve_users()
        users = d_act['to'] + [d_act['from']]
        self.update_users(users)

        if len(d_act['nlu']['outcomes']) > 1:
            print 'More than 1 outcome! chk this case..'
            pdb.set_trace()

        #TODO: what happens when wit.ai's output is empty? handle the error cases
        for outcome in d_act['nlu']['outcomes']:
            # Ideally each location should also have an associated preference as should datetime
            if 'location' in outcome['entities']:
                for loc in outcome['entities']['location']:
                    self.loc.append({
                        'val': loc['value'],
                        'from': d_act['from']['email'],
                        'turn': len(self.turns)
                    })

            if 'local_search_query' in outcome['entities']:
                for loc in outcome['entities']['local_search_query']:
                    self.loc.append({
                        'val': loc['value'],
                        'from': d_act['from']['email'],
                        'turn': len(self.turns)
                    })

            # TODO: ideally each object in the state's datetime list should have a preference. What if the person says in the subsequent conversation, that
            # "Oh, actually 6p might work better, but if not I can happily meet at 4. ". An extended version of preference could also be dispreference -
            # changing his mind. for instance, "actually, I can only do 6p, sorry."
            if 'datetime' in outcome['entities']:
                for dt in outcome['entities']['datetime']:
                    for i, dt_interpret in enumerate(dt['values']):
                        dtval = dateutil.parser.parse(dt_interpret['value'])
                        wit_ai_bug = False
                        if i > 0:
                            tmpdtval = dateutil.parser.parse(
                                dt['values'][0]['value'])
                            if dtval - tmpdtval > datetime.timedelta(days=365):
                                wit_ai_bug = True
                        if not wit_ai_bug:
                            self.update_dt_avail(d_act['from']['email'],
                                                 dt_interpret)
                            # self.s['dt'].append(dt_interpret)
                            # self.s['dt'].add(((dt_interpret['value'], ), user_email, preference)

                        # in the following attempt, 'grain' information about datetime will be lost.
                        # so we cannot distinguish betwn 'tomorrow' and 'tomorrow at 12am'
                        # if dt_interpret['type'] == 'value':
                        #   from_dt = dateutil.parser.parse(dt_interpret['value'])
                        #   self.s['dt'].append((from_dt, ))
                        # elif dt_interpret['type'] == 'interval':
                        #   from_dt = dateutil.parser.parse(dt_interpret['from']['value'])
                        #   to_dt = dateutil.parser.parse(dt_interpret['from']['value'])
                        #   self.s['dt'].append((from_dt, to_dt))

            if 'duration' in outcome['entities']:
                for dur in outcome['entities']['duration']:
                    self.dur.append({
                        'val': dur,
                        'from': d_act['from']['email'],
                        'turn': len(self.turns)
                    })
                    # self.s['duration'].append(dur)

        self.turns.append(info)
Exemplo n.º 6
0
Arquivo: st.py Projeto: gkchai/planus
 def retrieve_users(self):
     for user_email in self.all:
         p = person(user_email)
         self.update_metas_helper(p)