Exemple #1
0
    def where(self, q, last_r):
        current_entity, current_type, current_solr_r = self.retrieve_entity(
            q, 'store%20entertainment%20facility')
        if last_r and not current_entity:
            last_entity, last_type, last_solr_r = self.retrieve_entity(
                last_r, 'store%20entertainment%20facility')
        else:
            last_entity = None

        if current_entity:
            location = SolrUtils.get_dynamic_response(current_solr_r,
                                                      'rich_location',
                                                      random_field=True)
            if not location:
                return self.simple.kernel(q)
            return None, current_entity + "," + location
        if not last_entity:
            location = '您在问什么?'
            return None, location

        q = QueryUtils.static_remove_pu(q).decode('utf-8')
        strict = re.compile(ur'在哪|在什么地方|带我去|在哪里')
        if re.match(strict, q):
            location = SolrUtils.get_dynamic_response(last_solr_r,
                                                      'rich_location',
                                                      random_field=True)
            if not location:
                location = '数据库中不存在'
            return None, location
        return 'base', "数据库中不存在"
Exemple #2
0
 def kernel(self, q, last_r):
     try:
         exact = self.exact_match(QueryUtils.static_remove_pu(q))
         if exact:
             return None, exact
         cls, probs = self.clf.predict(q)
         #
         if cls == 'where':
             direction, answer = self.where(q=q, last_r=last_r)
             return direction, answer
         if cls == 'exist':
             direction, answer = self.exist(q=q, last_r=last_r)
             return direction, answer
         if cls == 'ask_price':
             direction, answer = self.ask_price(q=q, last_r=last_r)
             return direction, answer
         if cls == 'ask_discount':
             direction, answer = self.ask_discount(q=q, last_r=last_r)
             return direction, answer
         if cls == 'ask_queue':
             direction, answer = self.ask_queue(q=q, last_r=last_r)
             return direction, answer
         # if cls == 'permit':
         #     direction, answer = self.permit(q=q, last_r=last_r)
         #     return direction, answer
         # if cls == 'whether':
         #     direction, answer = self.whether(q=q, last_r=last_r)
         #     return direction, answer
         # if cls == 'when':
         #     direction, answer = self.when(q=q, last_r=last_r)
         #     return direction, answer
         # if cls == 'how':
         #     direction, answer = self.how(q=q, last_r=last_r)
         #     return direction, answer
         # if cls == 'which':
         #     direction, answer = self.which(q=q, last_r=last_r)
         #     return direction, answer
         # if cls == 'what':
         #     direction, answer = self.what(q=q, last_r=last_r)
         #     return direction, answer
         if cls == 'list':
             direction, answer = self.list(q=q, last_r=last_r)
             return direction, answer
         if cls == 'ask_taste':
             direction, answer = self.taste(q=q, last_r=last_r)
             return direction, answer
         return self.simple.kernel(q)
     except Exception, e:
         traceback.print_exc()
         return self.simple.kernel(q)
Exemple #3
0
 def kernel(self, q):
     ## first try regex_plugin:
     scene, sugg_scene, q = self.regex_plugin(q)
     if scene:
         return scene, sugg_scene, q
     try:
         if not self.web:
             if not self.clf:
                 return 'sale', None, q
             q = QueryUtils.static_remove_pu(q)
             labels, _ = self.clf.predict(question=q)
             select = self.select_label(labels)
             ## qa plugin:
             if select == 'qa':
                 return select, 'sale', q
             if select == 'greeting':
                 return select, 'base', q
             return select, None, q
         else:
             text = requests.get('http://localhost:11305/sc/scene?q=' + q)
             return text.text, None, q
     except:
         return None, q