训练
@throws Exception
779558
public void train() throws Exception {

		loadData();
		/**
		 * 
		 * 更新参数的准则
		 */
		Update update;
		// viterbi解码
		Inferencer inference;

		HammingLoss loss = new HammingLoss();
		if (standard) {
			inference = new LinearViterbi(templets, labels.size());
			update = new LinearViterbiPAUpdate((LinearViterbi) inference, loss);
		} else {
			inference = new HigherOrderViterbi(templets, labels.size());
			update = new HigherOrderViterbiPAUpdate(templets, labels.size(), true);
		}

		OnlineTrainer trainer;

		if(cl!=null){
			trainer = new OnlineTrainer(cl, update, loss, factory,iterNum, c);
		}else{
			trainer = new OnlineTrainer(inference, update, loss,
					factory, iterNum, c);
		}

		cl = trainer.train(trainSet, testSet);

		if(cl!=null&&newmodel!=null)
			saveTo(newmodel);
		else
			saveTo(model);

	}
775142
@Override
    public void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage) throws Exception {
        try {
            JSONObject json = new JSONObject(((TextMessage) webSocketMessage).getPayload());
            ValidMessage rm = (ValidMessage) tgtools.util.JsonParseHelper.parseToObject(json, ValidMessage.class);
            validLogin(webSocketSession, rm);
            mWebsocketCommand.process(rm.getOperation(), rm.getData());
        } catch (Exception e) {
            try {
                ResponseMessage data = new ResponseMessage();
                data.setStatus(false);
                data.setData(e.getMessage());
                webSocketSession.sendMessage(new TextMessage(tgtools.util.JsonParseHelper.parseToJsonObject(data).toString()));
            } catch (Exception ex) {
                LogHelper.error("","AbstractSingleWebSocketHandler 初始化失败；原因："+e.toString(),"AbstractSingleWebSocketHandler.handleMessage",e);

            }
        }

    }
883958
protected void execute(final String[] args) throws Exception {
		// Process command-line.
		if (args.length == 0 || args.length == 1) {
			usage();
		}
		String userpass = args[0];
		String hostportOrPid = args[1];
		String beanname = null;// vGCutil
		String[] command = null;
		if (args.length > 2) {
			beanname = args[2];
		}
		if (args.length > 3) {
			command = new String[args.length - 3];
			for (int i = 3; i < args.length; i++) {
				command[i - 3] = args[i];
			}
		}
		String[] loginPassword = parseUserpass(userpass);

		// 模拟GC Util命令的扩展
		if (V_GCUTIL_BEAN_NAME.equalsIgnoreCase(beanname)) {
			// 支持配置interval 固定事件间隔连续输出
			int interval = 0;
			if (command != null && command.length > 0) {
				try {
					interval = Math.abs(Integer.parseInt(command[0]));// 拿绝对值, 避免负数的情况
				} catch (NumberFormatException e) {// NOSONAR
				}
			}

			ExtraCommand extraCommand = new ExtraCommand();
			extraCommand.execute(hostportOrPid, ((loginPassword == null) ? null : loginPassword[0]),
					((loginPassword == null) ? null : loginPassword[1]), beanname, interval);
			return;
		}

		Object[] result = execute(hostportOrPid, ((loginPassword == null) ? null : loginPassword[0]),
				((loginPassword == null) ? null : loginPassword[1]), beanname, command);
		if (result != null) {
			for (int i = 0; i < result.length; i++) {
				if (result[i] != null && result[i].toString().length() > 0) {
					if (command != null) {
						logger.info(command[i] + ": " + result[i]);
					} else {
						logger.info("\n" + result[i].toString());
					}
				}
			}
		}
	}
1325800
public login login() throws Exception
	{
		login login_obj = new login();
		login_obj.set_username(this.user_name);
		login_obj.set_password(this.password);
		login_obj.set_session_timeout(this.timeout);
		
		login result = login.add(this, login_obj);
		sessionid = result.get_sessionid();
		
		return result;
	}
853519
public static void main(String[] args) throws Exception {
		CWSTagger tag = new CWSTagger("../models/seg.m");
		System.out.println("不使用词典的分词：");
		String str = " 媒体计算研究所成立了, 高级数据挖掘(data mining)很难。 乐phone热卖！";
		String s = tag.tag(str);
		System.out.println(s);
		
		//设置英文预处理
		tag.setEnFilter(true);
		s = tag.tag(str);
		System.out.println(s);
//		tag.setEnFilter(false);
		
		System.out.println("\n设置临时词典：");
		ArrayList<String> al = new ArrayList<String>();
		al.add("数据挖掘");
		al.add("媒体计算研究所");
		al.add("乐phone");
		Dictionary dict = new Dictionary(false);
		dict.addSegDict(al);
		tag.setDictionary(dict);
		s = tag.tag(str);
		System.out.println(s);
		
		
		CWSTagger tag2 = new CWSTagger("../models/seg.m", new Dictionary("../models/dict.txt"));
		System.out.println("\n使用词典的分词：");
		String str2 = "媒体计算研究所成立了, 高级数据挖掘很难。 乐phone热卖！";
		String s2 = tag2.tag(str2);
		System.out.println(s2);
		
		//使用不严格的词典
		CWSTagger tag3 = new CWSTagger("../models/seg.m", new Dictionary("../models/dict_ambiguity.txt",true));
		//尽量满足词典，比如词典中有“成立”“成立了”和“了”, 会使用Viterbi决定更合理的输出
		System.out.println("\n使用不严格的词典的分词：");
		String str3 = "媒体计算研究所成立了, 高级数据挖掘很难";
		String s3 = tag3.tag(str3);
		System.out.println(s3);
		str3 = "我送给力学系的同学一个玩具 (送给给力力学力学系都在词典中)";
		s3 = tag3.tag(str3);
		System.out.println(s3);
		
		System.out.println("\n处理文件：");
		String s4 = tag.tagFile("../example-data/data-tag.txt");
		System.out.println(s4);
		
		String s5 = tag2.tagFile("../example-data/data-tag.txt");
		System.out.println(s5);
		
	}
533206
public function callback() {
        $xml = app('request')->input();
        if (empty($xml)) {
            throw new Exception(
                __('xml error')
            );
        }
        /**
         * 禁止引用外部xml实体
         */
        $disableLibxmlEntityLoader = libxml_disable_entity_loader(true);
        $args = Xml::specialDecode($xml);
        libxml_disable_entity_loader($disableLibxmlEntityLoader);
        Factory::log()
            ->info('WECHAT PAY CALLBACK: '.app('request')->input());
        if (!is_array($args)) {
            throw new Exception(
                __('xml error')
            );
        }
        if ($args['return_code'] != 'SUCCESS') {
            throw new Exception($args['return_msg']);
        }
        if (!$this->verify($args)) {
            throw new Exception(
                __('verify sign error')
            );
        }
        return $args;
    }
111658
public void delete(Object po) throws Exception{
		
		SqlParamsPairs sqlAndParams = ModelSqlUtils.getDeleteFromObject(po);
		//动态切换库名
		String sql = sqlAndParams.getSql();
		
		getProxy().update(sql, sqlAndParams.getParams());	
	}
1175100
public function add($key, $value)
    {
        if ($this->getReadOnly()) {
            throw new Exception('只读map，不允许执行添加操作', 100100603);
        }
        if (null === $key) {
            $this->_data[] = $value;
        } else {
            $this->_data[$key] = $value;
        }
    }
271962
public void start()
    throws Exception
  {
    if (_port < 0 && _unixPath == null) {
      return;
    }

    if (! _lifecycle.toStarting())
      return;

    boolean isValid = false;
    try {
      bind();
      postBind();

      enable();

      _acceptTask = new AcceptTcp(this, _serverSocket);
      _threadPool.execute(_acceptTask);

      // _connThreadPool.start();

      _suspendAlarm = new Alarm(new SuspendReaper());
      _suspendAlarm.runAfter(_suspendReaperTimeout);

      isValid = true;
    } finally {
      if (! isValid) {
        close();
      }
    }
  }
1265027
@Override
	public void run() {
		ThriftConnectionHandle<T> connection;
		long tmp;
		long nextCheckInMs = this.maxConnectionAge;

		int partitionSize = this.thriftConnectionPartition.getAvailableConnections();
		long currentTime = System.currentTimeMillis();
		for (int i = 0; i < partitionSize; i++) {
			try {
				connection = this.thriftConnectionPartition.poolFreeConnection();

				if (connection != null) {
					connection.setOriginatingPartition(this.thriftConnectionPartition);

					tmp = this.maxConnectionAge - (currentTime - connection.getConnectionCreationTimeInMs());

					if (tmp < nextCheckInMs) {
						nextCheckInMs = tmp;
					}

					// 判断连接是否过期
					if (connection.isExpired(currentTime)) {
						// 关闭连接
						closeConnection(connection);
						continue;
					}

					if (lifoMode == ServiceOrder.LIFO) {
						if (!(connection.getConnectionPartition().getFreeConnections().offer(connection))) {
							connection.internalClose();
						}
					} else {
						this.thriftConnectionPool.putConnectionBackInPartition(connection);
					}
					// 避免cpu使用率过高 进行一段时间休眠
					Thread.sleep(20L);
				}
			} catch (Throwable e) {
				logger.error("Connection max age thread exception.", e);
			}
		}

	}
