ClassModelBuilder.cs
上传用户:zhangkuixh
上传日期:2013-09-30
资源大小:5473k
文件大小:327k
源码类别:

搜索引擎

开发平台:

C#

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Data.SqlClient;
  7. using System.Threading;
  8. using System.Net;
  9. /*
  10.       '       迅龙中文分类搜索引擎  v0.6
  11.       '
  12.       '        LGPL  许可发行
  13.       '
  14.       '       宁夏大学  张冬 康彩  zd4004@163.com
  15.       ' 
  16.       '        官网 http://blog.163.com/zd4004/
  17.  */
  18. namespace XunLong.ModelBuilder
  19. {
  20.     /// <summary>
  21.     /// 建立模板
  22.     /// </summary>
  23.     public class ClassModelBuilder
  24.     {
  25.         private static Random raV = new Random();
  26.         /// <summary>
  27.         /// 取出的匹配字符串是否满足要求
  28.         /// </summary>
  29.         /// <param name="data"></param>
  30.         /// <returns>包含 且 《》成对 </returns>
  31.         private bool xStrItOK(string data)
  32.         {
  33.             if ((data.IndexOf("<") == -1) || (data.IndexOf(">") == -1) || (inStrNum(data, "<") != inStrNum(data, ">")))
  34.             {
  35.                 return false;
  36.             }
  37.             return false;
  38.         }
  39.         /// <summary>
  40.         /// 某个字符在串中的个数
  41.         /// </summary>
  42.         /// <param name="data"></param>
  43.         /// <returns></returns>
  44.         public  int inStrNum(string data, string one)
  45.         {
  46.             string c = data.Replace(one, "");
  47.             int cx = data.Length - c.Length;
  48.             return cx;
  49.         }
  50.         /// <summary>
  51.         /// 改变数据 <ZDKC0>" + data1 + "</ZDKC0> 在标题改变  以便标题栏能在完全相同时被识别 
  52.         /// 那么 0 位置就肯定为标题兰
  53.         /// </summary>
  54.         /// <param name="data"></param>
  55.         /// <returns></returns>
  56.         private static string RW_HTMLDB(string data)
  57.         {
  58.             int a1 = data.IndexOf("<ZDKC0>");
  59.             int a2 = data.IndexOf("</ZDKC0>");
  60.             int a3 = data.IndexOf("<ZDbody>");
  61.             int a4 = data.IndexOf("</ZDbody>");
  62.             int a5 = data.IndexOf(">", a3 + 1);
  63.             string data1 = "";
  64.             string data2 = "";
  65.             
  66.                int nowTitle = raV.Next( 25,984562);
  67.             try
  68.             {
  69.                 if (a1 > 0 & a2 > 0 & a2 > a1)
  70.                 {
  71.                     data1 = data.Substring(a1 + 7, a2 - a1 - 7);
  72.                 }
  73.                 if (a3 > 0 & a5 > 0 & a5 > a3)
  74.                 {
  75.                     data2 = data.Substring(a5 + 1, a4 - a5 - 1);
  76.                 }
  77.                 data1 = data1.Replace("*", "#");
  78.                 data2 = data2.Replace("*", "#");
  79.                 return " <ZDKC0>" + nowTitle.ToString()+"_"+data1.Length.ToString() + "</ZDKC0> <ZDbody>" + data2 + "</ZDbody>";
  80.             }
  81.             catch
  82.             {
  83.                 return " <ZDKC0>" + nowTitle.ToString() + "_" + data.Length.ToString() + "</ZDKC0> <ZDbody>" + data + "</ZDbody> ";
  84.             }
  85.         }
  86.         /// <summary>
  87.         /// 根据数据建立一个网页模板
  88.         /// </summary>
  89.         /// <param name="mHTMs"></param>
  90.         /// <returns></returns>
  91.         public  string BuilderModel(Hashtable mHTMs2)
  92.         {
  93.             Hashtable mHTMs = new Hashtable();
  94.             mHTMs.Clear();
  95.             foreach (System.Collections.DictionaryEntry de in mHTMs2)
  96.             {
  97.                 //原始的数据需要修改以便可以在标题相同的情况 下识别标题
  98.                 string NewHTM = RW_HTMLDB(de.Value.ToString());
  99.                 mHTMs.Add(de.Key, NewHTM);
  100.             }
  101.             Console.Write("..");
  102.             //得到最短的串
  103.             string oneModel = "";
  104.             
  105.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  106.             {
  107.                 if (oneModel.Length == 0)
  108.                 {
  109.                     oneModel = de.Value.ToString();
  110.                 }
  111.                 else
  112.                 {
  113.                     if (oneModel.Length > de.Value.ToString().Length)
  114.                     {
  115.                         oneModel = de.Value.ToString();
  116.                     }               
  117.                 }
  118.             }
  119.             //得到匹配临时模板的原始长度
  120.             int onemLong = oneModel.Length; 
  121.             Hashtable tdict = new Hashtable();
  122.             int tdictI = 0; //字典序号
  123.             tdict.Clear();
  124.             Hashtable oneModels = new Hashtable();
  125.             oneModels.Clear();
  126.             oneModels.Add(oneModel,"0");  //碎片如果相同 就不用继续寻找添加     
  127.            //存放临时碎片
  128.             Hashtable newModels = new Hashtable();
  129.             newModels.Clear();
  130.             oneModel = "";
  131.             NewStart: //开始遍历匹配串
  132.             if (oneModel.Length > 0)
  133.             {
  134.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  135.             }
  136.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  137.             {
  138.                 if (oneModels.Contains(de.Key) == false)
  139.                 {
  140.                     oneModels.Add(de.Key, "0");
  141.                 }
  142.             }
  143.             newModels.Clear();
  144.             foreach (System.Collections.DictionaryEntry de in oneModels)
  145.             {
  146.                 oneModel =de.Key.ToString();
  147.                 char[] oneModel_ss = oneModel.ToCharArray();
  148.                 if (oneModel.Length > 4)
  149.                 {
  150.                     
  151.                     int h = oneModel.Length;
  152.                     if ((5 * h>onemLong)&(onemLong>9000))
  153.                     {
  154.                         h = onemLong/5;
  155.                     }
  156.                     if (h > 512)
  157.                     {
  158.                         h = 512;
  159.                     }
  160.                     while (true)
  161.                     {
  162.                         if (h < 4)         //最短字符不能小于5  >=四
  163.                         { goto nextcmd2; }
  164.                         int st = 0;
  165.                         while (true)
  166.                         {
  167.                             if (st + h > oneModel.Length)
  168.                             { goto nextcmd1; }
  169.                             ///////**********************************************
  170.                           //  string a1= oneModel.Substring(st, 1);
  171.                          //   string a2= oneModel.Substring(st+h-1, 1);
  172.                             ////////////*****************************************
  173.                             char a1 = oneModel_ss[st];
  174.                           
  175.                             if ( a1!= '<')   //判断是否合法 含有 <  >
  176.                             {
  177.                                 goto nextcmd3;
  178.                             }
  179.                             char a2 = oneModel_ss[st + h - 1];
  180.                             if(a2 != '>')   //判断是否合法 含有 <  >
  181.                             {
  182.                                 goto nextcmd3;
  183.                             }
  184.                             string onestr = oneModel.Substring(st, h);
  185.                         //    if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  186.                          //   {
  187.                          //       goto nextcmd3;         //取开头和末尾在<>中的数据
  188.                          //   }
  189.                             //遍历数据  是否符合全部数据
  190.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  191.                             {
  192.                                // if ((de1.Value.ToString().IndexOf(onestr) == -1) & (de1.Value.ToString().Length > 0))
  193.                                 if (de1.Value.ToString().IndexOf(onestr) == -1)
  194.                                 {
  195.                                     goto nextcmd3;
  196.                                 }
  197.                             }
  198.                             //符合所有项都存在的条件 压入字典  
  199.                             tdict.Add(tdictI, onestr);
  200.                            ////Console.WriteLine("M-Dict>>  " + tdictI.ToString() + "  || " + onestr);
  201.                             //数据替换
  202.                             Hashtable mtmpp = new Hashtable();
  203.                             mtmpp.Clear();
  204.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  205.                             {                              
  206.                                  mtmpp.Add(de2.Key ,de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  207.                             }
  208.                             mHTMs = mtmpp;
  209.                             tdictI = tdictI + 1;  //字典序号
  210.                             
  211.                             //oneModel  截取   取出碎片 压入 newModels
  212.                            string  oneModelTmp = oneModel.Replace(onestr, "*");
  213.                            string[] mykc = oneModelTmp.Split('*');
  214.                             foreach (string ddee in mykc)
  215.                             {
  216.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  217.                                 {
  218.                                     newModels.Add(ddee, "0");
  219.                                 }
  220.                             }
  221.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  222.                         nextcmd3:
  223.                             st = st + 1;
  224.                         }
  225.                     nextcmd1:
  226.                         h = h - 1;
  227.                     }
  228.                 }
  229.           nextcmd2: ;
  230.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  231.            }
  232.            //mHTMs  处理新的 网页  只留下 *0*
  233.           Hashtable mtmppC = new Hashtable();
  234.           mtmppC.Clear();
  235.           foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  236.           {
  237.               string cckc = de2.Value.ToString(); 
  238.               //把cckc中的*0*提取出来
  239.               mtmppC.Add(de2.Key,getXnX(de2.Value.ToString()));
  240.              //Console.WriteLine("M-DATA1>>  "+cckc);
  241.           }
  242.            mHTMs= mtmppC;
  243.            string mmoo = GetComDataEND(mHTMs,tdict);
  244.            if (mmoo.Length == 0)
  245.            {
  246.                //从模板得到一个项目模板
  247.                mmoo = aassBuilderModel(mHTMs);
  248.            }
  249.            mmoo = mmoo.Replace("<","*");
  250.            mmoo = mmoo.Replace(">", "*");
  251.            string mo = mmoo;
  252.            if (mo.Length == 0)
  253.            {
  254.                return "";
  255.            }
  256.            else
  257.            {
  258.                Hashtable mytpp = new Hashtable();
  259.                mytpp.Clear();
  260.                foreach (System.Collections.DictionaryEntry dec in tdict)
  261.                {
  262.                    mo = mo.Replace("*" + dec.Key.ToString() + "*", "<kc*Kc>" + dec.Value.ToString() + "<kc*Kc>" );
  263.                }
  264.                mo = mo.Replace("<kc*Kc><kc*Kc><kc*Kc>", "<kc*Kc>"); 
  265.                mo = mo.Replace("<kc*Kc><kc*Kc>", "<kc*Kc>");
  266.                mo = mo.Replace("<kc*Kc>", "*"); 
  267.                return mo;
  268.               // ArrayList mm = new ArrayList();
  269.               
  270.            }
  271.         }
  272.         /// <summary>
  273.         /// 把cckc中的*0*提取出来
  274.         /// </summary>
  275.         /// <param name="data"></param>
  276.         /// <returns></returns>
  277.         private string getXnX(string data)
  278.         {
  279.             if (data.IndexOf("*") == -1)
  280.             {
  281.                 return "";
  282.             }
  283.             string mkc = "";
  284.             int ii = 0;
  285.             while (true)
  286.             {
  287.                 ii = ii + 1;
  288.                 if (data.IndexOf("*") == -1)
  289.                 {
  290.                    // mkc = mkc.Replace("###", "#");
  291.                    // mkc = mkc.Replace("##", "#");
  292.                     for (int uu = 0; uu < 1000; uu++)
  293.                     {
  294.                         try
  295.                         {
  296.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + "><" + uu.ToString() + ">", "<《3-" + uu.ToString() + "》>");
  297.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + ">", "<《2-" + uu.ToString() + "》>");
  298.                             mkc = mkc.Replace("<《3-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  299.                             mkc = mkc.Replace("<《2-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  300.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + "><" + uu.ToString() + ">", "<《3-" + uu.ToString() + "》>");
  301.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + ">", "<《2-" + uu.ToString() + "》>");
  302.                             mkc = mkc.Replace("<《3-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  303.                             mkc = mkc.Replace("<《2-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  304.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + "><" + uu.ToString() + ">", "<《3-" + uu.ToString() + "》>");
  305.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + ">", "<《2-" + uu.ToString() + "》>");
  306.                             mkc = mkc.Replace("<《3-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  307.                             mkc = mkc.Replace("<《2-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  308.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + "><" + uu.ToString() + ">", "<" + uu.ToString() + ">");
  309.                             mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + ">", "<" + uu.ToString() + ">");
  310.                         }
  311.                         catch
  312.                         {
  313.                             for (int uu_i = 0; uu_i < 800; uu_i++)
  314.                             {
  315.                                 mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + "><" + uu.ToString() + ">", "<《3-" + uu.ToString() + "》>");
  316.                                 mkc = mkc.Replace("<" + uu.ToString() + "><" + uu.ToString() + ">", "<《2-" + uu.ToString() + "》>");
  317.                                 mkc = mkc.Replace("<《3-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  318.                                 mkc = mkc.Replace("<《2-" + uu.ToString() + "》>", "<" + uu.ToString() + ">");
  319.                             }
  320.                         }
  321.                     }
  322.                     return mkc;
  323.                 }             
  324.             
  325.                 //1 取得第一个*  取得第2个*  截取第一个和第2个 之间的数据  截断字符串
  326.                 int a1 = data.IndexOf("*");
  327.                 int a2 = data.IndexOf("*", a1 + 1);
  328.                // string aa = data.Substring(a1, a2 - a1);
  329.                // mkc = mkc + aa;
  330.                  string aa = data.Substring(a1+1, a2 - a1-1);
  331.                //  mkc = mkc + "#<"+aa+">#";
  332.                  mkc = mkc + "<" + aa + ">";
  333.                 data = data.Substring(a2 + 1, data.Length - a2-1);
  334.             }
  335.         }
  336.         /// <summary>
  337.         /// 《2》根据子模板建立一个超级模板
  338.         /// </summary>
  339.         /// <param name="mHTMs"></param>
  340.         /// <returns></returns>
  341.         private string aassBuilderModel(Hashtable mHTMs)
  342.         {
  343.             Console.Write("..");
  344.             //得到最短的串
  345.             string oneModel = "";
  346.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  347.             {
  348.                 if (oneModel.Length == 0)
  349.                 {
  350.                     oneModel = de.Value.ToString();
  351.                 }
  352.                 else
  353.                 {
  354.                     if (oneModel.Length > de.Value.ToString().Length)
  355.                     {
  356.                         oneModel = de.Value.ToString();
  357.                     }
  358.                 }
  359.             }
  360.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  361.             {
  362.                 if (oneModel != de.Value.ToString())                    //不相同
  363.                 {
  364.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  365.                     {
  366.                         goto cXStart;
  367.                     }
  368.                 }     
  369.             }
  370.             return oneModel;
  371.         cXStart:
  372.             //得到匹配临时模板的原始长度
  373.             int onemLong = oneModel.Length;
  374.             Hashtable tdict = new Hashtable();
  375.             int tdictI = 0; //字典序号
  376.             tdict.Clear();
  377.             Hashtable oneModels = new Hashtable();
  378.             oneModels.Clear();
  379.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  380.             //存放临时碎片
  381.             Hashtable newModels = new Hashtable();
  382.             newModels.Clear();
  383.             oneModel = "";
  384.         NewStart: //开始遍历匹配串
  385.             if (oneModel.Length > 0)
  386.             {
  387.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  388.             }
  389.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  390.             {
  391.                 if (oneModels.Contains(de.Key) == false)
  392.                 {
  393.                     oneModels.Add(de.Key, "0");
  394.                 }
  395.             }
  396.             newModels.Clear();
  397.             foreach (System.Collections.DictionaryEntry de in oneModels)
  398.             {
  399.                 oneModel = de.Key.ToString();
  400.                 if (oneModel.Length > 2)
  401.                 {
  402.                     int h = oneModel.Length;
  403.                     while (true)
  404.                     {
  405.                         if (h < 3)         //最短字符不能小于5  >=四
  406.                         { goto nextcmd2; }
  407.                         int st = 0;
  408.                         while (true)
  409.                         {
  410.                             if (st + h > oneModel.Length)
  411.                             { goto nextcmd1; }
  412.                             string a1 = oneModel.Substring(st, 1);
  413.                             string a2 = oneModel.Substring(st + h - 1, 1);
  414.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  415.                             {
  416.                                 goto nextcmd3;
  417.                             }
  418.                             string onestr = oneModel.Substring(st, h);
  419.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  420.                             {
  421.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  422.                             }
  423.                             //遍历数据  是否符合全部数据
  424.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  425.                             {
  426.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  427.                                 {
  428.                                     goto nextcmd3;
  429.                                 }
  430.                             }
  431.                             //符合所有项都存在的条件 压入字典  
  432.                             tdict.Add(tdictI, onestr);
  433.                            //Console.WriteLine("M-Dict2>>  " + tdictI.ToString() + "  || " + onestr);
  434.                             //数据替换
  435.                             Hashtable mtmpp = new Hashtable();
  436.                             mtmpp.Clear();
  437.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  438.                             {
  439.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  440.                                 string tmp_str = de2.Value.ToString();
  441.                                 if (tmp_str == null)
  442.                                 {
  443.                                 }
  444.                                 else
  445.                                 {
  446.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  447.                                 }
  448.                             }
  449.                             mHTMs = mtmpp;
  450.                             tdictI = tdictI + 1;  //字典序号
  451.                             //oneModel  截取   取出碎片 压入 newModels
  452.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  453.                             string[] mykc = oneModelTmp.Split('*');
  454.                             foreach (string ddee in mykc)
  455.                             {
  456.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  457.                                 {
  458.                                     newModels.Add(ddee, "0");
  459.                                 }
  460.                             }
  461.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  462.                         nextcmd3:
  463.                             st = st + 1;
  464.                         }
  465.                     nextcmd1:
  466.                         h = h - 1;
  467.                     }
  468.                 }
  469.             nextcmd2: ;
  470.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  471.             }
  472.             //mHTMs  处理新的 网页  只留下 *0*
  473.             Hashtable mtmppC = new Hashtable();
  474.             mtmppC.Clear();
  475.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  476.             {
  477.                 string cckc = de2.Value.ToString();
  478.                 //把cckc中的*0*提取出来
  479.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  480.                //Console.WriteLine("M-DATA2>>  " + cckc);
  481.                // mtmppC.Add(de2.Key, de2.Value.ToString());
  482.             }
  483.             mHTMs = mtmppC;
  484.            string mmoo = GetComDataEND(mHTMs,tdict);
  485.            if (mmoo.Length == 0)
  486.            {
  487.                //从模板得到一个项目模板
  488.                mmoo = aass3BuilderModel(mHTMs);
  489.            }
  490.             mmoo = mmoo.Replace("<", "*");
  491.             mmoo = mmoo.Replace(">", "*");
  492.             if (mmoo.Length == 0)
  493.             {
  494.                 return "";
  495.             }
  496.             else
  497.             {
  498.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  499.                 {
  500.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  501.                 }
  502.                 //Console.WriteLine("TRETURN2>>  " + mmoo);
  503.                 return mmoo;
  504.             }
  505.         }
  506.         /// <summary>
  507.         /// 《3》根据子模板建立一个超级模板
  508.         /// </summary>
  509.         /// <param name="mHTMs"></param>
  510.         /// <returns></returns>
  511.         private string aass3BuilderModel(Hashtable mHTMs)
  512.         {
  513.             Console.Write("..");
  514.             //得到最短的串
  515.             string oneModel = "";
  516.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  517.             {
  518.                 if (oneModel.Length == 0)
  519.                 {
  520.                     oneModel = de.Value.ToString();
  521.                 }
  522.                 else
  523.                 {
  524.                     if (oneModel.Length > de.Value.ToString().Length)
  525.                     {
  526.                         oneModel = de.Value.ToString();
  527.                     }
  528.                 }
  529.             }
  530.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  531.             {
  532.                 if (oneModel != de.Value.ToString())                    //不相同
  533.                 {
  534.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  535.                     {
  536.                         goto cXStart;
  537.                     }
  538.                 }
  539.             }
  540.             return oneModel;
  541.         cXStart:
  542.             //得到匹配临时模板的原始长度
  543.             int onemLong = oneModel.Length;
  544.             Hashtable tdict = new Hashtable();
  545.             int tdictI = 0; //字典序号
  546.             tdict.Clear();
  547.             Hashtable oneModels = new Hashtable();
  548.             oneModels.Clear();
  549.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  550.             //存放临时碎片
  551.             Hashtable newModels = new Hashtable();
  552.             newModels.Clear();
  553.             oneModel = "";
  554.         NewStart: //开始遍历匹配串
  555.             if (oneModel.Length > 0)
  556.             {
  557.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  558.             }
  559.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  560.             {
  561.                 if (oneModels.Contains(de.Key) == false)
  562.                 {
  563.                     oneModels.Add(de.Key, "0");
  564.                 }
  565.             }
  566.             newModels.Clear();
  567.             foreach (System.Collections.DictionaryEntry de in oneModels)
  568.             {
  569.                 oneModel = de.Key.ToString();
  570.                 if (oneModel.Length > 2)
  571.                 {
  572.                     int h = oneModel.Length;
  573.                     while (true)
  574.                     {
  575.                         if (h < 3)         //最短字符不能小于5  >=四
  576.                         { goto nextcmd2; }
  577.                         int st = 0;
  578.                         while (true)
  579.                         {
  580.                             if (st + h > oneModel.Length)
  581.                             { goto nextcmd1; }
  582.                             string a1 = oneModel.Substring(st, 1);
  583.                             string a2 = oneModel.Substring(st + h - 1, 1);
  584.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  585.                             {
  586.                                 goto nextcmd3;
  587.                             }
  588.                             string onestr = oneModel.Substring(st, h);
  589.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  590.                             {
  591.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  592.                             }
  593.                             //遍历数据  是否符合全部数据
  594.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  595.                             {
  596.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  597.                                 {
  598.                                     goto nextcmd3;
  599.                                 }
  600.                             }
  601.                             //符合所有项都存在的条件 压入字典  
  602.                             tdict.Add(tdictI, onestr);
  603.                            //Console.WriteLine("M-Dict3>>  " + tdictI.ToString() + "  || " + onestr);
  604.                             //数据替换
  605.                             Hashtable mtmpp = new Hashtable();
  606.                             mtmpp.Clear();
  607.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  608.                             {
  609.                                 string tmp_str = de2.Value.ToString();
  610.                                 if (tmp_str == null)
  611.                                 {
  612.                                 }
  613.                                 else
  614.                                 {
  615.                                     try
  616.                                     {
  617.                                         mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  618.                                     }
  619.                                     catch
  620.                                     {
  621.                                         return "";
  622.                                     }
  623.                                 }
  624.                             }
  625.                             mHTMs = mtmpp;
  626.                             tdictI = tdictI + 1;  //字典序号
  627.                             //oneModel  截取   取出碎片 压入 newModels
  628.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  629.                             string[] mykc = oneModelTmp.Split('*');
  630.                             foreach (string ddee in mykc)
  631.                             {
  632.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  633.                                 {
  634.                                     newModels.Add(ddee, "0");
  635.                                 }
  636.                             }
  637.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  638.                         nextcmd3:
  639.                             st = st + 1;
  640.                         }
  641.                     nextcmd1:
  642.                         h = h - 1;
  643.                     }
  644.                 }
  645.             nextcmd2: ;
  646.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  647.             }
  648.             //mHTMs  处理新的 网页  只留下 *0*
  649.             Hashtable mtmppC = new Hashtable();
  650.             mtmppC.Clear();
  651.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  652.             {
  653.                 string cckc = de2.Value.ToString();
  654.                 //把cckc中的*0*提取出来
  655.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  656.                //Console.WriteLine("M-DATA3>>  " + cckc);
  657.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  658.             }
  659.             mHTMs = mtmppC;
  660.            string mmoo = GetComDataEND(mHTMs,tdict);
  661.            if (mmoo.Length == 0)
  662.            {
  663.                //从模板得到一个项目模板
  664.                mmoo = aass4BuilderModel(mHTMs);
  665.            }
  666.             mmoo = mmoo.Replace("<", "*");
  667.             mmoo = mmoo.Replace(">", "*");
  668.             if (mmoo.Length == 0)
  669.             {
  670.                 return "";
  671.             }
  672.             else
  673.             {
  674.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  675.                 {
  676.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  677.                 }
  678.                 //Console.WriteLine("TRETURN3>>  " + mmoo);
  679.                 return mmoo;
  680.             }
  681.         }
  682.         /// <summary>
  683.         /// 《4》根据子模板建立一个超级模板
  684.         /// </summary>
  685.         /// <param name="mHTMs"></param>
  686.         /// <returns></returns>
  687.         private string aass4BuilderModel(Hashtable mHTMs)
  688.         {
  689.             Console.Write("..");
  690.             //得到最短的串
  691.             string oneModel = "";
  692.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  693.             {
  694.                 if (oneModel.Length == 0)
  695.                 {
  696.                     oneModel = de.Value.ToString();
  697.                 }
  698.                 else
  699.                 {
  700.                     if (oneModel.Length > de.Value.ToString().Length)
  701.                     {
  702.                         oneModel = de.Value.ToString();
  703.                     }
  704.                 }
  705.             }
  706.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  707.             {
  708.                 if (oneModel != de.Value.ToString())                    //不相同
  709.                 {
  710.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  711.                     {
  712.                         goto cXStart;
  713.                     }
  714.                 }
  715.             }
  716.             return oneModel;
  717.         cXStart:
  718.             //得到匹配临时模板的原始长度
  719.             int onemLong = oneModel.Length;
  720.             Hashtable tdict = new Hashtable();
  721.             int tdictI = 0; //字典序号
  722.             tdict.Clear();
  723.             Hashtable oneModels = new Hashtable();
  724.             oneModels.Clear();
  725.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  726.             //存放临时碎片
  727.             Hashtable newModels = new Hashtable();
  728.             newModels.Clear();
  729.             oneModel = "";
  730.         NewStart: //开始遍历匹配串
  731.             if (oneModel.Length > 0)
  732.             {
  733.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  734.             }
  735.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  736.             {
  737.                 if (oneModels.Contains(de.Key) == false)
  738.                 {
  739.                     oneModels.Add(de.Key, "0");
  740.                 }
  741.             }
  742.             newModels.Clear();
  743.             foreach (System.Collections.DictionaryEntry de in oneModels)
  744.             {
  745.                 oneModel = de.Key.ToString();
  746.                 if (oneModel.Length > 2)
  747.                 {
  748.                     int h = oneModel.Length;
  749.                     while (true)
  750.                     {
  751.                         if (h < 3)         //最短字符不能小于5  >=四
  752.                         { goto nextcmd2; }
  753.                         int st = 0;
  754.                         while (true)
  755.                         {
  756.                             if (st + h > oneModel.Length)
  757.                             { goto nextcmd1; }
  758.                             string a1 = oneModel.Substring(st, 1);
  759.                             string a2 = oneModel.Substring(st + h - 1, 1);
  760.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  761.                             {
  762.                                 goto nextcmd3;
  763.                             }
  764.                             string onestr = oneModel.Substring(st, h);
  765.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  766.                             {
  767.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  768.                             }
  769.                             //遍历数据  是否符合全部数据
  770.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  771.                             {
  772.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  773.                                 {
  774.                                     goto nextcmd3;
  775.                                 }
  776.                             }
  777.                             //符合所有项都存在的条件 压入字典  
  778.                             tdict.Add(tdictI, onestr);
  779.                            //Console.WriteLine("M-Dict4>>  " + tdictI.ToString() + "  || " + onestr);
  780.                             //数据替换
  781.                             Hashtable mtmpp = new Hashtable();
  782.                             mtmpp.Clear();
  783.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  784.                             {
  785.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  786.                                 string tmp_str = de2.Value.ToString();
  787.                                 if (tmp_str == null)
  788.                                 {
  789.                                 }
  790.                                 else
  791.                                 {
  792.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  793.                                 }
  794.                             }
  795.                             mHTMs = mtmpp;
  796.                             tdictI = tdictI + 1;  //字典序号
  797.                             //oneModel  截取   取出碎片 压入 newModels
  798.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  799.                             string[] mykc = oneModelTmp.Split('*');
  800.                             foreach (string ddee in mykc)
  801.                             {
  802.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  803.                                 {
  804.                                     newModels.Add(ddee, "0");
  805.                                 }
  806.                             }
  807.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  808.                         nextcmd3:
  809.                             st = st + 1;
  810.                         }
  811.                     nextcmd1:
  812.                         h = h - 1;
  813.                     }
  814.                 }
  815.             nextcmd2: ;
  816.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  817.             }
  818.             //mHTMs  处理新的 网页  只留下 *0*
  819.             Hashtable mtmppC = new Hashtable();
  820.             mtmppC.Clear();
  821.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  822.             {
  823.                 string cckc = de2.Value.ToString();
  824.                 //把cckc中的*0*提取出来
  825.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  826.                //Console.WriteLine("M-DATA4>>  " + cckc);
  827.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  828.             }
  829.             mHTMs = mtmppC;
  830.             //从模板得到一个项目模板
  831.             //string mmoo = aass5BuilderModel(mHTMs);
  832.             string mmoo = GetComDataEND(mHTMs, tdict);
  833.             if (mmoo.Length == 0)
  834.             {
  835.                 //从模板得到一个项目模板
  836.                 mmoo = aass3BuilderModel(mHTMs);
  837.             }
  838.             mmoo = mmoo.Replace("<", "*");
  839.             mmoo = mmoo.Replace(">", "*");
  840.             if (mmoo.Length == 0)
  841.             {
  842.                 return "";
  843.             }
  844.             else
  845.             {
  846.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  847.                 {
  848.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  849.                 }
  850.                 //Console.WriteLine("TRETURN4>>  " + mmoo);
  851.                 return mmoo;
  852.             
  853.             }
  854.         }
  855.         /// <summary>
  856.         /// 《5》根据子模板建立一个超级模板
  857.         /// </summary>
  858.         /// <param name="mHTMs"></param>
  859.         /// <returns></returns>
  860.         private string aass5BuilderModel(Hashtable mHTMs)
  861.         {
  862.             Console.Write("..");
  863.             //得到最短的串
  864.             string oneModel = "";
  865.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  866.             {
  867.                 if (oneModel.Length == 0)
  868.                 {
  869.                     oneModel = de.Value.ToString();
  870.                 }
  871.                 else
  872.                 {
  873.                     if (oneModel.Length > de.Value.ToString().Length)
  874.                     {
  875.                         oneModel = de.Value.ToString();
  876.                     }
  877.                 }
  878.             }
  879.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  880.             {
  881.                 if (oneModel != de.Value.ToString())                    //不相同
  882.                 {
  883.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  884.                     {
  885.                         goto cXStart;
  886.                     }
  887.                 }
  888.             }
  889.             return oneModel;
  890.         cXStart:
  891.             //得到匹配临时模板的原始长度
  892.             int onemLong = oneModel.Length;
  893.             Hashtable tdict = new Hashtable();
  894.             int tdictI = 0; //字典序号
  895.             tdict.Clear();
  896.             Hashtable oneModels = new Hashtable();
  897.             oneModels.Clear();
  898.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  899.             //存放临时碎片
  900.             Hashtable newModels = new Hashtable();
  901.             newModels.Clear();
  902.             oneModel = "";
  903.         NewStart: //开始遍历匹配串
  904.             if (oneModel.Length > 0)
  905.             {
  906.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  907.             }
  908.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  909.             {
  910.                 if (oneModels.Contains(de.Key) == false)
  911.                 {
  912.                     oneModels.Add(de.Key, "0");
  913.                 }
  914.             }
  915.             newModels.Clear();
  916.             foreach (System.Collections.DictionaryEntry de in oneModels)
  917.             {
  918.                 oneModel = de.Key.ToString();
  919.                 if (oneModel.Length > 2)
  920.                 {
  921.                     int h = oneModel.Length;
  922.                     while (true)
  923.                     {
  924.                         if (h < 3)         //最短字符不能小于5  >=四
  925.                         { goto nextcmd2; }
  926.                         int st = 0;
  927.                         while (true)
  928.                         {
  929.                             if (st + h > oneModel.Length)
  930.                             { goto nextcmd1; }
  931.                             string a1 = oneModel.Substring(st, 1);
  932.                             string a2 = oneModel.Substring(st + h - 1, 1);
  933.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  934.                             {
  935.                                 goto nextcmd3;
  936.                             }
  937.                             string onestr = oneModel.Substring(st, h);
  938.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  939.                             {
  940.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  941.                             }
  942.                             //遍历数据  是否符合全部数据
  943.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  944.                             {
  945.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  946.                                 {
  947.                                     goto nextcmd3;
  948.                                 }
  949.                             }
  950.                             //符合所有项都存在的条件 压入字典  
  951.                             tdict.Add(tdictI, onestr);
  952.                            //Console.WriteLine("M-Dict5>>  " + tdictI.ToString() + "  || " + onestr);
  953.                             //数据替换
  954.                             Hashtable mtmpp = new Hashtable();
  955.                             mtmpp.Clear();
  956.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  957.                             {
  958.                                 //mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  959.                                 string tmp_str = de2.Value.ToString();
  960.                                 if (tmp_str == null)
  961.                                 {
  962.                                 }
  963.                                 else
  964.                                 {
  965.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  966.                                 }
  967.                             }
  968.                             mHTMs = mtmpp;
  969.                             tdictI = tdictI + 1;  //字典序号
  970.                             //oneModel  截取   取出碎片 压入 newModels
  971.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  972.                             string[] mykc = oneModelTmp.Split('*');
  973.                             foreach (string ddee in mykc)
  974.                             {
  975.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  976.                                 {
  977.                                     newModels.Add(ddee, "0");
  978.                                 }
  979.                             }
  980.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  981.                         nextcmd3:
  982.                             st = st + 1;
  983.                         }
  984.                     nextcmd1:
  985.                         h = h - 1;
  986.                     }
  987.                 }
  988.             nextcmd2: ;
  989.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  990.             }
  991.             //mHTMs  处理新的 网页  只留下 *0*
  992.             Hashtable mtmppC = new Hashtable();
  993.             mtmppC.Clear();
  994.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  995.             {
  996.                 string cckc = de2.Value.ToString();
  997.                 //把cckc中的*0*提取出来
  998.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  999.                //Console.WriteLine("M-DATA5>>  " + cckc);
  1000.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1001.             }
  1002.             mHTMs = mtmppC;
  1003.             //从模板得到一个项目模板
  1004.             //string mmoo = aass6BuilderModel(mHTMs);
  1005.             string mmoo = GetComDataEND(mHTMs, tdict);
  1006.             if (mmoo.Length == 0)
  1007.             {
  1008.                 //从模板得到一个项目模板
  1009.                 mmoo = aass3BuilderModel(mHTMs);
  1010.             }
  1011.             mmoo = mmoo.Replace("<", "*");
  1012.             mmoo = mmoo.Replace(">", "*");
  1013.             if (mmoo.Length == 0)
  1014.             {
  1015.                 return "";
  1016.             }
  1017.             else
  1018.             {
  1019.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1020.                 {
  1021.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1022.                 }
  1023.                 //Console.WriteLine("TRETURN5>>  " + mmoo);
  1024.                 return mmoo;
  1025.             }
  1026.         }
  1027.         /// <summary>
  1028.         /// 《6》根据子模板建立一个超级模板
  1029.         /// </summary>
  1030.         /// <param name="mHTMs"></param>
  1031.         /// <returns></returns>
  1032.         private string aass6BuilderModel(Hashtable mHTMs)
  1033.         {
  1034.             Console.Write("..");
  1035.             //得到最短的串
  1036.             string oneModel = "";
  1037.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1038.             {
  1039.                 if (oneModel.Length == 0)
  1040.                 {
  1041.                     oneModel = de.Value.ToString();
  1042.                 }
  1043.                 else
  1044.                 {
  1045.                     if (oneModel.Length > de.Value.ToString().Length)
  1046.                     {
  1047.                         oneModel = de.Value.ToString();
  1048.                     }
  1049.                 }
  1050.             }
  1051.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1052.             {
  1053.                 if (oneModel != de.Value.ToString())                    //不相同
  1054.                 {
  1055.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1056.                     {
  1057.                         goto cXStart;
  1058.                     }
  1059.                 }
  1060.             }
  1061.             return oneModel;
  1062.         cXStart:
  1063.             //得到匹配临时模板的原始长度
  1064.             int onemLong = oneModel.Length;
  1065.             Hashtable tdict = new Hashtable();
  1066.             int tdictI = 0; //字典序号
  1067.             tdict.Clear();
  1068.             Hashtable oneModels = new Hashtable();
  1069.             oneModels.Clear();
  1070.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1071.             //存放临时碎片
  1072.             Hashtable newModels = new Hashtable();
  1073.             newModels.Clear();
  1074.             oneModel = "";
  1075.         NewStart: //开始遍历匹配串
  1076.             if (oneModel.Length > 0)
  1077.             {
  1078.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1079.             }
  1080.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1081.             {
  1082.                 if (oneModels.Contains(de.Key) == false)
  1083.                 {
  1084.                     oneModels.Add(de.Key, "0");
  1085.                 }
  1086.             }
  1087.             newModels.Clear();
  1088.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1089.             {
  1090.                 oneModel = de.Key.ToString();
  1091.                 if (oneModel.Length > 2)
  1092.                 {
  1093.                     int h = oneModel.Length;
  1094.                     while (true)
  1095.                     {
  1096.                         if (h < 3)         //最短字符不能小于5  >=四
  1097.                         { goto nextcmd2; }
  1098.                         int st = 0;
  1099.                         while (true)
  1100.                         {
  1101.                             if (st + h > oneModel.Length)
  1102.                             { goto nextcmd1; }
  1103.                             string a1 = oneModel.Substring(st, 1);
  1104.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1105.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1106.                             {
  1107.                                 goto nextcmd3;
  1108.                             }
  1109.                             string onestr = oneModel.Substring(st, h);
  1110.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1111.                             {
  1112.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1113.                             }
  1114.                             //遍历数据  是否符合全部数据
  1115.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1116.                             {
  1117.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1118.                                 {
  1119.                                     goto nextcmd3;
  1120.                                 }
  1121.                             }
  1122.                             //符合所有项都存在的条件 压入字典  
  1123.                             tdict.Add(tdictI, onestr);
  1124.                            //Console.WriteLine("M-Dict6>>  " + tdictI.ToString() + "  || " + onestr);
  1125.                             //数据替换
  1126.                             Hashtable mtmpp = new Hashtable();
  1127.                             mtmpp.Clear();
  1128.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1129.                             {
  1130.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1131.                                 string tmp_str = de2.Value.ToString();
  1132.                                 if (tmp_str == null)
  1133.                                 {
  1134.                                 }
  1135.                                 else
  1136.                                 {
  1137.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1138.                                 }
  1139.                             }
  1140.                             mHTMs = mtmpp;
  1141.                             tdictI = tdictI + 1;  //字典序号
  1142.                             //oneModel  截取   取出碎片 压入 newModels
  1143.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1144.                             string[] mykc = oneModelTmp.Split('*');
  1145.                             foreach (string ddee in mykc)
  1146.                             {
  1147.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  1148.                                 {
  1149.                                     newModels.Add(ddee, "0");
  1150.                                 }
  1151.                             }
  1152.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  1153.                         nextcmd3:
  1154.                             st = st + 1;
  1155.                         }
  1156.                     nextcmd1:
  1157.                         h = h - 1;
  1158.                     }
  1159.                 }
  1160.             nextcmd2: ;
  1161.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  1162.             }
  1163.             //mHTMs  处理新的 网页  只留下 *0*
  1164.             Hashtable mtmppC = new Hashtable();
  1165.             mtmppC.Clear();
  1166.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1167.             {
  1168.                 string cckc = de2.Value.ToString();
  1169.                 //把cckc中的*0*提取出来
  1170.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  1171.                //Console.WriteLine("M-DATA6>>  " + cckc);
  1172.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1173.             }
  1174.             mHTMs = mtmppC;
  1175.             //从模板得到一个项目模板
  1176.             //string mmoo = aass7BuilderModel(mHTMs);
  1177.             string mmoo = GetComDataEND(mHTMs, tdict);
  1178.             if (mmoo.Length == 0)
  1179.             {
  1180.                 //从模板得到一个项目模板
  1181.                 mmoo = aass3BuilderModel(mHTMs);
  1182.             }
  1183.             mmoo = mmoo.Replace("<", "*");
  1184.             mmoo = mmoo.Replace(">", "*");
  1185.             if (mmoo.Length == 0)
  1186.             {
  1187.                 return "";
  1188.             }
  1189.             else
  1190.             {
  1191.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1192.                 {
  1193.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1194.                 }
  1195.                 //Console.WriteLine("TRETURN6>>  " + mmoo);
  1196.                 return mmoo;
  1197.             }
  1198.         }
  1199.         /// <summary>
  1200.         /// 《7》根据子模板建立一个超级模板
  1201.         /// </summary>
  1202.         /// <param name="mHTMs"></param>
  1203.         /// <returns></returns>
  1204.         private string aass7BuilderModel(Hashtable mHTMs)
  1205.         {
  1206.             Console.Write("..");
  1207.             //得到最短的串
  1208.             string oneModel = "";
  1209.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1210.             {
  1211.                 if (oneModel.Length == 0)
  1212.                 {
  1213.                     oneModel = de.Value.ToString();
  1214.                 }
  1215.                 else
  1216.                 {
  1217.                     if (oneModel.Length > de.Value.ToString().Length)
  1218.                     {
  1219.                         oneModel = de.Value.ToString();
  1220.                     }
  1221.                 }
  1222.             }
  1223.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1224.             {
  1225.                 if (oneModel != de.Value.ToString())                    //不相同
  1226.                 {
  1227.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1228.                     {
  1229.                         goto cXStart;
  1230.                     }
  1231.                 }
  1232.             }
  1233.             return oneModel;
  1234.         cXStart:
  1235.             //得到匹配临时模板的原始长度
  1236.             int onemLong = oneModel.Length;
  1237.             Hashtable tdict = new Hashtable();
  1238.             int tdictI = 0; //字典序号
  1239.             tdict.Clear();
  1240.             Hashtable oneModels = new Hashtable();
  1241.             oneModels.Clear();
  1242.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1243.             //存放临时碎片
  1244.             Hashtable newModels = new Hashtable();
  1245.             newModels.Clear();
  1246.             oneModel = "";
  1247.         NewStart: //开始遍历匹配串
  1248.             if (oneModel.Length > 0)
  1249.             {
  1250.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1251.             }
  1252.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1253.             {
  1254.                 if (oneModels.Contains(de.Key) == false)
  1255.                 {
  1256.                     oneModels.Add(de.Key, "0");
  1257.                 }
  1258.             }
  1259.             newModels.Clear();
  1260.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1261.             {
  1262.                 oneModel = de.Key.ToString();
  1263.                 if (oneModel.Length > 2)
  1264.                 {
  1265.                     int h = oneModel.Length;
  1266.                     while (true)
  1267.                     {
  1268.                         if (h < 3)         //最短字符不能小于5  >=四
  1269.                         { goto nextcmd2; }
  1270.                         int st = 0;
  1271.                         while (true)
  1272.                         {
  1273.                             if (st + h > oneModel.Length)
  1274.                             { goto nextcmd1; }
  1275.                             string a1 = oneModel.Substring(st, 1);
  1276.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1277.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1278.                             {
  1279.                                 goto nextcmd3;
  1280.                             }
  1281.                             string onestr = oneModel.Substring(st, h);
  1282.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1283.                             {
  1284.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1285.                             }
  1286.                             //遍历数据  是否符合全部数据
  1287.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1288.                             {
  1289.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1290.                                 {
  1291.                                     goto nextcmd3;
  1292.                                 }
  1293.                             }
  1294.                             //符合所有项都存在的条件 压入字典  
  1295.                             tdict.Add(tdictI, onestr);
  1296.                            //Console.WriteLine("M-Dict7>>  " + tdictI.ToString() + "  || " + onestr);
  1297.                             //数据替换
  1298.                             Hashtable mtmpp = new Hashtable();
  1299.                             mtmpp.Clear();
  1300.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1301.                             {
  1302.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1303.                                 string tmp_str = de2.Value.ToString();
  1304.                                 if (tmp_str == null)
  1305.                                 {
  1306.                                 }
  1307.                                 else
  1308.                                 {
  1309.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1310.                                 }
  1311.                             }
  1312.                             mHTMs = mtmpp;
  1313.                             tdictI = tdictI + 1;  //字典序号
  1314.                             //oneModel  截取   取出碎片 压入 newModels
  1315.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1316.                             string[] mykc = oneModelTmp.Split('*');
  1317.                             foreach (string ddee in mykc)
  1318.                             {
  1319.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  1320.                                 {
  1321.                                     newModels.Add(ddee, "0");
  1322.                                 }
  1323.                             }
  1324.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  1325.                         nextcmd3:
  1326.                             st = st + 1;
  1327.                         }
  1328.                     nextcmd1:
  1329.                         h = h - 1;
  1330.                     }
  1331.                 }
  1332.             nextcmd2: ;
  1333.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  1334.             }
  1335.             //mHTMs  处理新的 网页  只留下 *0*
  1336.             Hashtable mtmppC = new Hashtable();
  1337.             mtmppC.Clear();
  1338.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1339.             {
  1340.                 string cckc = de2.Value.ToString();
  1341.                 //把cckc中的*0*提取出来
  1342.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  1343.                //Console.WriteLine("M-DATA7>>  " + cckc);
  1344.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1345.             }
  1346.             mHTMs = mtmppC;
  1347.             //从模板得到一个项目模板
  1348.            // string mmoo = aass8BuilderModel(mHTMs);
  1349.             string mmoo = GetComDataEND(mHTMs, tdict);
  1350.             if (mmoo.Length == 0)
  1351.             {
  1352.                 //从模板得到一个项目模板
  1353.                 mmoo = aass3BuilderModel(mHTMs);
  1354.             }
  1355.             mmoo = mmoo.Replace("<", "*");
  1356.             mmoo = mmoo.Replace(">", "*");
  1357.             if (mmoo.Length == 0)
  1358.             {
  1359.                 return "";
  1360.             }
  1361.             else
  1362.             {
  1363.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1364.                 {
  1365.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1366.                 }
  1367.                 //Console.WriteLine("TRETURN7>>  " + mmoo);
  1368.                 return mmoo;
  1369.             }
  1370.         }
  1371.         /// <summary>
  1372.         /// 《8》根据子模板建立一个超级模板
  1373.         /// </summary>
  1374.         /// <param name="mHTMs"></param>
  1375.         /// <returns></returns>
  1376.         private string aass8BuilderModel(Hashtable mHTMs)
  1377.         {
  1378.             Console.Write("..");
  1379.             
  1380.             //得到最短的串
  1381.             string oneModel = "";
  1382.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1383.             {
  1384.                 if (oneModel.Length == 0)
  1385.                 {
  1386.                     oneModel = de.Value.ToString();
  1387.                 }
  1388.                 else
  1389.                 {
  1390.                     if (oneModel.Length > de.Value.ToString().Length)
  1391.                     {
  1392.                         oneModel = de.Value.ToString();
  1393.                     }
  1394.                 }
  1395.             }
  1396.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1397.             {
  1398.                 if (oneModel != de.Value.ToString())                    //不相同
  1399.                 {
  1400.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1401.                     {
  1402.                         goto cXStart;
  1403.                     }
  1404.                 }
  1405.             }
  1406.             return oneModel;
  1407.         cXStart:
  1408.             //得到匹配临时模板的原始长度
  1409.             int onemLong = oneModel.Length;
  1410.             Hashtable tdict = new Hashtable();
  1411.             int tdictI = 0; //字典序号
  1412.             tdict.Clear();
  1413.             Hashtable oneModels = new Hashtable();
  1414.             oneModels.Clear();
  1415.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1416.             //存放临时碎片
  1417.             Hashtable newModels = new Hashtable();
  1418.             newModels.Clear();
  1419.             oneModel = "";
  1420.         NewStart: //开始遍历匹配串
  1421.             if (oneModel.Length > 0)
  1422.             {
  1423.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1424.             }
  1425.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1426.             {
  1427.                 if (oneModels.Contains(de.Key) == false)
  1428.                 {
  1429.                     oneModels.Add(de.Key, "0");
  1430.                 }
  1431.             }
  1432.             newModels.Clear();
  1433.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1434.             {
  1435.                 oneModel = de.Key.ToString();
  1436.                 if (oneModel.Length > 2)
  1437.                 {
  1438.                     int h = oneModel.Length;
  1439.                     while (true)
  1440.                     {
  1441.                         if (h < 3)         //最短字符不能小于5  >=四
  1442.                         { goto nextcmd2; }
  1443.                         int st = 0;
  1444.                         while (true)
  1445.                         {
  1446.                             if (st + h > oneModel.Length)
  1447.                             { goto nextcmd1; }
  1448.                             string a1 = oneModel.Substring(st, 1);
  1449.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1450.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1451.                             {
  1452.                                 goto nextcmd3;
  1453.                             }
  1454.                             string onestr = oneModel.Substring(st, h);
  1455.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1456.                             {
  1457.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1458.                             }
  1459.                             //遍历数据  是否符合全部数据
  1460.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1461.                             {
  1462.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1463.                                 {
  1464.                                     goto nextcmd3;
  1465.                                 }
  1466.                             }
  1467.                             //符合所有项都存在的条件 压入字典  
  1468.                             tdict.Add(tdictI, onestr);
  1469.                             //数据替换
  1470.                             Hashtable mtmpp = new Hashtable();
  1471.                             mtmpp.Clear();
  1472.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1473.                             {
  1474.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1475.                                 string tmp_str = de2.Value.ToString();
  1476.                                 if (tmp_str == null)
  1477.                                 {
  1478.                                 }
  1479.                                 else
  1480.                                 {
  1481.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1482.                                 }
  1483.                             }
  1484.                             mHTMs = mtmpp;
  1485.                             tdictI = tdictI + 1;  //字典序号
  1486.                             //oneModel  截取   取出碎片 压入 newModels
  1487.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1488.                             string[] mykc = oneModelTmp.Split('*');
  1489.                             foreach (string ddee in mykc)
  1490.                             {
  1491.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  1492.                                 {
  1493.                                     newModels.Add(ddee, "0");
  1494.                                 }
  1495.                             }
  1496.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  1497.                         nextcmd3:
  1498.                             st = st + 1;
  1499.                         }
  1500.                     nextcmd1:
  1501.                         h = h - 1;
  1502.                     }
  1503.                 }
  1504.             nextcmd2: ;
  1505.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  1506.             }
  1507.             //mHTMs  处理新的 网页  只留下 *0*
  1508.             Hashtable mtmppC = new Hashtable();
  1509.             mtmppC.Clear();
  1510.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1511.             {
  1512.                 string cckc = de2.Value.ToString();
  1513.                 //把cckc中的*0*提取出来
  1514.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  1515.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1516.             }
  1517.             mHTMs = mtmppC;
  1518.             //从模板得到一个项目模板
  1519.             //string mmoo = aass9BuilderModel(mHTMs);
  1520.             string mmoo = GetComDataEND(mHTMs, tdict);
  1521.             if (mmoo.Length == 0)
  1522.             {
  1523.                 //从模板得到一个项目模板
  1524.                 mmoo = aass3BuilderModel(mHTMs);
  1525.             }
  1526.             mmoo = mmoo.Replace("<", "*");
  1527.             mmoo = mmoo.Replace(">", "*");
  1528.             if (mmoo.Length == 0)
  1529.             {
  1530.                 return "";
  1531.             }
  1532.             else
  1533.             {
  1534.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1535.                 {
  1536.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1537.                 }
  1538.                 //Console.WriteLine("TRETURN8>>  " + mmoo);
  1539.                 return mmoo;
  1540.             }
  1541.         }
  1542.         /// <summary>
  1543.         /// 《9》根据子模板建立一个超级模板
  1544.         /// </summary>
  1545.         /// <param name="mHTMs"></param>
  1546.         /// <returns></returns>
  1547.         private string aass9BuilderModel(Hashtable mHTMs)
  1548.         {
  1549.             Console.Write("..");
  1550.             //得到最短的串
  1551.             string oneModel = "";
  1552.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1553.             {
  1554.                 if (oneModel.Length == 0)
  1555.                 {
  1556.                     oneModel = de.Value.ToString();
  1557.                 }
  1558.                 else
  1559.                 {
  1560.                     if (oneModel.Length > de.Value.ToString().Length)
  1561.                     {
  1562.                         oneModel = de.Value.ToString();
  1563.                     }
  1564.                 }
  1565.             }
  1566.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1567.             {
  1568.                 if (oneModel != de.Value.ToString())                    //不相同
  1569.                 {
  1570.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1571.                     {
  1572.                         goto cXStart;
  1573.                     }
  1574.                 }
  1575.             }
  1576.             return oneModel;
  1577.         cXStart:
  1578.             //得到匹配临时模板的原始长度
  1579.             int onemLong = oneModel.Length;
  1580.             Hashtable tdict = new Hashtable();
  1581.             int tdictI = 0; //字典序号
  1582.             tdict.Clear();
  1583.             Hashtable oneModels = new Hashtable();
  1584.             oneModels.Clear();
  1585.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1586.             //存放临时碎片
  1587.             Hashtable newModels = new Hashtable();
  1588.             newModels.Clear();
  1589.             oneModel = "";
  1590.         NewStart: //开始遍历匹配串
  1591.             if (oneModel.Length > 0)
  1592.             {
  1593.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1594.             }
  1595.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1596.             {
  1597.                 if (oneModels.Contains(de.Key) == false)
  1598.                 {
  1599.                     oneModels.Add(de.Key, "0");
  1600.                 }
  1601.             }
  1602.             newModels.Clear();
  1603.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1604.             {
  1605.                 oneModel = de.Key.ToString();
  1606.                 if (oneModel.Length > 2)
  1607.                 {
  1608.                     int h = oneModel.Length;
  1609.                     while (true)
  1610.                     {
  1611.                         if (h < 3)         //最短字符不能小于5  >=四
  1612.                         { goto nextcmd2; }
  1613.                         int st = 0;
  1614.                         while (true)
  1615.                         {
  1616.                             if (st + h > oneModel.Length)
  1617.                             { goto nextcmd1; }
  1618.                             string a1 = oneModel.Substring(st, 1);
  1619.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1620.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1621.                             {
  1622.                                 goto nextcmd3;
  1623.                             }
  1624.                             string onestr = oneModel.Substring(st, h);
  1625.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1626.                             {
  1627.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1628.                             }
  1629.                             //遍历数据  是否符合全部数据
  1630.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1631.                             {
  1632.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1633.                                 {
  1634.                                     goto nextcmd3;
  1635.                                 }
  1636.                             }
  1637.                             //符合所有项都存在的条件 压入字典  
  1638.                             tdict.Add(tdictI, onestr);
  1639.                             //数据替换
  1640.                             Hashtable mtmpp = new Hashtable();
  1641.                             mtmpp.Clear();
  1642.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1643.                             {
  1644.                                 //mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1645.                                 string tmp_str = de2.Value.ToString();
  1646.                                 if (tmp_str == null)
  1647.                                 {
  1648.                                 }
  1649.                                 else
  1650.                                 {
  1651.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1652.                                 }
  1653.                             }
  1654.                             mHTMs = mtmpp;
  1655.                             tdictI = tdictI + 1;  //字典序号
  1656.                             //oneModel  截取   取出碎片 压入 newModels
  1657.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1658.                             string[] mykc = oneModelTmp.Split('*');
  1659.                             foreach (string ddee in mykc)
  1660.                             {
  1661.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  1662.                                 {
  1663.                                     newModels.Add(ddee, "0");
  1664.                                 }
  1665.                             }
  1666.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  1667.                         nextcmd3:
  1668.                             st = st + 1;
  1669.                         }
  1670.                     nextcmd1:
  1671.                         h = h - 1;
  1672.                     }
  1673.                 }
  1674.             nextcmd2: ;
  1675.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  1676.             }
  1677.             //mHTMs  处理新的 网页  只留下 *0*
  1678.             Hashtable mtmppC = new Hashtable();
  1679.             mtmppC.Clear();
  1680.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1681.             {
  1682.                 string cckc = de2.Value.ToString();
  1683.                 //把cckc中的*0*提取出来
  1684.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  1685.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1686.             }
  1687.             mHTMs = mtmppC;
  1688.             //从模板得到一个项目模板
  1689.            // string mmoo = aass10BuilderModel(mHTMs);
  1690.             string mmoo = GetComDataEND(mHTMs, tdict);
  1691.             if (mmoo.Length == 0)
  1692.             {
  1693.                 //从模板得到一个项目模板
  1694.                 mmoo = aass3BuilderModel(mHTMs);
  1695.             }
  1696.             mmoo = mmoo.Replace("<", "*");
  1697.             mmoo = mmoo.Replace(">", "*");
  1698.             if (mmoo.Length == 0)
  1699.             {
  1700.                 return "";
  1701.             }
  1702.             else
  1703.             {
  1704.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1705.                 {
  1706.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1707.                 }
  1708.                 return mmoo;
  1709.             }
  1710.         }
  1711.         //10
  1712.         /// <summary>
  1713.         /// 《10》根据子模板建立一个超级模板
  1714.         /// </summary>
  1715.         /// <param name="mHTMs"></param>
  1716.         /// <returns></returns>
  1717.         private string aass10BuilderModel(Hashtable mHTMs)
  1718.         {
  1719.             Console.Write("..");
  1720.             //得到最短的串
  1721.             string oneModel = "";
  1722.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1723.             {
  1724.                 if (oneModel.Length == 0)
  1725.                 {
  1726.                     oneModel = de.Value.ToString();
  1727.                 }
  1728.                 else
  1729.                 {
  1730.                     if (oneModel.Length > de.Value.ToString().Length)
  1731.                     {
  1732.                         oneModel = de.Value.ToString();
  1733.                     }
  1734.                 }
  1735.             }
  1736.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1737.             {
  1738.                 if (oneModel != de.Value.ToString())                    //不相同
  1739.                 {
  1740.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1741.                     {
  1742.                         goto cXStart;
  1743.                     }
  1744.                 }
  1745.             }
  1746.             return oneModel;
  1747.         cXStart:
  1748.             //得到匹配临时模板的原始长度
  1749.             int onemLong = oneModel.Length;
  1750.             Hashtable tdict = new Hashtable();
  1751.             int tdictI = 0; //字典序号
  1752.             tdict.Clear();
  1753.             Hashtable oneModels = new Hashtable();
  1754.             oneModels.Clear();
  1755.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1756.             //存放临时碎片
  1757.             Hashtable newModels = new Hashtable();
  1758.             newModels.Clear();
  1759.             oneModel = "";
  1760.         NewStart: //开始遍历匹配串
  1761.             if (oneModel.Length > 0)
  1762.             {
  1763.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1764.             }
  1765.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1766.             {
  1767.                 if (oneModels.Contains(de.Key) == false)
  1768.                 {
  1769.                     oneModels.Add(de.Key, "0");
  1770.                 }
  1771.             }
  1772.             newModels.Clear();
  1773.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1774.             {
  1775.                 oneModel = de.Key.ToString();
  1776.                 if (oneModel.Length > 2)
  1777.                 {
  1778.                     int h = oneModel.Length;
  1779.                     while (true)
  1780.                     {
  1781.                         if (h < 3)         //最短字符不能小于5  >=四
  1782.                         { goto nextcmd2; }
  1783.                         int st = 0;
  1784.                         while (true)
  1785.                         {
  1786.                             if (st + h > oneModel.Length)
  1787.                             { goto nextcmd1; }
  1788.                             string a1 = oneModel.Substring(st, 1);
  1789.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1790.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1791.                             {
  1792.                                 goto nextcmd3;
  1793.                             }
  1794.                             string onestr = oneModel.Substring(st, h);
  1795.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1796.                             {
  1797.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1798.                             }
  1799.                             //遍历数据  是否符合全部数据
  1800.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1801.                             {
  1802.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1803.                                 {
  1804.                                     goto nextcmd3;
  1805.                                 }
  1806.                             }
  1807.                             //符合所有项都存在的条件 压入字典  
  1808.                             tdict.Add(tdictI, onestr);
  1809.                             //数据替换
  1810.                             Hashtable mtmpp = new Hashtable();
  1811.                             mtmpp.Clear();
  1812.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1813.                             {
  1814.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1815.                                 string tmp_str = de2.Value.ToString();
  1816.                                 if (tmp_str == null)
  1817.                                 {
  1818.                                 }
  1819.                                 else
  1820.                                 {
  1821.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1822.                                 }
  1823.                             }
  1824.                             mHTMs = mtmpp;
  1825.                             tdictI = tdictI + 1;  //字典序号
  1826.                             //oneModel  截取   取出碎片 压入 newModels
  1827.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1828.                             string[] mykc = oneModelTmp.Split('*');
  1829.                             foreach (string ddee in mykc)
  1830.                             {
  1831.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  1832.                                 {
  1833.                                     newModels.Add(ddee, "0");
  1834.                                 }
  1835.                             }
  1836.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  1837.                         nextcmd3:
  1838.                             st = st + 1;
  1839.                         }
  1840.                     nextcmd1:
  1841.                         h = h - 1;
  1842.                     }
  1843.                 }
  1844.             nextcmd2: ;
  1845.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  1846.             }
  1847.             //mHTMs  处理新的 网页  只留下 *0*
  1848.             Hashtable mtmppC = new Hashtable();
  1849.             mtmppC.Clear();
  1850.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1851.             {
  1852.                 string cckc = de2.Value.ToString();
  1853.                 //把cckc中的*0*提取出来
  1854.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  1855.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  1856.             }
  1857.             mHTMs = mtmppC;
  1858.             //从模板得到一个项目模板
  1859.            // string mmoo = aass11BuilderModel(mHTMs);
  1860.             string mmoo = GetComDataEND(mHTMs, tdict);
  1861.             if (mmoo.Length == 0)
  1862.             {
  1863.                 //从模板得到一个项目模板
  1864.                 mmoo = aass3BuilderModel(mHTMs);
  1865.             }
  1866.             mmoo = mmoo.Replace("<", "*");
  1867.             mmoo = mmoo.Replace(">", "*");
  1868.             if (mmoo.Length == 0)
  1869.             {
  1870.                 return "";
  1871.             }
  1872.             else
  1873.             {
  1874.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  1875.                 {
  1876.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  1877.                 }
  1878.                 return mmoo;
  1879.             }
  1880.         }
  1881.         //11
  1882.         /// <summary>
  1883.         /// 《11》根据子模板建立一个超级模板
  1884.         /// </summary>
  1885.         /// <param name="mHTMs"></param>
  1886.         /// <returns></returns>
  1887.         private string aass11BuilderModel(Hashtable mHTMs)
  1888.         {
  1889.             Console.Write("..");
  1890.             //得到最短的串
  1891.             string oneModel = "";
  1892.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1893.             {
  1894.                 if (oneModel.Length == 0)
  1895.                 {
  1896.                     oneModel = de.Value.ToString();
  1897.                 }
  1898.                 else
  1899.                 {
  1900.                     if (oneModel.Length > de.Value.ToString().Length)
  1901.                     {
  1902.                         oneModel = de.Value.ToString();
  1903.                     }
  1904.                 }
  1905.             }
  1906.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  1907.             {
  1908.                 if (oneModel != de.Value.ToString())                    //不相同
  1909.                 {
  1910.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  1911.                     {
  1912.                         goto cXStart;
  1913.                     }
  1914.                 }
  1915.             }
  1916.             return oneModel;
  1917.         cXStart:
  1918.             //得到匹配临时模板的原始长度
  1919.             int onemLong = oneModel.Length;
  1920.             Hashtable tdict = new Hashtable();
  1921.             int tdictI = 0; //字典序号
  1922.             tdict.Clear();
  1923.             Hashtable oneModels = new Hashtable();
  1924.             oneModels.Clear();
  1925.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  1926.             //存放临时碎片
  1927.             Hashtable newModels = new Hashtable();
  1928.             newModels.Clear();
  1929.             oneModel = "";
  1930.         NewStart: //开始遍历匹配串
  1931.             if (oneModel.Length > 0)
  1932.             {
  1933.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  1934.             }
  1935.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  1936.             {
  1937.                 if (oneModels.Contains(de.Key) == false)
  1938.                 {
  1939.                     oneModels.Add(de.Key, "0");
  1940.                 }
  1941.             }
  1942.             newModels.Clear();
  1943.             foreach (System.Collections.DictionaryEntry de in oneModels)
  1944.             {
  1945.                 oneModel = de.Key.ToString();
  1946.                 if (oneModel.Length > 2)
  1947.                 {
  1948.                     int h = oneModel.Length;
  1949.                     while (true)
  1950.                     {
  1951.                         if (h < 3)         //最短字符不能小于5  >=四
  1952.                         { goto nextcmd2; }
  1953.                         int st = 0;
  1954.                         while (true)
  1955.                         {
  1956.                             if (st + h > oneModel.Length)
  1957.                             { goto nextcmd1; }
  1958.                             string a1 = oneModel.Substring(st, 1);
  1959.                             string a2 = oneModel.Substring(st + h - 1, 1);
  1960.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  1961.                             {
  1962.                                 goto nextcmd3;
  1963.                             }
  1964.                             string onestr = oneModel.Substring(st, h);
  1965.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  1966.                             {
  1967.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  1968.                             }
  1969.                             //遍历数据  是否符合全部数据
  1970.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  1971.                             {
  1972.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1)&(de1.Value.ToString().Length>0))
  1973.                                 {
  1974.                                     goto nextcmd3;
  1975.                                 }
  1976.                             }
  1977.                             //符合所有项都存在的条件 压入字典  
  1978.                             tdict.Add(tdictI, onestr);
  1979.                             //数据替换
  1980.                             Hashtable mtmpp = new Hashtable();
  1981.                             mtmpp.Clear();
  1982.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  1983.                             {
  1984.                                 //mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  1985.                                 string tmp_str = de2.Value.ToString();
  1986.                                 if (tmp_str == null)
  1987.                                 {
  1988.                                 }
  1989.                                 else
  1990.                                 {
  1991.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  1992.                                 }
  1993.                             }
  1994.                             mHTMs = mtmpp;
  1995.                             tdictI = tdictI + 1;  //字典序号
  1996.                             //oneModel  截取   取出碎片 压入 newModels
  1997.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  1998.                             string[] mykc = oneModelTmp.Split('*');
  1999.                             foreach (string ddee in mykc)
  2000.                             {
  2001.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  2002.                                 {
  2003.                                     newModels.Add(ddee, "0");
  2004.                                 }
  2005.                             }
  2006.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  2007.                         nextcmd3:
  2008.                             st = st + 1;
  2009.                         }
  2010.                     nextcmd1:
  2011.                         h = h - 1;
  2012.                     }
  2013.                 }
  2014.             nextcmd2: ;
  2015.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  2016.             }
  2017.             //mHTMs  处理新的 网页  只留下 *0*
  2018.             Hashtable mtmppC = new Hashtable();
  2019.             mtmppC.Clear();
  2020.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2021.             {
  2022.                 string cckc = de2.Value.ToString();
  2023.                 //把cckc中的*0*提取出来
  2024.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  2025.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  2026.             }
  2027.             mHTMs = mtmppC;
  2028.             //从模板得到一个项目模板
  2029.            // string mmoo = aass12BuilderModel(mHTMs);
  2030.             string mmoo = GetComDataEND(mHTMs, tdict);
  2031.             if (mmoo.Length == 0)
  2032.             {
  2033.                 //从模板得到一个项目模板
  2034.                 mmoo = aass3BuilderModel(mHTMs);
  2035.             }
  2036.             mmoo = mmoo.Replace("<", "*");
  2037.             mmoo = mmoo.Replace(">", "*");
  2038.             if (mmoo.Length == 0)
  2039.             {
  2040.                 return "";
  2041.             }
  2042.             else
  2043.             {
  2044.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  2045.                 {
  2046.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  2047.                 }
  2048.                 return mmoo;
  2049.             }
  2050.         }
  2051.         ////////////////////////////////////////////////////////////////////////////////
  2052.        //12
  2053.        ////////////////////////////////////////////////////////////////////////////////
  2054.         //12
  2055.         /// <summary>
  2056.         /// 《12》根据子模板建立一个超级模板
  2057.         /// </summary>
  2058.         /// <param name="mHTMs"></param>
  2059.         /// <returns></returns>
  2060.         private string aass12BuilderModel(Hashtable mHTMs)
  2061.         {
  2062.             Console.Write("..");
  2063.             //得到最短的串
  2064.             string oneModel = "";
  2065.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2066.             {
  2067.                 if (oneModel.Length == 0)
  2068.                 {
  2069.                     oneModel = de.Value.ToString();
  2070.                 }
  2071.                 else
  2072.                 {
  2073.                     if (oneModel.Length > de.Value.ToString().Length)
  2074.                     {
  2075.                         oneModel = de.Value.ToString();
  2076.                     }
  2077.                 }
  2078.             }
  2079.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2080.             {
  2081.                 if (oneModel != de.Value.ToString())                    //不相同
  2082.                 {
  2083.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  2084.                     {
  2085.                         goto cXStart;
  2086.                     }
  2087.                 }
  2088.             }
  2089.             return oneModel;
  2090.         cXStart:
  2091.             //得到匹配临时模板的原始长度
  2092.             int onemLong = oneModel.Length;
  2093.             Hashtable tdict = new Hashtable();
  2094.             int tdictI = 0; //字典序号
  2095.             tdict.Clear();
  2096.             Hashtable oneModels = new Hashtable();
  2097.             oneModels.Clear();
  2098.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  2099.             //存放临时碎片
  2100.             Hashtable newModels = new Hashtable();
  2101.             newModels.Clear();
  2102.             oneModel = "";
  2103.         NewStart: //开始遍历匹配串
  2104.             if (oneModel.Length > 0)
  2105.             {
  2106.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  2107.             }
  2108.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  2109.             {
  2110.                 if (oneModels.Contains(de.Key) == false)
  2111.                 {
  2112.                     oneModels.Add(de.Key, "0");
  2113.                 }
  2114.             }
  2115.             newModels.Clear();
  2116.             foreach (System.Collections.DictionaryEntry de in oneModels)
  2117.             {
  2118.                 oneModel = de.Key.ToString();
  2119.                 if (oneModel.Length > 2)
  2120.                 {
  2121.                     int h = oneModel.Length;
  2122.                     while (true)
  2123.                     {
  2124.                         if (h < 3)         //最短字符不能小于5  >=四
  2125.                         { goto nextcmd2; }
  2126.                         int st = 0;
  2127.                         while (true)
  2128.                         {
  2129.                             if (st + h > oneModel.Length)
  2130.                             { goto nextcmd1; }
  2131.                             string a1 = oneModel.Substring(st, 1);
  2132.                             string a2 = oneModel.Substring(st + h - 1, 1);
  2133.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  2134.                             {
  2135.                                 goto nextcmd3;
  2136.                             }
  2137.                             string onestr = oneModel.Substring(st, h);
  2138.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  2139.                             {
  2140.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  2141.                             }
  2142.                             //遍历数据  是否符合全部数据
  2143.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  2144.                             {
  2145.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1) & (de1.Value.ToString().Length > 0))
  2146.                                 {
  2147.                                     goto nextcmd3;
  2148.                                 }
  2149.                             }
  2150.                             //符合所有项都存在的条件 压入字典  
  2151.                             tdict.Add(tdictI, onestr);
  2152.                             //数据替换
  2153.                             Hashtable mtmpp = new Hashtable();
  2154.                             mtmpp.Clear();
  2155.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2156.                             {
  2157.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  2158.                                 string tmp_str = de2.Value.ToString();
  2159.                                 if (tmp_str == null)
  2160.                                 {
  2161.                                 }
  2162.                                 else
  2163.                                 {
  2164.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  2165.                                 }
  2166.                             }
  2167.                             mHTMs = mtmpp;
  2168.                             tdictI = tdictI + 1;  //字典序号
  2169.                             //oneModel  截取   取出碎片 压入 newModels
  2170.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  2171.                             string[] mykc = oneModelTmp.Split('*');
  2172.                             foreach (string ddee in mykc)
  2173.                             {
  2174.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  2175.                                 {
  2176.                                     newModels.Add(ddee, "0");
  2177.                                 }
  2178.                             }
  2179.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  2180.                         nextcmd3:
  2181.                             st = st + 1;
  2182.                         }
  2183.                     nextcmd1:
  2184.                         h = h - 1;
  2185.                     }
  2186.                 }
  2187.             nextcmd2: ;
  2188.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  2189.             }
  2190.             //mHTMs  处理新的 网页  只留下 *0*
  2191.             Hashtable mtmppC = new Hashtable();
  2192.             mtmppC.Clear();
  2193.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2194.             {
  2195.                 string cckc = de2.Value.ToString();
  2196.                 //把cckc中的*0*提取出来
  2197.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  2198.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  2199.             }
  2200.             mHTMs = mtmppC;
  2201.             //从模板得到一个项目模板
  2202.             //string mmoo = aass13BuilderModel(mHTMs);
  2203.             string mmoo = GetComDataEND(mHTMs, tdict);
  2204.             if (mmoo.Length == 0)
  2205.             {
  2206.                 //从模板得到一个项目模板
  2207.                 mmoo = aass3BuilderModel(mHTMs);
  2208.             }
  2209.             mmoo = mmoo.Replace("<", "*");
  2210.             mmoo = mmoo.Replace(">", "*");
  2211.             if (mmoo.Length == 0)
  2212.             {
  2213.                 return "";
  2214.             }
  2215.             else
  2216.             {
  2217.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  2218.                 {
  2219.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  2220.                 }
  2221.                 return mmoo;
  2222.             }
  2223.         }
  2224.         ////////////////////////////////////////////////////////////////////////////////
  2225.         //13
  2226.         ////////////////////////////////////////////////////////////////////////////////
  2227.         //13
  2228.         /// <summary>
  2229.         /// 《13》根据子模板建立一个超级模板
  2230.         /// </summary>
  2231.         /// <param name="mHTMs"></param>
  2232.         /// <returns></returns>
  2233.         private string aass13BuilderModel(Hashtable mHTMs)
  2234.         {
  2235.             //得到最短的串
  2236.             string oneModel = "";
  2237.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2238.             {
  2239.                 if (oneModel.Length == 0)
  2240.                 {
  2241.                     oneModel = de.Value.ToString();
  2242.                 }
  2243.                 else
  2244.                 {
  2245.                     if (oneModel.Length > de.Value.ToString().Length)
  2246.                     {
  2247.                         oneModel = de.Value.ToString();
  2248.                     }
  2249.                 }
  2250.             }
  2251.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2252.             {
  2253.                 if (oneModel != de.Value.ToString())                    //不相同
  2254.                 {
  2255.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  2256.                     {
  2257.                         goto cXStart;
  2258.                     }
  2259.                 }
  2260.             }
  2261.             return oneModel;
  2262.         cXStart:
  2263.             //得到匹配临时模板的原始长度
  2264.             int onemLong = oneModel.Length;
  2265.             Hashtable tdict = new Hashtable();
  2266.             int tdictI = 0; //字典序号
  2267.             tdict.Clear();
  2268.             Hashtable oneModels = new Hashtable();
  2269.             oneModels.Clear();
  2270.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  2271.             //存放临时碎片
  2272.             Hashtable newModels = new Hashtable();
  2273.             newModels.Clear();
  2274.             oneModel = "";
  2275.         NewStart: //开始遍历匹配串
  2276.             if (oneModel.Length > 0)
  2277.             {
  2278.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  2279.             }
  2280.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  2281.             {
  2282.                 if (oneModels.Contains(de.Key) == false)
  2283.                 {
  2284.                     oneModels.Add(de.Key, "0");
  2285.                 }
  2286.             }
  2287.             newModels.Clear();
  2288.             foreach (System.Collections.DictionaryEntry de in oneModels)
  2289.             {
  2290.                 oneModel = de.Key.ToString();
  2291.                 if (oneModel.Length > 2)
  2292.                 {
  2293.                     int h = oneModel.Length;
  2294.                     while (true)
  2295.                     {
  2296.                         if (h < 3)         //最短字符不能小于5  >=四
  2297.                         { goto nextcmd2; }
  2298.                         int st = 0;
  2299.                         while (true)
  2300.                         {
  2301.                             if (st + h > oneModel.Length)
  2302.                             { goto nextcmd1; }
  2303.                             string a1 = oneModel.Substring(st, 1);
  2304.                             string a2 = oneModel.Substring(st + h - 1, 1);
  2305.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  2306.                             {
  2307.                                 goto nextcmd3;
  2308.                             }
  2309.                             string onestr = oneModel.Substring(st, h);
  2310.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  2311.                             {
  2312.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  2313.                             }
  2314.                             //遍历数据  是否符合全部数据
  2315.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  2316.                             {
  2317.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1) & (de1.Value.ToString().Length > 0))
  2318.                                 {
  2319.                                     goto nextcmd3;
  2320.                                 }
  2321.                             }
  2322.                             //符合所有项都存在的条件 压入字典  
  2323.                             tdict.Add(tdictI, onestr);
  2324.                             //数据替换
  2325.                             Hashtable mtmpp = new Hashtable();
  2326.                             mtmpp.Clear();
  2327.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2328.                             {
  2329.                                 //mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  2330.                                 string tmp_str = de2.Value.ToString();
  2331.                                 if (tmp_str == null)
  2332.                                 {
  2333.                                 }
  2334.                                 else
  2335.                                 {
  2336.                                     mtmpp.Add(de2.Key, tmp_str.Replace(onestr, "*" + tdictI.ToString() + "*"));
  2337.                                 }
  2338.                             }
  2339.                             mHTMs = mtmpp;
  2340.                             tdictI = tdictI + 1;  //字典序号
  2341.                             //oneModel  截取   取出碎片 压入 newModels
  2342.                             string oneModelTmp = oneModel.Replace(onestr, "*");
  2343.                             string[] mykc = oneModelTmp.Split('*');
  2344.                             foreach (string ddee in mykc)
  2345.                             {
  2346.                                 if ((ddee.Length > 4) & (newModels.Contains(ddee) == false))
  2347.                                 {
  2348.                                     newModels.Add(ddee, "0");
  2349.                                 }
  2350.                             }
  2351.                             goto NewStart;             //因为碎片变化  所以重新开始扫描
  2352.                         nextcmd3:
  2353.                             st = st + 1;
  2354.                         }
  2355.                     nextcmd1:
  2356.                         h = h - 1;
  2357.                     }
  2358.                 }
  2359.             nextcmd2: ;
  2360.                 goto NewStart;  //本次遍历结束  去掉本字符串   
  2361.             }
  2362.             //mHTMs  处理新的 网页  只留下 *0*
  2363.             Hashtable mtmppC = new Hashtable();
  2364.             mtmppC.Clear();
  2365.             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2366.             {
  2367.                 string cckc = de2.Value.ToString();
  2368.                 //把cckc中的*0*提取出来
  2369.                 mtmppC.Add(de2.Key, getXnX(de2.Value.ToString()));
  2370.                 // mtmppC.Add(de2.Key, de2.Value.ToString());
  2371.             }
  2372.             mHTMs = mtmppC;
  2373.             //从模板得到一个项目模板
  2374.            // string mmoo = aass14BuilderModel(mHTMs);
  2375.             string mmoo = GetComDataEND(mHTMs, tdict);
  2376.             if (mmoo.Length == 0)
  2377.             {
  2378.                 //从模板得到一个项目模板
  2379.                 mmoo = aass3BuilderModel(mHTMs);
  2380.             }
  2381.             mmoo = mmoo.Replace("<", "*");
  2382.             mmoo = mmoo.Replace(">", "*");
  2383.             if (mmoo.Length == 0)
  2384.             {
  2385.                 return "";
  2386.             }
  2387.             else
  2388.             {
  2389.                 foreach (System.Collections.DictionaryEntry dec in tdict)
  2390.                 {
  2391.                     mmoo = mmoo.Replace("*" + dec.Key.ToString() + "*", dec.Value.ToString());
  2392.                 }
  2393.                 return mmoo;
  2394.             }
  2395.         }
  2396.         ////////////////////////////////////////////////////////////////////////////////
  2397.         //14
  2398.         ////////////////////////////////////////////////////////////////////////////////
  2399.         //14
  2400.         /// <summary>
  2401.         /// 《14》根据子模板建立一个超级模板
  2402.         /// </summary>
  2403.         /// <param name="mHTMs"></param>
  2404.         /// <returns></returns>
  2405.         private string aass14BuilderModel(Hashtable mHTMs)
  2406.         {
  2407.             //得到最短的串
  2408.             string oneModel = "";
  2409.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2410.             {
  2411.                 if (oneModel.Length == 0)
  2412.                 {
  2413.                     oneModel = de.Value.ToString();
  2414.                 }
  2415.                 else
  2416.                 {
  2417.                     if (oneModel.Length > de.Value.ToString().Length)
  2418.                     {
  2419.                         oneModel = de.Value.ToString();
  2420.                     }
  2421.                 }
  2422.             }
  2423.             foreach (System.Collections.DictionaryEntry de in mHTMs)
  2424.             {
  2425.                 if (oneModel != de.Value.ToString())                    //不相同
  2426.                 {
  2427.                     if (de.Value.ToString().IndexOf(oneModel) == -1)    //不包含
  2428.                     {
  2429.                         goto cXStart;
  2430.                     }
  2431.                 }
  2432.             }
  2433.             return oneModel;
  2434.         cXStart:
  2435.             //得到匹配临时模板的原始长度
  2436.             int onemLong = oneModel.Length;
  2437.             Hashtable tdict = new Hashtable();
  2438.             int tdictI = 0; //字典序号
  2439.             tdict.Clear();
  2440.             Hashtable oneModels = new Hashtable();
  2441.             oneModels.Clear();
  2442.             oneModels.Add(oneModel, "0");  //碎片如果相同 就不用继续寻找添加     
  2443.             //存放临时碎片
  2444.             Hashtable newModels = new Hashtable();
  2445.             newModels.Clear();
  2446.             oneModel = "";
  2447.         NewStart: //开始遍历匹配串
  2448.             if (oneModel.Length > 0)
  2449.             {
  2450.                 oneModels.Remove(oneModel);       //移除旧的字符串  压入分解后的字符串
  2451.             }
  2452.             foreach (System.Collections.DictionaryEntry de in newModels)    //加入新的碎片项
  2453.             {
  2454.                 if (oneModels.Contains(de.Key) == false)
  2455.                 {
  2456.                     oneModels.Add(de.Key, "0");
  2457.                 }
  2458.             }
  2459.             newModels.Clear();
  2460.             foreach (System.Collections.DictionaryEntry de in oneModels)
  2461.             {
  2462.                 oneModel = de.Key.ToString();
  2463.                 if (oneModel.Length > 2)
  2464.                 {
  2465.                     int h = oneModel.Length;
  2466.                     while (true)
  2467.                     {
  2468.                         if (h < 3)         //最短字符不能小于5  >=四
  2469.                         { goto nextcmd2; }
  2470.                         int st = 0;
  2471.                         while (true)
  2472.                         {
  2473.                             if (st + h > oneModel.Length)
  2474.                             { goto nextcmd1; }
  2475.                             string a1 = oneModel.Substring(st, 1);
  2476.                             string a2 = oneModel.Substring(st + h - 1, 1);
  2477.                             if ((a1 != "<") | (a2 != ">"))   //判断是否合法 含有 <  >
  2478.                             {
  2479.                                 goto nextcmd3;
  2480.                             }
  2481.                             string onestr = oneModel.Substring(st, h);
  2482.                             if ((onestr.Substring(0, 1) != "<") | (onestr.Substring(onestr.Length - 1, 1) != ">") | (onestr.IndexOf(">") == -1) | (onestr.IndexOf("<") == -1))
  2483.                             {
  2484.                                 goto nextcmd3;         //取开头和末尾在<>中的数据
  2485.                             }
  2486.                             //遍历数据  是否符合全部数据
  2487.                             foreach (System.Collections.DictionaryEntry de1 in mHTMs)
  2488.                             {
  2489.                                 if ((de1.Value.ToString().IndexOf(onestr) == -1) & (de1.Value.ToString().Length > 0))
  2490.                                 {
  2491.                                     goto nextcmd3;
  2492.                                 }
  2493.                             }
  2494.                             //符合所有项都存在的条件 压入字典  
  2495.                             tdict.Add(tdictI, onestr);
  2496.                             //数据替换
  2497.                             Hashtable mtmpp = new Hashtable();
  2498.                             mtmpp.Clear();
  2499.                             foreach (System.Collections.DictionaryEntry de2 in mHTMs)
  2500.                             {
  2501.                                // mtmpp.Add(de2.Key, de2.Value.ToString().Replace(onestr, "*" + tdictI.ToString() + "*"));
  2502.                                 string tmp_str = de2.Value.ToString();
  2503.                                 if (tmp_str == null)
  2504.                                 {
  2505.                                 }
  2506.                                 else