Пример #1
0
def code(question, intent, language):
    code_entity = code_classify.entity(question)
    read_file = open(os.path.join(app.root_path, "datasets/code_data.json"),
                     'r')
    code_data = json.load(read_file)
    code_ite = code_data['items']
    code_languages = []
    count = 0
    if len(code_entity) == 2 and type(code_entity[0]) == str:
        entity = str(code_entity[0].strip("\n").lower())
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        else:
            language = language
        for d in code_ite:
            if entity == d['title'].lower():
                code_languages.append(d['code_lang'])
        for d in code_ite:
            if entity == d['title'].lower() and language in code_languages:
                if language == d['code_lang'].lower():
                    code_a = "Code for " + d[
                        'content'] + "\n Code language is " + d['code_lang']
                    count = count + 1
                    return code_a
        if count == 0:
            ent = {}
            for i in range(len(code_languages)):
                entity = intent + " " + str(code_entity[0].strip(
                    "\n").lower()) + " in " + code_languages[i]
                print(entity)
                ent[i] = entity
            return ent
            for d in code_ite:
                if entity == d['title'].lower() and lang in code_languages:
                    if lang == d['code_lang'].lower():
                        return d['content']
                        count = count + 1
    else:
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        elif language:
            language = language
        else:
            msg = "Please be more specific"
            if settings.CHATBOT_LOG == "db":
                result = chatbot_log(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
        code_list = {}
        for i in code_entity[0]:
            code_list[i] = intent + " " + code_entity[0][i]
        return code_list
Пример #2
0
def code(question, intent, language):
    code_entity = code_classify.entity(question)
    read_file = open(os.path.join(app.root_path, "datasets/code_data.json"),
                     'r')
    code_data = json.load(read_file)
    code_ite = code_data['items']
    code_languages = []
    count = 0
    if len(code_entity) == 2 and type(code_entity[0]) == str:
        entity = str(code_entity[0].strip("\n").lower())
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        else:
            language = language
        for d in code_ite:
            if entity == d['title'].lower():
                code_languages.append(d['code_lang'])
        for d in code_ite:
            if entity == d['title'].lower() and language in code_languages:
                if language == d['code_lang'].lower():
                    code_a = "Code for " + d[
                        'content'] + "\n Code language is " + d['code_lang']
                    count = count + 1
                    return code_a, language
        if count == 0:
            code_l = {}
            entity = intent + " " + str(code_entity[0].strip("\n").lower())
            for i in range(len(code_languages)):
                code_l[i + 1] = code_languages[i]
            return entity, code_l
            #print("The language you typed is not availabe. Select from the following:")
            #for i in code_l:
            #   print(str(i)+":"+code_l[i])
            #TO_BE_CHANGEDn=int(input("Enter your choice: "))
            #lang=language
            for d in code_ite:
                if entity == d['title'].lower() and lang in code_languages:
                    if lang == d['code_lang'].lower():
                        return d['content']
                        #print("\n Code language is " + d['code_lang'])
                        count = count + 1
        #TO_BE_CHANGEDques=input("\n Do you have more Questions Y/N ")
    else:
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        else:
            language = language
        code_list = {}
        for i in code_entity[0]:
            code_list[i] = intent + " " + code_entity[0][i]
        return code_list, language
Пример #3
0
def code(question,intent,language):
        code_entity=code_classify.entity(question)
        read_file = open(os.path.join(app.root_path, "datasets/code_data.json"), 'r') 
        code_data = json.load(read_file)
        code_ite=code_data['items']
        code_languages=[]
        count=0
        if len(code_entity)==2 and type(code_entity[0])==str:
            entity=str(code_entity[0].strip("\n").lower())
            if language is None:
               language=str(code_entity[-1].strip("\n").lower())
            else:
               language=language
            for d in code_ite:
                 if entity==d['title'].lower():
                    code_languages.append(d['code_lang'])
            for d in code_ite:
                 if entity==d['title'].lower() and language in code_languages:
                    if language==d['code_lang'].lower():
                       code_a="Code for "+ d['content']+"\n Code language is " + d['code_lang']
                       count=count+1
                       return code_a,language
            if count==0:
                    code_l={}
                    entity=intent+" "+str(code_entity[0].strip("\n").lower())
                    for i in range(len(code_languages)):
                        code_l[i+1]=code_languages[i]
                    return entity,code_l      
                    #print("The language you typed is not availabe. Select from the following:")
                    #for i in code_l:
                     #   print(str(i)+":"+code_l[i])
                    #TO_BE_CHANGEDn=int(input("Enter your choice: "))
                    #lang=language
                    for d in code_ite:
                        if entity==d['title'].lower() and lang in code_languages:
                              if lang==d['code_lang'].lower():
                                 return d['content']
                                 #print("\n Code language is " + d['code_lang'])
                                 count=count+1
            #TO_BE_CHANGEDques=input("\n Do you have more Questions Y/N ")
        else:
             if language is None:
               language=str(code_entity[-1].strip("\n").lower())
             else:
               language=language
             code_list={}
             for i in code_entity[0]:
                 code_list[i]=intent+" "+code_entity[0][i]
             return code_list,language
Пример #4
0
def code(question, intent, language):
    code_entity = code_classify.entity(question)
    read_file = open(os.path.join(app.root_path, "datasets/code_data.json"),
                     'r')
    code_data = json.load(read_file)
    code_ite = code_data['items']
    code_languages = []
    count = 0
    if len(code_entity) == 2 and type(code_entity[0]) == str:
        entity = str(code_entity[0].strip("\n").lower())
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        else:
            language = language
        for d in code_ite:
            if entity == d['title'].lower():
                code_languages.append(d['code_lang'])
        for d in code_ite:
            if entity == d['title'].lower() and language in code_languages:
                if language == d['code_lang'].lower():
                    code_a = "Code for " + d[
                        'content'] + "\n Code language is " + d['code_lang']
                    count = count + 1
                    return code_a
        if count == 0:
            ent = {}
            for i in range(len(code_languages)):
                entity = intent + " " + str(code_entity[0].strip(
                    "\n").lower()) + " in " + code_languages[i]
                print(entity)
                ent[i] = entity
            return ent
            for d in code_ite:
                if entity == d['title'].lower() and lang in code_languages:
                    if lang == d['code_lang'].lower():
                        return d['content']
                        count = count + 1
    else:
        if language is None:
            language = str(code_entity[-1].strip("\n").lower())
        else:
            language = language
        code_list = {}
        for i in code_entity[0]:
            code_list[i] = intent + " " + code_entity[0][i]
        return code_list