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)
def ProcessRow_chat(row): result = [] for question in row: filter = [u',',u'?',u'。',u';',u'!',u'“',u'”',u'’',u'‘',u',',u'.',u'!','?'] for i in filter: question = question.replace(i, '') lenOfQ = len(question) if lenOfQ == 0: continue listOfWildcard = [] for i in range(lenOfQ): if question[i] == '=': listOfWildcard.append(i) word,tag = PProc.withtag_cut(question) for idx in listOfWildcard: imid = 0 for idxOfword,item in enumerate(word): if imid == idx: word.insert(idxOfword, u'=') tag.insert(idxOfword, 'wc') break imid += len(item) word, tag = PProc.wordtag_process(word, tag) #print ' '.join(word) result += QuestionGet_chat(word, tag) return result
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)