Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何建立单词表_C#_Large Data Volumes - Fatal编程技术网

C# 如何建立单词表

C# 如何建立单词表,c#,large-data-volumes,C#,Large Data Volumes,所以现在我想制作一个爱沙尼亚单词列表,大约2000万个小写单词。要获取wordlist的输入,可以使用。语料库文件采用文本编码倡议(TEI)格式。我试着用正则表达式来查找单词 这就是我所做的:它效率低下,mcv乱七八糟,如果单词的哈希集无法放入内存,它会刹车,它不知道输入编码——所以像š这样的字母可能会出现问题,它不会显示估计的完成时间,一些控件有默认名称,而一些没有,它不会使用多任务处理(不确定是否应该),它使用了一些奇怪的修复程序和大量的锁定界面,这样看起来就不会“冻结”。至少它很短,你几乎

所以现在我想制作一个爱沙尼亚单词列表,大约2000万个小写单词。要获取wordlist的输入,可以使用。语料库文件采用文本编码倡议(TEI)格式。我试着用正则表达式来查找单词

这就是我所做的:它效率低下,mcv乱七八糟,如果单词的哈希集无法放入内存,它会刹车,它不知道输入编码——所以像š这样的字母可能会出现问题,它不会显示估计的完成时间,一些控件有默认名称,而一些没有,它不会使用多任务处理(不确定是否应该),它使用了一些奇怪的修复程序和大量的锁定界面,这样看起来就不会“冻结”。至少它很短,你几乎没有注意到没有评论

优点是,它几乎可以从.tei、.txt、.csv、smgl、xhtml或任何类似格式的输入中读取单词而不会出现很多错误

现在你知道我想做什么了,我是如何尝试去做的(有什么问题),我只是想知道如何去做(用最少的体力劳动)

图像示例:

代码示例&:

