예제 #1
0
int main(int argc, char *argv[])
{
	string strtmp; //用于保存从语料库中读入的每一行
	string line; //用于输出每一行的结果

	ifstream infile(argv[1]); // 打开输入文件
	if (!infile.is_open()) // 打开输入文件失败则退出程序
	{
		cerr << "Unable to open input file: " << argv[1] << " -- bailing out!" << endl;
		exit(-1);
	}

	ofstream outfile1("SegmentResult.txt"); //确定输出文件 
	if (!outfile1.is_open())
	{
		cerr << "Unable to open file:SegmentResult.txt" << "--bailing out!" << endl;
		exit(-1);
	}

	while (getline(infile, strtmp))    //读入语料库中的每一行并用最大匹配法处理 
	{
		line = strtmp;
		line = SegmentSentenceMM(line); // 调用分词函数进行分词处理 
		outfile1 << line << endl; // 将分词结果写入目标文件 
	}

	return 0;
}
예제 #2
0
void ExtractMatchingPairs(
    const char* model_file,
    const char* scene_file,
    const T& threshold,
    const char* extracted_model_file,
    const char* extracted_scene_file) {

  std::ifstream infile1(model_file);
  vnl_matrix<T> model;
  model.read_ascii(infile1);

  std::ifstream infile2(scene_file);
  vnl_matrix<T> scene;
  scene.read_ascii(infile2);

  vnl_matrix<T> extracted_model, extracted_scene;
  ExtractMatchingPairs<T>(
      model, scene, threshold, extracted_model, extracted_scene);

  std::ofstream outfile1(extracted_model_file, std::ios_base::out);
  extracted_model.print(outfile1);

  std::ofstream outfile2(extracted_scene_file, std::ios_base::out);
  extracted_scene.print(outfile2);
}
예제 #3
0
bool MovieStore::saveAccounts(string custFile, string transFile) {
	bool success;

	ofstream outfile1(custFile.c_str(), ios::out | ios::trunc);
	if (!outfile1) {
		cout << "Customers file could not be opened." << endl;
		return false;
	}

	ofstream outfile2(transFile.c_str(), ios::out | ios::app);
	if (!outfile2) {
		cout << "Transactions file could not be opened." << endl;
		return false;
	}

	//outfile << "testing 456" << endl;
	success = custList->saveCusts(outfile1, outfile2);
	outfile1.close();
	outfile2.close();
	return success;
}
예제 #4
0
void g( const char* model_file,
    const char* scene_file,
    double threshold,
    const char* extracted_model_file,
    const char* extracted_scene_file) {

  std::ifstream infile1(model_file);
  vnl_matrix<double> model;
  model.read_ascii(infile1);

  std::ifstream infile2(scene_file);
  vnl_matrix<double> scene;
  scene.read_ascii(infile2);

  vnl_matrix<double> extracted_model, extracted_scene;
  f(model, scene, threshold, extracted_model, extracted_scene);

  std::ofstream outfile1(extracted_model_file, std::ios_base::out);
  extracted_model.print(outfile1);

  std::ofstream outfile2(extracted_scene_file, std::ios_base::out);
  extracted_scene.print(outfile2);
}
예제 #5
0
bool Utc::read_data()
{
qDebug() << "begin read_data()";	
	QFile inp("data.tex");
	if (!inp.open(QFile::ReadOnly))
	{
qDebug() << "ERROR 1!";
		return false;		
	}
	QTextStream text(&inp);

	QFile outfile("data_result.txt");
//	outfile.open(QIODevice::WriteOnly);
	if (!outfile.open(QFile::WriteOnly))
	{
qDebug() << "ERROR 2!";
		return false;		
	}
	QTextStream out(&outfile);
	out.setCodec("UTF-8");

	QFile outfile1("data_result1.txt");
//	outfile.open(QIODevice::WriteOnly);
	if (!outfile1.open(QFile::WriteOnly))
	{
qDebug() << "ERROR 2!";
		return false;		
	}
	QTextStream out1(&outfile1);
	out1.setCodec("UTF-8");
	int q_number = 0, a_number = -1;;

	QVector<BaseAns> ans;
	while (!text.atEnd())
	{
		QString line = text.readLine();
		if (line.isEmpty() || line[0] != '%') out << line << endl;
qDebug() << "--------- new line";
qDebug() << line;
		if ("%%%%% " == line.left(6))
		{
			ans.clear();
			q_number++;
			a_number = -1;
		}
		else if ("%%% " == line.left(4))
		{
			BaseAns a;
//%%% 2 2172-1-0; 2179-2-3;  %%%			
			QStringList qst0 = line.split(" ");
			int i = qst0[1].toInt();
			a_number++;
			for (int j = 0; j < i; j++)
			{
//2172-1-0;	
				QStringList qst1 = qst0[2 + j].split('-');
				qst1[2] = qst1[2].remove(qst1[2].size() - 1);
				int testID = qst1[0].toInt();
				if (all_tests[testID].points > 0)
				{
					int k = 
				all_tests[testID].q[qst1[1].toInt()].ans_student[qst1[2].toInt()];
					a.total++;
					if (k == 1) a.correct++;
					else if (k == 2) a.incorrect++;
qDebug() << " all : " << a.total << a.correct << a.incorrect;  	
// ep = total*(ui.exam_max->value())/num_questions/4.0;
					if (all_tests[testID].points*(ui.exam_max->
								value())/num_questions/4.0 >= 5) //????????????????
					{
						a.total1++;
						if (k == 1) a.correct1++;
						else if (k == 2) a.incorrect1++;
qDebug() << " >=5 : " << a.total1 << a.correct1 << a.incorrect1;  				
					}
				}
			}
			a.text = text.readLine();
			out << a.text << " % " << a.total << ":" <<  a.total - a.correct - a.incorrect << ":" << a.correct << ":" << a.incorrect 
				<< "  " << a.total1 << ":" << a.total1 - a.correct1 - a.incorrect1 << ":" << a.correct1 << ":" << a.incorrect1 << endl;
			out1 << q_number << " " << static_cast<char>('a' + a_number) << " " 
				<< a.total << " " << a.total - a.correct - a.incorrect << " " << a.correct << " " << a.incorrect << " " 
				<< a.total1 << " " << a.total1 - a.correct1 - a.incorrect1 << " " << a.correct1 << " " << a.incorrect1 
				<< endl;
qDebug() << a.text;
			ans.push_back(a);
		}		
	}
	inp.close();
	outfile.close();
	outfile1.close();
qDebug() << "end read_data()";	
	return true;
}