Exemple #1
0
def scenario_based(text):
    sent = api.sentences(text)
    text = []
    for s in sent['sentences']:
        morphs = api.morph(s)
        query = list()
        for morph in morphs['morphs']:
            query.append(u'{}:{}'.format(morph['surface'], morph['pos']))
    texts = api.trigger(scenario_file,query)
    for t in texts['texts']:
        text.append(t)
    if len(text)>0:
        r = random.randint(0,len(text)-1)
        return text[r]
    return None
Exemple #2
0
    for rep in reps["replies"]:
        print "======================================================"
        if reps["grade"] == 0:
            scenario_file = "scenario_c09.txt"
        elif reps["grade"] == 1:
            scenario_file = "scenario_c09.txt"
        else:
            scenario_file = "scenario_c09.txt"
        sent = api.sentences(rep["text"])
        text = []
        for s in sent["sentences"]:
            print "-------------------------------------------------------"
            print s
            morphs = api.morph(s)
            print json.dumps(morphs, ensure_ascii=False, indent=4)
            query = list()
            for morph in morphs["morphs"]:
                query.append(u"{}:{}".format(morph["surface"], morph["pos"]))
            print json.dumps(query, ensure_ascii=False, indent=4)
            texts = api.trigger(scenario_file, query)
            print json.dumps(texts, ensure_ascii=False, indent=4)
            for t in texts["texts"]:
                text.append(t)
                print t
        if len(text) > 0:
            r = random.randint(0, len(text) - 1)
            print "++++++++++++++++++++++++++++++++++++++"
            print str(len(text))
            print text[r]
            api.send_reply(rep["mention_id"], rep["user_name"], text[r])