Example #1
0
    def __init__(self):
        if Handle.dialog is None:
            dic = DictManager()
            dic.load_dict('../../data/test/name.dic')
            nlu = NLU(dic)
            nlu.setPreprocessor('zhBook')
            nlu.appendTagger(GreedyTagger())
            tagger = RuleTagger()
            ruleFile = '../../data/test/RuleEngine/rule0'
            tagger.loadRules(ruleFile)
            nlu.appendTagger(tagger)
            nlu.setPreprocessor('govTitle')
            nlu.appendRewriter(RemoveTokRewriter())

            nlr = NLR()
            nlr.load_template('../../data/reply-template')

            semantic = SemanticBase()
            semantic.loadSemanticRules(
                '../../data/test/Semantics/wx-test-semantics.json')

            indexer = GovTitleExtracter()
            indexer.getIndexId(dic)
            indexer.loadIndex('../../tools/gov/gov-index')
            indexer.loadContent('../../tools/gov/gov_q')

            dialog = DialogManager()
            dialog.addModule("NLU", nlu)
            dialog.addModule("NLR", nlr)
            dialog.addModule("SEMANTIC", semantic)
            dialog.addModule("GOV", indexer)
            dialog.loadHandler('../../data/state-def-wx.json')
            Handle.dialog = dialog
        else:
            print('dialog already inited')
Example #2
0
#!/usr/bin/python
import argparse
import pprint
import os,sys
from os.path import realpath, join, dirname
sys.path.insert(0, join(dirname(realpath(__file__)), '../'))
from plantDiseaseAI.backend.DictManager import *


pp = pprint.PrettyPrinter(indent=2)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
               description='build dict', usage='''
               ./build-dict.py --data_root=../data/test/dict --output=../data/test/name.dic
               ''', formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--data_root', type=str, 
                         default='../data/test/dict',
                         help='directory root of dict')
    parser.add_argument('--output', type=str,
                         default='../data/test/name.dic',
                         help='output path of dict')
    args = parser.parse_args()
    dic = DictManager()
    dic.compile_dict(args.data_root, args.output)
    #dicTest = DictManager()
    #dicTest.load_dict(args.output)
    #pp.pprint(dicTest._names)
                        type=str,
                        default='Welcome',
                        help='current taskId')
    parser.add_argument('--w',
                        type=str,
                        default='',
                        help='whiteboard variables')
    parser.add_argument(
        '--ss',
        type=str,
        default='../data/test/Semantics/wx-test-semantics.json',
        help='semantics file')
    parser.add_argument('--ii', type=str, help='test dialog file')

    args = parser.parse_args()
    dic = DictManager()
    dic.load_dict(args.d)
    nlu = NLU(dic)
    nlu.appendTagger(GreedyTagger())
    tagger = RuleTagger()
    ruleFile = '../data/test/RuleEngine/rule0'
    tagger.loadRules(ruleFile)
    nlu.appendTagger(tagger)
    nlu.setPreprocessor('govTitle')
    nlu.appendRewriter(RemoveTokRewriter())

    nlr = NLR()
    nlr.load_template(args.t)

    semantic = SemanticBase()
    semantic.loadSemanticRules(args.ss)