📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace textFCM
{
public partial class Form1 : Form
{
private Document doc;
private int check = 0;
public ArrayList id = new ArrayList();
public ArrayList Cos = new ArrayList();
public ArrayList Jaccard = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.CurrentDirectory;
openFileDialog.Filter = "文本文件|*.txt|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
this.label4.Visible = true;
this.Refresh();
string fName = openFileDialog.FileName;
doc = new Document(fName);
this.richTextBox1.Text = "已选择初始文本:" + fName.Substring(fName.LastIndexOf("\\") + 1);
}
check = 1;
this.label4.Visible = false;
this.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
if (check == 0)
{
this.richTextBox1.Text = "请选择初始文本!";
this.Refresh();
return;
}
ArrayList text = new ArrayList();
this.Invalidate();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.InitialDirectory = Environment.CurrentDirectory;
openFileDialog.Filter = "文本文件|*.txt|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
this.label4.Visible = true;
this.Refresh();
string[] fName = openFileDialog.FileNames;
for (int i = 0; i < fName.Length; i++)
{
Document doc0 = new Document(fName[i]);
double num1 = doc0.SimilitudeValueToDocumentUsingCos(doc, doc0);
double num2 = doc0.SimilitudeValueToDocumentUsingGeneralizedJaccardCoefficient(doc, doc0);
string sfNameT = fName[i].Substring(fName[i].LastIndexOf("\\") + 1);
id.Add(sfNameT);
Cos.Add(num1);
Jaccard.Add(num2);
text.Add(sfNameT + "\t" + Convert.ToString(num1) + "\t" + Convert.ToString(num2));
}
StringBuilder strBuild = new StringBuilder("");
for (int i = 0; i < text.Count; i++)
{
strBuild.Append(text[i].ToString() + "\n");
}
this.richTextBox1.Text = "文本\tCos\t\t\tJaccard\n" + strBuild.ToString();
this.label4.Visible = false;
this.Refresh();
}
}
private void button3_Click(object sender, EventArgs e)
{
int c = 2, m = 2, s = 4;//c聚类个数,m控制参数,s迭代次数
bool sim = true;
ArrayList text = new ArrayList();
try
{
c = Convert.ToInt32(this.textBox1.Text);
m = Convert.ToInt32(this.textBox3.Text);
s = Convert.ToInt32(this.textBox2.Text);
sim = this.radioButton1.Checked;
}
catch
{
this.richTextBox1.Text = "请填写参数!";
this.Refresh();
return;
}
this.Invalidate();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.InitialDirectory = Environment.CurrentDirectory;
openFileDialog.Filter = "文本文件|*.txt|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
this.label4.Visible = true;
this.Refresh();
string[] fName = openFileDialog.FileNames;
FCM fcm = new FCM();
this.richTextBox1.Text = fcm.FCMf(fName, c, m, s, sim);
this.label4.Visible = false;
this.Refresh();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -