def teachMode3(sent, target=None): sent = mgr.doWords(sent) info = nlpCtr.abstractSentence(sent) # obj = getItem(mgr.getRealName(info['object'])) subjFunc = mapper.getModeMap(mgr.getRealName(info['subject'])) objFunc = mapper.getModeMap(mgr.getRealName(info['object'])) hedFunc = mapper.getModeMap(info['pred'])
def anylize(sent): # sent = mgr.doWords(sent) info = nlpCtr.abstractSentence(sent) subj = info['subject'] obj = info['object'] hed = info['pred'] attSubj = info['attSubj'] attObj = info['attObj'] if hed and subj and obj: hed = 'teach_' + info['pred'] teach(hed, subj, obj)
def teach(sent): sent = mgr.doWords(sent) info = nlpCtr.abstractSentence(sent) subj = getItem(mgr.getRealName(info['subject'])) obj = getItem(mgr.getRealName(info['object'])) hedFunc = mapper.getMap(info['pred']) exec(hedFunc, {'subj': subj, 'obj': obj}) smartUpDb(subj) smartUpDb(obj) # print(obj.members) return subj, obj
def teachMode(sent, target=None): sent = mgr.doWords(sent) info = nlpCtr.abstractSentence(sent) obj = getItem(mgr.getRealName(info['object'])) subjFunc = mapper.getModeMap(mgr.getRealName(info['subject'])) hedFunc = mapper.getModeMap(info['pred']) if subjFunc and hedFunc: tar = obj if target is None else getItem(target) mode = tar.mode mode += [(subjFunc + hedFunc, obj.name)] tar.setMode(mode) smartUpDb(tar)
def anylize2(sent, content): info = nlpCtr.abstractSentence(sent) subj = info['subject'] obj = info['object'] hed = info['pred'] attSubj = info['attSubj'] attObj = info['attObj'] subjRes = None objRes = None if subj and attSubj and content: subjRes = actionAtt('action_' + subj, attSubj, content) if obj and attObj and content: objRes = actionAtt('action_' + obj, attObj, content) if hed and subjRes and objRes: m = eval(hed) arr = getArgs(hed) dic = {} for i in arr: dic[i] = eval(i) res = m(**dic) print(res)
paragraph = """ 在美丽的旌湖旁,坐落着德阳市实验小学校。 一进校门,看到四周有几座高大的教学楼,分别是真全楼、真玉楼、真思楼、真问楼、真学楼。穿过真玉楼来到了我们篮球场和乒乓球场,又穿过乒乓球场就来到了红红的跑道上。跑道像一大片红领巾似的,向前走来到了升旗台。每到星期一的时候,全校同学在升旗台下一起唱国歌。这是一所非常美丽的学校! 春天,学校的树木和小草开始发芽了,到处鸟语花香,生机勃勃。漂亮的李花开了,白白的,像花仙子正在翩翩起舞似的。 夏天,学校树木的叶子长得又多又密,像撑开的大伞,给我们遮阳避暑。小草也长得多绿多茂密啊!真像一块绿油油的地毯。 秋天,花草凋落,秋姑娘把树上的叶子涂成了黄色。同学们都喜欢把捡来的银杏叶做成书签。枫叶也渐渐地变成红色,枫叶像手掌一样,真美丽啊! 冬天,天气越来越冷了,我们穿的可厚了。树上的叶子打了一层厚厚的霜。霜是白色的,摸一下就会掉。霜真的好神奇啊! 我爱学校,更爱学校的四季,学校的四季就像画家笔下的四季图一样,美丽而迷人。 """ questions = [ '德阳市实验小学校在哪里?', '德阳市实验小学校有哪些教学楼?', '德阳市实验小学校的升旗台在哪里?', '我爱学校吗?', '我是比较爱学校,还是学校的四季?', '夏天,学校树木的叶子长得怎样?', ] paraList = nlpCtr.paragraphToList(paragraph) modeCtr.learn(paraList) for q in questions: datas = nlpCtr.abstractSentence(q) modeCtr.question(datas)
def teachMode2(sent, target): sent = mgr.doWords(sent) info = nlpCtr.abstractSentence(sent) hedFunc = mapper.getModeMap(info['pred'])
# pos = ltp.pos(hidden) # dep = ltp.dep(hidden) # print(seg) # print(pos) # print(dep) from NlpCtr import nlpCtr from SentMgr import SentMgr from QuesRecognizer import quesRgr from ComFuncs import * # nlpCtr.abstractSentence('妈妈是一个可爱的人,她有一双灵巧的手。') sentC = '在我们的校园里有一处美丽的景色,非常有人气,那就是校园的鱼池。' # sentC = '我们的校园有什么?' infosC = nlpCtr.abstractSentence(sentC) sentMgr = SentMgr(infosC) quesRgr.fitMode(sentC, sentMgr) # resC = [] # sentC = '在我们的校园里有一处美丽的景色,那就是校园的鱼池。' # infosC = nlpCtr.abstractSentence(sentC) # for i in infosC: # resC.append(SentMgr(i)) # res = [] # sent = '我们的校园有鱼池吗?' # infos = nlpCtr.abstractSentence(sent) # for i in infos: # res.append(SentMgr(i))
# sents = ltp.sent_split([paragraph]) # for sent in sents: # print(sent) seg, hidden = ltp.seg([paragraph]) paragraph = '&'.join(seg[0]) print(paragraph) # pattern = r'(.+)是(.+),还是(.+?)[?。]{0,}$' #今天的晚餐是要吃面,还是要吃汉堡? # pattern = r'(.+)&和&(.+),(.+比较.+)[?。]{0,}$' #学校和学校的四季,你比较喜欢哪个? pattern = r'(.+?)&(爱)&(.+?),(&更&爱&)(.+?)[,。].*' #我爱学校,更爱学校的四季,学校的四季就像画家笔下的四季图一样,美丽而迷人。 ret = re.match(pattern, paragraph) if ret: print(ret.groups()) groups = ret.groups() for g in groups: info = nlpCtr.abstractSentence(g.replace('&', '')) print('g:', info) # sent = '我爱学校,更爱学校的四季。' # seg, hidden = ltp.seg([sent]) # pos = ltp.pos(hidden) # dep = ltp.dep(hidden) # print(seg) # print(pos) # print(dep) # print(nlpCtr.abstractSentence(sent)) class Master(): def __init__(self) -> None: self._name = ''