Exemple #1
0
def des_sol(question,intent):
        entity=entity_classifier1.entity_recognizer(question.lower())
        if entity is None:
           entity=entity_classifier2.entity(question)
        intent=intent  
        read_file = open(os.path.join(app.root_path, "datasets/desc_sol.json"), 'r')
        data = json.load(read_file)
        ite=data['items']
        if type(entity)==str:
            for d in ite:
                 if entity.lower()==d['title'].lower():
                      if intent=="Description":
                          desc="Description for "+d['title']+" is : "+ d[intent]
                          intent="NULL"
                          return desc
                          break
                      else:
                          sol="Solution for "+d['title']+" is : "+ d[intent]
                          intent="NULL"
                          return sol
                          break
        else:
             if len(entity)>0:
                for i in entity:
                    entity[i]=intent+" "+entity[i]
                
                return entity
             else:
                msg="Please be more specific"
                return msg
Exemple #2
0
def des_sol(question, intent):
    entity = entity_classifier1.entity_recognizer(question.lower())
    if entity is None:
        entity = entity_classifier2.entity(question)
    intent = intent
    read_file = open(os.path.join(app.root_path, "datasets/desc_sol.json"),
                     'r')
    data = json.load(read_file)
    ite = data['items']
    if type(entity) == str:
        for d in ite:
            if entity.lower() == d['title'].lower():
                if intent == "Description":
                    desc = "Description for " + d['title'] + " is : " + d[
                        intent]
                    intent = "NULL"
                    return desc
                    break
                else:
                    sol = "Solution for " + d['title'] + " is : " + d[intent]
                    intent = "NULL"
                    return sol
                    break
    else:
        if len(entity) > 0:
            for i in entity:
                entity[i] = intent + " " + entity[i]

            return entity
        else:
            msg = "Please be more specific"
            return msg
Exemple #3
0
def des_sol(question, intent):
    entity = entity_classifier1.entity_recognizer(question.lower())
    if entity is None:
        entity = entity_classifier2.entity(question)

    intent = intent
    read_file = open(
        os.path.join(app.root_path, "datasets/desc_solution.json"), 'r')
    data = json.load(read_file)
    ite = data['items']
    if type(entity) == str:
        for d in ite:
            if entity.lower() == d['title'].lower():
                if intent == "Description":
                    desc = "Description for " + d['title'] + " is : " + d[
                        intent]
                    intent = "NULL"
                    return desc
                    break
                else:
                    sol = "Solution for " + d['title'] + " is : " + d[intent]
                    intent = "NULL"
                    return sol
                    break
    else:
        if settings.GOOGLE:
            if question:
                result = web_scraping.web_scraper(question)
                return result
        elif len(entity) > 0:
            for i in entity:
                entity[i] = intent + " " + entity[i]
            return entity
        else:
            log = open(os.path.join(app.root_path, "logs.txt"), "a")
            msg = "Please be more specific"
            if settings.CHATBOT_LOG == "db":
                result = ChatbotLog(question)
                db.session.add(result)
                db.session.commit()
            else:
                log = open(os.path.join(app.root_path, "logs.txt"), "a")
                log.write(question + "\n")
                log.close()
            return msg