コード例 #1
0
ファイル: TrainFromSql.py プロジェクト: Lisaheyu/lisa1111
def WriteAiml_how(knowledge,string_how,ID, fw_match):
    if len(knowledge) < 2:
        return
    question = []
    for item in knowledge:
        question.append(item.Question)

    parm = question[1]
    key = parm.split('>')[0]
    verb = parm.split('>')[1]
    keyList = PProc.withtag_cut(key)[0]
    PProc.syn_wordlist(keyList)
    verb = PProc.syn_word(verb)
    if '0' not in keyList:
        stringx = string_how.replace('KNOW', (u'KNOWLEDGE %s' % ID).encode('utf-8'))
        stringx = stringx.replace('KEY', ' '.join(keyList).encode('utf-8'))
        stringx = stringx.replace('VERB', verb.encode('utf-8'))
        stringx = stringx.replace('VALUE', (u'match-what|%s' %ID).encode('utf-8'))
        fw_match.write(stringx)
    else:
        keyList[keyList.index('0')] = '*'
        stringx = string_how.replace('KNOW', (u'KNOWLEDGE %s' % ID).encode('utf-8'))
        stringx = stringx.replace('KEY', ' '.join(keyList).encode('utf-8'))
        stringx = stringx.replace('VERB', verb.encode('utf-8'))
        stringx = stringx.replace('VALUE', (u'match-what|%s' % ID).encode('utf-8'))
        fw_match.write(stringx)
        keyList.remove('*')
        stringx = string_how.replace('KNOW', (u'KNOWLEDGE %s' % ID).encode('utf-8'))
        stringx = stringx.replace('KEY', ' '.join(keyList).encode('utf-8'))
        stringx = stringx.replace('VERB', verb.encode('utf-8'))
        stringx = stringx.replace('VALUE', (u'match-what|%s' % ID))
        fw_match.write(stringx)
コード例 #2
0
ファイル: TrainFromSql.py プロジェクト: Lisaheyu/lisa1111
def updata_searchengine(Knowledge,SeIndexDir):
    #remove old index
    os.system('rm -rf %s' % SeIndexDir)
    os.system('mkdir %s' % SeIndexDir)

    QuestionNorm = []
    for KID,item in Knowledge.items():
        for question in item[0]:
            if int(question.IsNorm) == 1:
                QuestionNorm.append(question)

    question = []
    for item in QuestionNorm:
        mid = {}
        mid['question'] = item.Question
        mid['questionID'] = item.QuestionID
        question.append(mid)

    schema = Schema(title=TEXT(stored=True),quesId=ID(stored=True))
    ix = create_in(SeIndexDir, schema)

    writer = ix.writer()
    for i in question:
        word = PProc.cut_for_search(i['question'])
        PProc.syn_wordlist(word)
        writer.add_document(title=u' '.join(word),quesId = u'%s' % i['questionID'])
    writer.commit()
コード例 #3
0
ファイル: TrainFromSql.py プロジェクト: Lisaheyu/lisa1111
def WriteAiml_what(knowledge, string_what, ID, fw_match):
    if len(knowledge) < 2:
        return
    key = knowledge[1].Question
    keyList, tag = PProc.withtag_cut(key)
    PProc.syn_wordlist(keyList)
    stringx = string_what.replace('KNOW', (u'KNOWLEDGE %s' % ID).encode('utf-8'))
    stringx = stringx.replace('KEY', ' '.join(keyList).encode('utf-8'))
    stringx = stringx.replace('VALUE', (u'match-what|%s' % ID).encode('utf-8'))
    fw_match.write(stringx)