Example #1
0
        public List <String> Read(String queryLaTeX)
        {
            StreamReader   sr   = new StreamReader("C:\\Users\\Administrator\\Desktop\\第二篇论文实验读写数据库\\2.txt", Encoding.Default);
            List <AAIndex> list = new List <AAIndex>();
            String         read = sr.ReadLine();

            //int a = 0;
            while (read != null)
            {
                //a++;
                //if (a == 6742)
                //    break;
                String[] re    = read.Split('#');
                AAIndex  index = new AAIndex();
                index.zishi = re[0];
                //Console.WriteLine("txt文件中子式为:"+re[0]);
                index.zishiStructure = re[1];
                index.LaTeX          = re[2];

                list.Add(index);
                // Console.WriteLine(re[2]);
                read = sr.ReadLine();
            }

            System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
            stop.Start();//开始监视代码运行时间

            //现在相当于当成数据库了,这个list存储着属性为子式、子式结构和数学公式的集合
            Dictionary <int, List <FinalNode1> > children = new Dictionary <int, List <FinalNode1> >();
            ChildrenBTree childrenBTree = new ChildrenBTree();

            children = childrenBTree.childrenBTree(queryLaTeX);

            //用一个集合存储最终查询后的结果表达式的集合
            List <String> resultList = new List <String>();

            //这个是获取一个LaTeX的每一个子式
            foreach (var it in children)
            {
                //定义每一个子式
                String zishi = "";
                foreach (var itt in it.Value)
                {
                    zishi = zishi + itt.zifu;
                }
                //Console.WriteLine("AARead.cs:"+zishi);
                //先查询包含子式的集合
                foreach (var itts in list.Where(p => p.zishi.Equals(zishi)).ToList())
                {
                    //Console.WriteLine(itts.LaTeX);
                    resultList.Add(itts.LaTeX);
                }
            }

            //foreach (var it in resultList)
            //{
            //    Console.WriteLine("草泥马有没有啊:"+it);

            //}


            //这个是获取一个LaTeX的每一个子式结构
            foreach (var it in children)
            {
                //定义每一个子式结构
                String zishiStructure = "";
                foreach (var itt in it.Value)
                {
                    if (isSpecialYunSuanShu(itt.zifu))
                    {
                    }
                    else
                    {
                        zishiStructure = zishiStructure + itt.zifu;
                    }
                }

                //Console.WriteLine("AARead.cs:" + zishiStructure);
                if (zishiStructure.Equals(""))
                {
                    continue;
                }

                //先查询包含子式的集合
                foreach (var itts in list.Where(p => p.zishiStructure.Equals(zishiStructure)).ToList())
                {
                    resultList.Add(itts.LaTeX);
                }
            }
            stop.Stop();                                        //代码结束时间
            TimeSpan timespan     = stop.Elapsed;
            double   milliseconds = timespan.TotalMilliseconds; //总毫秒

            //Console.WriteLine("查询所得数学表达式时间为:" + milliseconds + "毫秒");
            return(resultList);
        }
Example #2
0
        //这个方法是把数据写入txt文件,到时候写入SQLServer里面,因为我现在没有内存下载数据库了
        public void Write()
        {
            //先测试一下
            //StreamReader sr = new StreamReader("C:\\Users\\Administrator\\Desktop\\最终版组合测试添加数据用来修改的\\最终版组合测试添加数据用来修改的\\测试建索引\\1.txt", Encoding.Default);
            //StreamWriter sw = new StreamWriter("C:\\Users\\Administrator\\Desktop\\最终版组合测试添加数据用来修改的\\最终版组合测试添加数据用来修改的\\测试建索引\\2.txt");

            //第一步:先把txt所有数学公式读入内存
            StreamReader sr = new StreamReader("C:\\Users\\Administrator\\Desktop\\最终版组合测试添加数据用来修改的\\最终版组合测试添加数据用来修改的\\14最终版组合测试模糊匹配有点毛病啊,已解决14\\第二个实验测试数据\\1.txt", Encoding.Default);
            StreamWriter sw = new StreamWriter("C:\\Users\\Administrator\\Desktop\\第二篇论文实验读写数据库\\2.txt");

            List <AAIndex> indexList = new List <AAIndex>();

            DuiShu duishu = new DuiShu();
            FuShu  fuShu  = new FuShu();
            String read   = sr.ReadLine();

            read = duishu.duiShu(read);
            read = fuShu.fuShu(read);

            int a = 0;


            while (read != null)
            {
                //if (a == 100)
                //{
                //    break;

                //}
                //a++;
                //先读每一个数学公式,然后把每一个数学公式的子式、子式结构和该数学公式提取出即可

                //Console.WriteLine(read);
                Dictionary <int, List <FinalNode1> > children = new Dictionary <int, List <FinalNode1> >();
                ChildrenBTree childrenBTree = new ChildrenBTree();
                children = childrenBTree.childrenBTree(read);

                //这个是获取一个LaTeX的每一个子式
                foreach (var it in children)
                {
                    //定义每一个子式
                    String zishi = "";

                    //定义每一个子式结构
                    String zishiStructure = "";

                    foreach (var itt in it.Value)
                    {
                        zishi = zishi + itt.zifu;

                        if (isSpecialYunSuanShu(itt.zifu))
                        {
                        }
                        else
                        {
                            zishiStructure = zishiStructure + itt.zifu;
                        }
                    }
                    //Console.WriteLine("子式:" + zishi);
                    AAIndex index = new AAIndex();
                    index.zishi          = zishi;
                    index.zishiStructure = zishiStructure;
                    index.LaTeX          = read;

                    indexList.Add(index);
                }



                read = sr.ReadLine();
                if (read == null)
                {
                    break;
                }
                read = duishu.duiShu(read);
                read = fuShu.fuShu(read);
            }
            //Console.WriteLine("哪出bug了:===============");
            //开始写了
            foreach (var it in indexList)
            {
                if (it.zishiStructure.Equals(""))
                {
                    sw.WriteLine(it.zishi + "#" + " " + "#" + it.LaTeX + "#" + it.xuhao);
                }
                else
                {
                    sw.WriteLine(it.zishi + "#" + it.zishiStructure + "#" + it.LaTeX + "#" + it.xuhao);
                }
            }
            sw.Flush();
        }