使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用System.Data.SqlClient;
使用System.IO;
使用System.Text.RegularExpressions;
名称空间读取器
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有无效列表视图1_DragEnter(对象发送方,DragEventArgs e)
{
if(例如,Data.GetDataPresent(DataFormats.FileDrop,false)=true)
{
e、 效果=DragDropEffects.All;
}  
}
私有无效列表视图1_DragDrop(对象发送方,DragEventArgs e)
{
塞吉洛克(真);
this.loading.Visible=true;
ignorechecking=true;
string[]files=(string[])e.Data.GetData(DataFormats.FileDrop,false);
Dictionary listviewgroups=新建字典();
int filenamesi=0;
foreach(文件中的字符串文件)
{
progresslabel.Text=string.Format(“进度:\t[{0}/{1}]”,filenamesi++,files.Length);
Application.DoEvents();
如果(File.Exists(File))
{
FileInfo ff=new System.IO.FileInfo(文件);
如果(!listviewgroups.ContainsKey(ff.DirectoryName))
{
添加(ff.DirectoryName,新ListViewGroup(ff.DirectoryName,HorizontalAlignment.Left));
添加(listviewgroups[ff.DirectoryName]);
}
ListViewItem项目=新的ListViewItem(ff.Name);
listviewgroups[ff.DirectoryName].Items.Add(item);
item.Checked=true;
item.SubItems.Add(“+((int)ff.Length/1024)+”KB”);
//item.Group.Header=ff.DirectoryName;
//listviewgroups[ff.DirectoryName].Items.Add(item);
listView1.Items.Add(项目);
}
}
塞吉洛克(假);
忽略检查=错误;
this.loading.Visible=false;
updatechecked();
}
私有无效列表视图1_ItemChecked(对象发送方,ItemCheckedEventArgs e)
{
updatechecked();
}
私有布尔ignorechecking=false;
私有void updatechecked(){
如果(忽略检查)
返回;
长尺寸=0;
整数计数=0;
foreach(此.listView1.Items中的ListViewItem项)
{
如果(选中项)
{
计数++;
size+=Int32.Parse(item.SubItems[1].Text.Split(“.ToArray())[0]);
}
}
this.text1.Text=”“+计数;
this.text2.Text=“”+大小+“KB”;
}
私有void putHashset(HashSet d,字符串文件名)
{
StringBuilder sb=新的StringBuilder();
foreach(d中的字符串键)
sb.Append(key.Append(“\n”);
writealText(文件名,sb.ToString());
}
私有HashSet getHashset(字符串文件名)
{
返回新的HashSet(新的Regex(“\\n+”).Split(File.ReadAllText(filename));
}
private void removefilefromlistview(字符串fullfilename){
foreach(此.listView1.Items中的ListViewItem项)
{
字符串文件=item.Group.Header+“\\”+item.SubItems[0]。文本;
if(fullfilename.CompareTo(文件)==0)
{
item.Checked=false;
this.listView1.Items.Remove(item);
}
}
}
私有void启动器(对象发送方、事件参数)
{
HashSet filenames=新的HashSet();
StringBuilder数据=null;
塞吉洛克(真);
this.time2.Text=“”;
this.time1.Text=String.Format(“{0:d/M/yyyy HH:mm:ss}”,DateTime.Now);
foreach(此.listView1.Items中的ListViewItem项){
如果(选中项){
字符串文件=item.Group.Header+“\\”+item.SubItems[0]。文本;
如果(File.Exists(File))
文件名。添加(文件);
}
}
字符串outputfile=output.Text;
HashSet单词=null;
if(File.Exists(output.Text))
words=getHashset(outputfile);
其他的
words=新HashSet();
int filenamesnr=filenames.Count;
int filenamesi=0;
foreach(文件名中的字符串str){
progresslabel.Text=string.Format(“进度:\t[{0}/{1}]”,文件名
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;

namespace Reader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
            {
                e.Effect = DragDropEffects.All;
            }  
        }

        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            setguiLock(true);
            this.loading.Visible = true;
            ignorechecking = true;
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            Dictionary<String, ListViewGroup> listviewgroups = new Dictionary<string,ListViewGroup>();

            int filenamesi = 0;

            foreach (string file in files)
            {
                progresslabel.Text = string.Format("Progress: \t[ {0} / {1} ]", filenamesi++, files.Length);
                Application.DoEvents();
               if (File.Exists(file))
                {
                    FileInfo ff = new System.IO.FileInfo(file);
                    if (!listviewgroups.ContainsKey(ff.DirectoryName))
                    {
                        listviewgroups.Add(ff.DirectoryName, new ListViewGroup(ff.DirectoryName, HorizontalAlignment.Left));
                        listView1.Groups.Add(listviewgroups[ff.DirectoryName]);
                    }
                    ListViewItem item = new ListViewItem(ff.Name);
                    listviewgroups[ff.DirectoryName].Items.Add(item);
                    item.Checked = true;

                    item.SubItems.Add("" +((int)ff.Length/1024)+" KB");

                  //  item.Group.Header = ff.DirectoryName;
                  //  listviewgroups[ff.DirectoryName].Items.Add(item);
                    listView1.Items.Add(item);
               }
            }
            setguiLock(false);
            ignorechecking = false;
            this.loading.Visible = false;
            updatechecked();
        }

        private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            updatechecked();
        }
        private bool ignorechecking = false;
        private void updatechecked(){
            if (ignorechecking)
                return;
            long size = 0;
            int count = 0;
            foreach (ListViewItem item in this.listView1.Items)
            {
                if (item.Checked)
                {
                    count++;
                    size += Int32.Parse(item.SubItems[1].Text.Split(" ".ToArray())[0]); 
                }
            }
            this.text1.Text = ""+count;
            this.text2.Text = ""+size + " KB";
        }
        private void putHashset(HashSet<string> d, string filename)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string key in d) 
                sb.Append(key).Append("\n");

            File.WriteAllText(filename, sb.ToString());
        }
        private HashSet<string> getHashset(string filename)
        {
            return new HashSet<string>(new Regex("\\n+").Split(File.ReadAllText(filename)));
        }

        private void removefilefromlistview(string fullfilename) {
            foreach (ListViewItem item in this.listView1.Items)
            {
                String file = item.Group.Header + "\\" + item.SubItems[0].Text;
                if (fullfilename.CompareTo(file) == 0)
                {
                    item.Checked = false;
                    this.listView1.Items.Remove(item);
                }
            }
        }
        private void starter(object sender, EventArgs e)
        {
            HashSet<string> filenames = new HashSet<string>();
            StringBuilder data = null;

            setguiLock(true);
            this.time2.Text = "";
            this.time1.Text = String.Format("{0:d/M/yyyy HH:mm:ss}", DateTime.Now);

            foreach (ListViewItem item in this.listView1.Items) {
                if (item.Checked) {
                    String file = item.Group.Header + "\\" + item.SubItems[0].Text;
                    if (File.Exists(file))
                        filenames.Add(file);
                }
            }

            string outputfile = output.Text;
            HashSet<string> words = null;
            if (File.Exists(output.Text))
                words = getHashset(outputfile);
            else
                words = new HashSet<string>();

            int filenamesnr = filenames.Count;
            int filenamesi = 0;
            foreach (String str in filenames){
                progresslabel.Text = string.Format("Progress: \t[ {0} / {1} ]", filenamesi++, filenamesnr);
                Application.DoEvents();
                data = new StringBuilder(System.IO.File.ReadAllText(str, Encoding.UTF7).ToLower());

                data = data.Replace("&auml;", "ä");
                data = data.Replace("&ouml;", "ö");
                data = data.Replace("&uuml;", "ü");
                data = data.Replace("&otilde;", "õ");

                String sdata = new Regex(@"<(.|\n)*?>|%[a-zA-Z0-9]+?;|&[#a-zA-Z0-9]+?;").Replace(data.ToString(), "");

                foreach (string word in new Regex("[^A-Za-zšžõäöüŠŽÕÄÖÜ]+").Split(sdata))
                    if(word.Length>1)
                            words.Add(word);

                removefilefromlistview(str);
            }
            progresslabel.Text = "Progress:";
            putHashset(words, outputfile);

            foreach (ListViewItem item in this.listView1.Items)
                if (item.Checked)
                {
                    item.Checked = false;
                    listView1.Items.Remove(item);
                }

            this.time2.Text = String.Format("{0:d/M/yyyy HH:mm:ss}", DateTime.Now);
            setguiLock(false);
        }

        private void setguiLock(bool value){
            if(value){
                this.Enabled = false;
                this.button1.Enabled = false;
                this.listView1.Enabled = false;
                this.output.Enabled = false;
                this.openoutput.Enabled = false;
                this.progresslabel.Visible = true;
                this.Enabled = true;
            }else{
                this.Enabled = false;
                this.openoutput.Enabled = true;
                this.output.Enabled = true;
                this.listView1.Enabled = true;
                this.button1.Enabled = true;
                this.progresslabel.Visible = false;
                this.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (!File.Exists(output.Text))
                   File.WriteAllText(output.Text, " ");
            System.Diagnostics.Process.Start(output.Text);
        }
    }
}