737706
final public function begin()
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        if ($this->_begintransaction) {
            throw new Exception("已经开启了一个事务，请勿重新开启", Exception::CODE_DATABASE_ERROR);
        }
        $this->pdo->beginTransaction();
        $this->_begintransaction = true;
        return $this;
    }
1362905
public void start() throws IkasoaException {
		if (server == null) {
			log.debug("Server configuration : {}", configuration);
			// 不允许使用1024以内的端口.
			if (!ServerUtil.isSocketPort(serverPort))
				throw new IkasoaException(String.format(
						"Server initialize failed ! Port range must is 1025 ~ 65535 . Your port is : %d .",
						serverPort));
			try {
				initServer(getTransport());
			} catch (TTransportException e) {
				throw new IkasoaException("Server initialize failed !", e);
			}
		}
		// 如果服务没有启动,则自动启动服务.
		if (server != null) {
			if (server.isServing()) {
				log.info("Server already run .");
				return;
			}
			server.serve();
			log.info("Startup server ... (name : {} , port : {})", getServerName(), getServerPort());
		} else
			log.warn("Startup server failed !");
	}
224534
public function multiInit()
    {
        //domain > url
        $host = $this->env->get('HTTP_HOST');
        $apps = [];
        if (isset($this->multiApps[$host])) {
            $apps = $this->multiApps[$host];
        }
        $defapps = isset($this->multiApps['default']) ? $this->multiApps['default'] : [];
        if (!$apps && !$defapps) {
            throw new Exception("无法找到设置的初始化映射规则");
        }
        $app = null;
        $dir = null;
        $setting = [];
        $middleware = null;
        if ($apps) {
            $_apps = $this->getAppConfig($apps);
            if ($_apps) {
                list($app, $dir, $setting, $middleware) = $_apps;
            }
        } else {
            $_apps = $this->getAppConfig($defapps);
            if ($_apps) {
                list($app, $dir, $setting, $middleware) = $_apps;
            }
        }
        //开始处理新的路由
        if ($app === null) {
            if ($this->getConfig('debug')) {
                throw new Exception('无法找到请求的处理方法');
            } else {
                $this->route->notFound();
            }
        }
        $this->init($app, $dir, $setting, $middleware);
        //注册其他应用的自动加载
        foreach ($this->multiApps as $apps) {
            if (!$apps) {
                continue;
            }
            foreach ($apps as $_app) {
                list($appname, $_dir) = $_app;
                if ($app != $appname) {
                    $namespace = $appname;
                    $this->loader->addNamespace('\\' . $namespace, $_dir . '/' . $appname . '/');
                }
                $this->setInitApps($appname, $_dir);
            }
        }
        return $app;
    }
171719
public static void main(String[] args) throws Exception {

		
		CWSTagger cws = new CWSTagger("../models/seg.m");
		tag = new POSTagger(cws,"../models/pos.m");
		
		System.out.println("得到支持的词性标签集合");
		System.out.println(tag.getSupportedTags());
		System.out.println(tag.getSupportedTags().size());
		System.out.println("\n");
		
		String str = "媒体计算研究所成立了，高级数据挖掘很难。乐phone很好！";
		String s = tag.tag(str);
		System.out.println("处理未分词的句子");
		System.out.println(s);
		
		System.out.println("使用英文标签");
		tag.SetTagType("en");		
		System.out.println(tag.getSupportedTags());
		System.out.println(tag.getSupportedTags().size());
		s = tag.tag(str);
		System.out.println(s);		
		System.out.println();
		
		CWSTagger cws2 = new CWSTagger("../models/seg.m", new Dictionary("../models/dict.txt"));
		
		//bool值指定该dict是否用于cws分词（分词和词性可以使用不同的词典）
		tag = new POSTagger(cws2, "../models/pos.m"
				, new Dictionary("../models/dict.txt"), true);//true就替换了之前的dict.txt
		tag.removeDictionary(false);//不移除分词的词典
		tag.setDictionary(new Dictionary("../models/dict.txt"), false);//设置POS词典，分词使用原来设置
		
		String str2 = "媒体计算研究所成立了，高级数据挖掘很难。乐phone很好！";
		String s2 = tag.tag(str2);
		System.out.println("处理未分词的句子，使用词典");
		System.out.println(s2);
		System.out.println();
		
		Dictionary dict = new Dictionary();
		dict.add("媒体计算","mypos1","mypos2");
		dict.add("乐phone","专有名");
		tag.setDictionary(dict, true);
		String s22 = tag.tag(str2);
		System.out.println(s22);
		System.out.println();
		
		POSTagger tag1 = new POSTagger("../models/pos.m");
		String str1 = "媒体计算 研究所 成立 了 , 高级 数据挖掘 很 难";
		String[] w = str1.split(" ");
		String[] s1 = tag1.tagSeged(w);
		System.out.println("直接处理分好词的句子:++++++++++");
		for(int i=0;i<s1.length;i++){
			System.out.print(w[i]+"/"+s1[i]+" ");
		}
		System.out.println("\n");
		
		POSTagger tag3 = new POSTagger("../models/pos.m", new Dictionary("../models/dict.txt"));
		String str3 = "媒体计算 研究所 成立 了 , 高级 数据挖掘 很 难 ";
		String[] w3 = str3.split(" ");
		String[] s3 = tag3.tagSeged(w3);
		System.out.println("直接处理分好词的句子，使用词典");
		for(int i=0;i<s3.length;i++){
			System.out.print(w3[i]+"/"+s3[i]+" ");
		}
		System.out.println("\n");
		
		//????????????????????????????
		
		System.out.println("重新构造");
		cws = new CWSTagger("../models/seg.m");
		tag = new POSTagger(cws,"../models/pos.m");
		str = "媒体计算研究所成立了, 高级数据挖掘很难";
		System.out.println(tag.tag(str));
		String[][] sa = tag.tag2Array(str);
		for(int i = 0; i < sa.length; i++) {
			for(int j = 0; j < sa[i].length; j++) {
					System.out.print(sa[i][j] + " ");
			}
			System.out.println();
		}
		
		String s4 = tag.tagFile("../example-data/data-tag.txt");
		System.out.println("\n处理文件：");
		System.out.println(s4);
	}
273914
public void save(Object po) throws Exception {
		String autoGeneratedColumnName = IdUtils.getAutoGeneratedId(po);
		if(!"".equals(autoGeneratedColumnName)){
			//有自增字段
			int idValue = save(po, autoGeneratedColumnName);
			//把自增的主键值再设置回去
			IdUtils.setAutoIncreamentIdValue(po,autoGeneratedColumnName,idValue);
		}else{
			SqlParamsPairs sqlAndParams = ModelSqlUtils.getInsertFromObject(po);
			
			getProxy().update(sqlAndParams.getSql(), sqlAndParams.getParams());
		}		
	}
421872
public void init() throws Exception {
        userDir = new File(System.getProperty("user.dir")).getAbsolutePath();
        System.setProperty("user.dir", options.getExecutionDirectory().getAbsolutePath());

        if (!cfg.exists()) {

            ConfigurationManager manager = new ConfigurationManager(cfg, false, locateConfigurationProvider());

            try {

                manager.runProjectConfigurationInitializers();

                if (options.isVerbose()) {
                    log.info("CONFIGURATION FILE [" + cfg.getAbsolutePath() + "] CREATION COMPLETE");
                }

            } catch (IOException aux) {
                if (options.isVerbose()) {
                    log.error("The system can't create the file [ " + cfg.getAbsolutePath() + "]");
                }
                if (options.isThrowException()) {
                    System.setProperty("user.dir", userDir);
                    throw aux;
                }
            }

        } else {
            if (options.isVerbose()) {
                log.error("The configuration file [" + cfg.getAbsolutePath() + "] already exists");
            }
        }
        System.setProperty("user.dir", userDir);
    }
1191728
protected void doStop() throws Exception
    {
        MultiException mex=new MultiException();
        
        
        Thread thread= Thread.currentThread();
        ClassLoader lastContextLoader= thread.getContextClassLoader();
        
        try
        {
            // Context listeners
            if (_contextListeners != null)
            {
                if (_webAppHandler != null)
                {
                    ServletContextEvent event= new ServletContextEvent(getServletContext());
                    
                    for (int i= LazyList.size(_contextListeners); i-- > 0;)
                    {
                        try 
                        {
                            ((ServletContextListener)LazyList.get(_contextListeners, i)).contextDestroyed(event);
                        }
                        catch (Exception e)
                        {
                            mex.add(e);
                        }
                    }
                }
            }
            _contextListeners= null;
            
            // Stop the context
            try
            {
                super.doStop();
            }
            catch (Exception e)
            {
                mex.add(e);
            }
            
            // clean up
            clearSecurityConstraints();
            
            if (_webAppHandler != null)
                removeHandler(_webAppHandler);
            _webAppHandler= null;
            
            if (_errorPages != null)
                _errorPages.clear();
            _errorPages= null;
            
            _webApp=null;
            _webInf=null;
            
            _configurations=null;
            
        }
        finally
        {
            thread.setContextClassLoader(lastContextLoader);
        }
        
        if (mex!=null)
            mex.ifExceptionThrow();
    }