Exemplo n.º 1
0
        public List <FinalNode1> AdjacentNodeList(String LaTeX)
        {
            AdjacentNode      adjacentNodes    = new AdjacentNode();
            List <FinalNode1> AdjacentNodeList = new List <FinalNode1>();//存放邻接节点有序对的集合
            LimAndSum         limandSums       = new LimAndSum();
            DuiJiaoXian       duijiaoxian      = new DuiJiaoXian();
            NciGenHao         nicigenHao       = new NciGenHao();
            DuiShu            duishu           = new DuiShu();
            int    biaozhi;
            String final;
            String cao;

            char[] caos;
            FuShu  fushu = new FuShu();

            biaozhi = 1;                       //每次循环前设置一个标志令标志等于1
            final   = "";                      //每次令final为空字符串,用来接收“特殊lim和sum表达式”还是“一般表达式”
            cao     = LaTeX.ToString().Trim(); //把数据库的数学表达式读出来,要开始判断了啊
            caos    = cao.ToCharArray();
            for (int i = 0; i < caos.Length; i++)
            {
                if (Convert.ToString(caos[i]).Equals("\\") && Convert.ToString(caos[i + 1]).Equals("l") && Convert.ToString(caos[i + 2]).Equals("i") && Convert.ToString(caos[i + 3]).Equals("m"))
                {
                    biaozhi = 0;
                    break;
                }
                else if (Convert.ToString(caos[i]).Equals("\\") && Convert.ToString(caos[i + 1]).Equals("s") && Convert.ToString(caos[i + 2]).Equals("u") && Convert.ToString(caos[i + 3]).Equals("m"))
                {
                    biaozhi = 0;
                    break;
                }
            }
            if (biaozhi == 0)//说明有lim这种的
            {
                final = limandSums.limAndSum(cao);
                final = fushu.fuShu(final);
                final = nicigenHao.NcigenHao(final);
                final = duishu.duiShu(final);
            }
            else
            {
                //下面这个是普通的和负号的
                final = fushu.fuShu(cao);
                final = nicigenHao.NcigenHao(final);
                final = duishu.duiShu(final);
            }
            //================================对于遇到含有lim和sum等特殊表达式的需要一段代码来特殊处理,如果不是这类表达式,那就不用处理,不过还有一些负号这类的===========================================
            AdjacentNodeList = adjacentNodes.AdjacentNodeList(final);

            return(AdjacentNodeList);
        }
Exemplo n.º 2
0
        public void Test2(String queryLaTeX)
        {
            StreamReader sr   = new StreamReader("C:\\Users\\dell\\Desktop\\暑假\\实验数据\\1.txt", Encoding.Default);
            String       read = sr.ReadLine();

            List <AAAAData> Final = new List <AAAAData>();

            while (read != null)
            {
                //获取子式
                ChildrenBTree children = new ChildrenBTree();
                Dictionary <int, List <FinalNode1> > aaa = new Dictionary <int, List <FinalNode1> >();
                aaa = children.childrenBTree(read);

                String strs = "";

                //Console.WriteLine("草拟吗:"+read);


                foreach (var aaaa in aaa)
                {
                    //每一个子式
                    String str = "";

                    foreach (var aaaaa in aaaa.Value)
                    {
                        str = str + aaaaa.zifu;
                    }



                    Dictionary <int, List <FinalNode1> > dics = new Dictionary <int, List <FinalNode1> >();
                    AAAA A = new AAAA();
                    dics = A.BTLevelScore(str, read);
                    if (dics == null || dics.Count == 0)
                    {
                        //Console.WriteLine("草擦曹操");
                        read = sr.ReadLine();
                        continue;
                    }
                    //下面这个是统计查询表达式a+b,在结果表达式a+b+c+a+b,的两个a+b的最小树的层次啊

                    foreach (var it in dics)
                    {
                        //Console.WriteLine("键值:" + it.Key);
                        int min = 10000;
                        foreach (var itt in it.Value)
                        {
                            if (itt.BTreeLevel < min)
                            {
                                min = itt.BTreeLevel;
                            }
                            //Console.WriteLine(itt.zifu+"\t"+itt.BTreeLevel);
                        }
                        strs = strs + min + "#";
                    }
                }


                //=============================
                //统计一下负数的那个,树的高度越高,它的负值越大,负的越厉害。注意现在统计的是结果表达式的最大高度,也就是read
                int fushu               = 0;
                int maxBTLevel          = 0;
                List <FinalNode1> lists = new List <FinalNode1>();
                AdjacentNode      aa    = new AdjacentNode();
                lists = aa.AdjacentNodeList(read);
                foreach (var it in lists)
                {
                    if (it.BTreeLevel > fushu)
                    {
                        fushu = it.BTreeLevel;
                    }
                }

                fushu = (-1) * fushu;
                strs  = strs + fushu + "#" + read;
                //Console.WriteLine(str);
                //已经得到一个查询表达式在结果表达式里面的层次级别了,开始计算分数了
                String[]   news = strs.Split('#');
                List <int> list = new List <int>();
                for (int i = 0; i < news.Length - 1; i++)
                {
                    list.Add(Convert.ToInt32(news[i]));
                    //Console.WriteLine("草:"+news[i]);
                }
                //开始排序
                int tempdata;
                for (int i = 0; i < list.Count - 1; i++)
                {
                    for (int j = i + 1; j < list.Count; j++)
                    {
                        if (list[j] < list[i])
                        {
                            tempdata = list[j];
                            list[j]  = list[i];
                            list[i]  = tempdata;
                        }
                    }
                }
                //开始利用公式计算
                double sum = 0;
                for (int i = 0; i < news.Length - 1; i++)
                {
                    sum = sum + Math.Abs(19 - (20 - Convert.ToDouble(news[i]))) / (19);
                    //Console.WriteLine("看看结果:"+sum);
                }
                sum = sum / (news.Length - 1);
                AAAAData d = new AAAAData();
                d.BTLevel = 1 - sum;
                d.str     = read;
                Final.Add(d);


                //=============================



                read = sr.ReadLine();
            }



            //开始排序
            AAAAData tempdatas;

            for (int i = 0; i < Final.Count - 1; i++)
            {
                for (int j = i + 1; j < Final.Count; j++)
                {
                    if (Final[j].BTLevel > Final[i].BTLevel)
                    {
                        tempdatas = Final[j];
                        Final[j]  = Final[i];
                        Final[i]  = tempdatas;
                    }
                }
            }
            foreach (var it in Final)
            {
                Console.WriteLine("公式为:" + it.str + "\t" + "相似度为:" + it.BTLevel);
            }
        }
Exemplo n.º 3
0
        public void WriteData()
        {
            //第一步:先把txt所有数学公式读入内存
            StreamReader   sr        = new StreamReader("C:\\Users\\Administrator\\Desktop\\最终版组合测试添加数据用来修改的\\最终版组合测试添加数据用来修改的\\14最终版组合测试模糊匹配有点毛病啊,已解决14\\第二个实验测试数据\\1.txt", Encoding.Default);
            StreamWriter   sw        = new StreamWriter("C:\\Users\\Administrator\\Desktop\\最终版组合测试添加数据用来修改的\\最终版组合测试添加数据用来修改的\\14最终版组合测试模糊匹配有点毛病啊,已解决14\\第二个实验测试数据\\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 == 1)
                //{
                //    break;

                //}
                //a++;

                List <FinalNode1> AdjacentNodeList = new List <FinalNode1>();
                AdjacentNode      ad = new AdjacentNode();
                AdjacentNodeList = ad.AdjacentNodeList(read);
                String str = null;


                //这个是每一个字符串
                //现在这个是中序遍历好的节点
                List <String> ji = new List <string>();
                foreach (var it in AdjacentNodeList)
                {
                    //第一:如果左右节点都为操作数
                    if (isOperator(it.zifu) && it.left != null && it.right != null && !isOperator(it.left.zifu) && !isOperator(it.right.zifu))
                    {
                        List <FinalNode1> nodeList = new List <FinalNode1>();
                        middleBianLi      zhongxu  = new middleBianLi(nodeList, it);
                        String            strr     = null;
                        foreach (var itt in nodeList)
                        {
                            strr = strr + itt.zifu;
                            //Console.WriteLine("链接为:"+itt.zifu);
                        }
                        //foreach (var itt in nodeList)
                        //{
                        //    if (isOperator(itt.zifu))
                        //    {
                        //        strr = strr + itt.BTreeLevel;
                        //    }
                        //}
                        ji.Add(strr);
                    }
                    //第二:如果左节点是操作数,右节点是操作符
                    if (isOperator(it.zifu) && it.left != null && it.right != null && !isOperator(it.left.zifu) && isOperator(it.right.zifu))
                    {
                        ji.Add(it.left.zifu /*+ it.left.BTreeLevel*/);
                        ji.Add(it.zifu /*+it.BTreeLevel*/);
                    }
                    //第三:如果左节点是操作符,右节点是操作数
                    if (isOperator(it.zifu) && it.left != null && it.right != null && isOperator(it.left.zifu) && !isOperator(it.right.zifu))
                    {
                        ji.Add(it.zifu /*+ it.BTreeLevel*/);
                        ji.Add(it.right.zifu /*+ it.right.BTreeLevel*/);
                    }
                    //第四:如果左右节点都是操作符
                    if (isOperator(it.zifu) && it.left != null && it.right != null && isOperator(it.left.zifu) && isOperator(it.right.zifu))
                    {
                        ji.Add(it.zifu /*+ it.BTreeLevel*/);
                    }
                    //第五:类似sina
                    if (isOperator(it.zifu) && it.left != null && it.right == null && !isOperator(it.left.zifu))
                    {
                        ji.Add(it.left.zifu + it.zifu);
                    }
                    //第六:类似sin(a+b)
                    if (isOperator(it.zifu) && it.left != null && it.right == null && isOperator(it.left.zifu))
                    {
                        ji.Add(it.zifu /*+ it.BTreeLevel*/);
                    }

                    //if (isOperator(it.zifu) && it.left!=null && it.right != null && !isOperator(it.left.zifu) && !isOperator(it.right.zifu))
                    //{
                    //    //如果该字符是运算符且左右节点都是运算数,说明它是个子树
                    //    //把中序遍历好的每一个节点存入集合当中
                    //    //Console.WriteLine("哈哈哈:"+it.zifu);
                    //    List<FinalNode1> nodeList = new List<FinalNode1>();
                    //    middleBianLi zhongxu = new middleBianLi(nodeList, it);
                    //    String strr = null;
                    //    foreach (var itt in nodeList)
                    //    {
                    //        strr = strr + itt.zifu;
                    //        //Console.WriteLine("链接为:"+itt.zifu);
                    //    }
                    //    foreach (var itt in nodeList)
                    //    {
                    //        if (isOperator(itt.zifu))
                    //        {
                    //            strr = strr + itt.BTreeLevel;
                    //        }
                    //    }
                    //    ji.Add(strr);
                    //}
                    //else if (it.left != null && it.right != null && isOperator(it.left.zifu) && !isOperator(it.right.zifu))
                    //{
                    //    ji.Add(it.zifu+it.BTreeLevel);
                    //    ji.Add(it.right.zifu+it.right.BTreeLevel);
                    //}
                    //else if (it.left != null && it.right != null && !isOperator(it.left.zifu) && isOperator(it.right.zifu))
                    //{
                    //    ji.Add(it.left.zifu+ it.left.BTreeLevel);
                    //    ji.Add(it.zifu+it.BTreeLevel);
                    //}
                }

                foreach (var itt in ji)
                {
                    str = str + itt + "#";
                }

                str = str + read;
                sw.WriteLine(str);
                //Console.WriteLine("草泥马了:" + str);
                //Console.WriteLine("==============================");



                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();
        }