📄 adjustmodel.java~28~
字号:
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2001 Chieu Hai Leong and Jason Baldridge
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////////////
import opennlp.maxent.*;
import opennlp.maxent.io.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
/**
* Adjust parameters of the model
*
* @author Si Guangtao
*/
public class AdjustModel {
MaxentModel _model;
ContextGenerator _cg = new BasicContextGenerator();
/** 主函数调用方法
* Main method. Call as follows:
* <p>
* java AdjustModel modelFile
*/
public static void main(String[] args) {
String modelFileName = "mailsModel.txt";
int mode;
double step;
Predicate pred2Adjust = new Predicate();
if (args.length > 0) {
pred2Adjust.word = args[0]; // 要修改的特征词
if (args[1].equals(""))
mode = 1;
else
mode = Integer.parseInt(args[1]);
if (args.length)
step = 1.0;
else
step = Double.parseDouble(args[2]);
}
else{
System.out.println("Invalid pred2Adjust!");
return;
}
try { // 从模型文件获得最大熵模型
GISModel model =new SuffixSensitiveGISModelReader(new File(modelFileName)).getModel();
model.AdjustMailModel(pred2Adjust, mode, step);
File outputFile = new File(modelFileName);
GISModelWriter writer = new SuffixSensitiveGISModelWriter(model, outputFile);
writer.persist();
System.out.print("\nModel has been adjusted!\n");
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -