예제 #1
0
def answer():
    # 接收前端发来的语音消息,并指定路径保存
    reco_file = request.files.get('reco')
    # 调用uuid三方模块生成唯一文件名
    from uuid import uuid4
    filename = f'{uuid4()}.wav'

    filepath = os.path.join(os.path.dirname(__file__), 'audio', 'questions', filename)
    reco_file.save(filepath)
    # print('语音问题保存路径:',filepath)

    # 调用语音识别模块,对语音信息进行格式转换保存在指定目录,然后进行识别,得到文字信息
    from ASR import asr
    text_question = asr(filepath)
    # print('语音问题文本',text_question)

    # 调用自然语言处理模块,对文字信息进行处理,得到回复文字信息
    from NLP import nlp
    text_answer = nlp(text_question)
    # print('语音回答文本',text_answer)

    # 调用语音合成模块,对回复的文字信息进行合成并保存在指定目录下
    from TTS import tts
    answer_filepath = tts(text_answer)
    print('语音回答文件路径:', answer_filepath)

    # 获取语音应答消息文件名并返回
    answer_filename = os.path.basename(answer_filepath)
    return {'filename': answer_filename}
예제 #2
0
    def cont_search(self, query):
        l = []
        n = nlp()
        chunks = n.process_content(query)
        print chunks

        for i in xrange(1, 4):
            d = {}
            for x in chunks:
                d[x] = []
            w = 'P' + str(i)
            # print w
            db = Client[w]
            # ld = db["linkData"]
            # ll = db["linkList"]
            linkData = db["linkData"]
            # for j in linkData.find():
            #     print j["name"]

            for res in linkData.find():
                v = 0
                texts = res["Contents"]
                for i in d:
                    for y in texts:
                        if i in y:
                            v = v + 1
                            # if res["URL"] not in d[i]:
                            #     d[i].append(res["URL"])
                    if v != 0:
                        d[i].append({res["URL"]: v})
                    #d[i][1].append(v)
            # print d

            for u in d.values()[0]:
                # print u.keys()
                # print ("--------------")
                c = 0
                for x in range(1, len(d)):
                    for t in d.values()[x]:
                        if u.keys() == (t.keys()):
                            c = c + 1
                if c == (len(d) - 1):
                    l.append(u)

        return l


# vp=search()
# q="sharedspace"
# print(vp.cont_search(q))
예제 #3
0
    def cont_search(self, query):
        l = []
        n = nlp()
        chunks = n.process_content(query)
        print chunks
        db = Client["IDF"]
        coll = db["Fri"]
        d = {}
        for x in chunks:
            d[x] = []

        for res in coll.find():
            v = 0
            texts = res["Representatives"]
            for i in d:
                for y in texts:
                    if i in y:
                        v = v + 1
                        if v != 0:
                            d[i].append(res["URL"])

        for u in d.values()[0]:
            c = 0
            for x in range(1, len(d)):
                for t in d.values()[x]:
                    if u == t:
                        c = c + 1
            if c == (len(d) - 1):
                if u not in l:
                    l.append(u)
        print len(l)
        return l


# vp=search()
# q="mdn"
# print vp.cont_search(q)
예제 #4
0
from NLP import nlp
from pymongo import MongoClient

meaningful=nlp()
Client = MongoClient()
linkk = "http://w3schools.com/css/default.asp"
# lin = "https://youtube.com/"
que = "HTML java"

class search1(object):

    def __init__(self):
        self.s = []
        self.p = []

    def process(self,query):

        chunks = meaningful.process_content(query)
        # print chunks

        for cnt in xrange(1,4):
            d = {}
            e = {}
            for x in chunks:
                d[x]=[]
                e[x]=[]

            w = "P" + str(cnt)
            # print w
            db = Client[w]
            linkData = db["linkData"]
예제 #5
0
from NLP import nlp
from pymongo import MongoClient
Client = MongoClient()
n = nlp()


class search(object):
    def cont_search(self, query):
        l = []
        n = nlp()
        chunks = n.process_content(query)
        print chunks

        for i in xrange(1, 4):
            d = {}
            for x in chunks:
                d[x] = []
            w = 'P' + str(i)
            # print w
            db = Client[w]
            # ld = db["linkData"]
            # ll = db["linkList"]
            linkData = db["linkData"]
            # for j in linkData.find():
            #     print j["name"]

            for res in linkData.find():
                v = 0
                texts = res["Contents"]
                for i in d:
                    for y in texts: