コード例 #1
0
	def post(self):
		try:
			scene = itest = None;
			if not self.body_json.has_key('text'):
				self.except_handle('the url data format error');
				return ;
			itest = self.body_json['text'];

			if not self.body_json.has_key('scene'):
				self.except_handle('not found argumen scene');
			else:
				scene = self.body_json['scene'];
			if len(itest) == 0:
				self.except_handle('the param text is empty');
				return ;
			if scene is None or scene == 'None' or len(scene) == 0:
				scene = None;
			logging.info('scene:%s input:%s' %(scene,itest));
			sres = self.mager.encode(itest,scene);
			common.print_dic(sres);
			self.write(self.gen_result(0,'enjoy success',sres));
		except Exception as e:
			logging.error(str(e));
			raise e;
コード例 #2
0
calc_sds = CalcSDS(net_data);

mark_unit.load_data('../tdata/unit.txt');
mark_num.load_data('../tdata/num.txt');
mark_tmood.load_data('../tdata/time_mood.txt');

calc_prep.load_data('../tdata/calc_prep.txt');
calc_verb.load_data('../tdata/calc_verb.txt');

fp = open('./test.txt','rb');
for line in fp.readlines():
	line = line.strip('\n');
	if line[0] == '#' or len(line) == 0: continue;
	struct['text'] = line.decode('utf-8');
	struct['tag_dict'] = dict();
	timer.encode(struct);
	struct['sp_sentence'] = word_seg.tokens(struct['text']);
	mark_tag.encode(struct);
	mark_num.encode(struct);
	mark_unit.encode(struct);
	mark_tmood.encode(struct);
	merge_obj.encode(struct);

	calc_prep.encode(struct);
	calc_verb.encode(struct);
	calc_nunit.encode(struct);
	calc_sds.encode(struct);
	common.print_dic(struct);
	break;

コード例 #3
0
ファイル: mager.py プロジェクト: dujinle/syntax_server
        self.struct['seg_text'] = self.wordseg.tokens(self.struct['text'])
        self.struct['otext'] = self.struct['text']
        self.struct['result'] = dict()

        self.timer.encode(self.struct)

        self.concpt.encode(self.struct)
        return self.struct


common.debug = False

if common.debug == True:
    try:
        mg = Mager()
        mg.init()
        while True:
            istr = raw_input("raw_input: ")
            if istr == 'q' or istr == 'bye': break
            print istr
            sarr = istr.decode('utf8').split(' ')
            if len(sarr) == 2:
                common.print_dic(mg.encode(sarr[0], sarr[1]))
            elif len(sarr) == 3:
                common.print_dic(mg.encode(sarr[0], sarr[1], sarr[2]))
            else:
                common.print_dic(mg.encode(sarr[0]))
    except Exception as e:
        raise e
コード例 #4
0
    print 'Usage:%s infile' % sys.argv[0]

ntype = {
    "prev": {
        "小姐": "MISS",
        "女士": "MISS",
        "先生": "SIR",
        "总": "MR"
    },
    "tail": {
        "小": "SIR",
        "老": "SIR"
    }
}

tdata = dict()
data = common.readfile(sys.argv[1])
for ty in ntype:
    for it in ntype[ty]:
        for dt in data:
            tdic = dict()
            if ty == 'prev':
                tdic['str'] = dt + it
            elif ty == 'tail':
                tdic['str'] = it + dt
            tdic['type'] = 'SB'
            tdic['stype'] = ntype[ty][it]
            tdata[tdic['str']] = tdic

common.print_dic(tdata)