Exemple #1
1
 private static IEnumerable<Sim> Compare(Quest fromQuest, string[] fromRoute, IList<Quest> questDB)
 {
     DolRoute EL = new DolRoute();
     var simList = new List<Sim>();
     questDB.All(quest =>
     {
         if (quest.ID == fromQuest.ID)
             return true;
         if (quest.RouteForSim.Count != 0)
         {
             var min = quest.RouteForSim.Min(route =>
             {
                 if (route.Count < 2)
                     return 2001;
                 var value = EL.Compute(fromRoute, route.ToArray());
                 return value;
             });
             if (min < 2000)
             {
                 simList.Add(new Sim()
                 {
                     CompareID = quest.ID,
                     QuestID = fromQuest.ID,
                     Value = min,
                     StartCity = EL.GetCityID(fromRoute[0])
                 });
             }
         }
         return true;
     });
     return simList.OrderBy(sim => sim.Value).Take(300);
 }
        //<tr bgcolor="#B7CFEB" align="center" style="background-color: rgb(143, 186, 236);">
        //         <td align="left"><a href="mission.do?act=look&amp;mission_id=3976" target="_black"><font class="zi14" color="black">高原白花的地图</font></a>&nbsp;<img alt="南十字星第四章" src="http://dols.enorth.com.cn/jpg\edition\CDS4.gif"></td>
        //         <td>0</td>
        //         <td align="left">
        //         <img alt="生态调查" src="http://dols.enorth.com.cn/jpg\skill\stdc.gif"><img alt="" src="http://dols.enorth.com.cn/jpg/num/5.gif"><img alt="生物学" src="http://dols.enorth.com.cn/jpg\skill\swx.gif"><img alt="" src="http://dols.enorth.com.cn/jpg/num/5.gif">
        //         </td>
        //         <td>0/0<br></td>
        //         <td align="left">热那亚门外 白花附近</td>
        //         <td align="left">
        //           <img alt="植物" src="http://dols.enorth.com.cn/jpg\distype\zw.jpg" width="20" height="20">
        //<font color="red">1★</font>
        //<a href="discover.do?act=look&amp;discover_id=3642" target="_black"><font color="red">火绒草</font></a>
        //           <br>
        //          <font color="#804000">                              </font>
        //           <br>
        //          <a href="mission.do?act=list&amp;link=pl8_mt0lt0pl0" target="_black">那不勒斯</a>
        //         </td>
        //       </tr>
        public static Dol.Base.Quest GetQuest(HtmlNode node)
        {
            //first td,first a
            var quest = new Dol.Base.Quest();
            var href = node.SelectSingleNode("td[1]").SelectSingleNode("a[1]").Attributes["href"].Value;
            quest.ID = Int32.Parse(missionRegex.Match(href).Groups["id"].Value);
            quest.Name = node.SelectSingleNode("td[1]").SelectSingleNode("a[1]").InnerText;
            quest.Name = quest.Name.Replace("“", "");
            quest.Name = Consistency.Parse(quest.Name);
            quest.Star = Int32.Parse(node.SelectSingleNode("td[2]").InnerText);
            quest.Skill = SkillHandler.ParseSkill(node.SelectSingleNode("td[3]"));
            var award = node.SelectSingleNode("td[4]").InnerText.Split('/');
            quest.Exp = Int32.Parse(award[0]);
            var fameStr=numRegex.Replace(award[1], "");
            quest.Fame = Int32.Parse(fameStr);
            var escape = new Escape();
            var raw=node.SelectSingleNode("td[5]").InnerHtml;
            raw=Consistency.Parse(raw);
            quest.Content = raw;
            var remark=RemarkHandler.ParseRemark(node.SelectSingleNode("td[6]"));
            quest.FromCityList = remark.FromCityList;
            quest.AwardItem = remark.AwardItem;
            quest.Discovery = remark.Discovery;
            quest.DiscoveryID = remark.DiscoveryID;
            quest.DiscoveryLevel = remark.DiscoveryLevel;
            quest.DiscoveryType = remark.DiscoveryType;
            quest.FollowQuestID = remark.FollowQuestID;
            quest.PreFoundName = remark.PreFoundName;
            quest.PreQuestID = remark.PreQuestID;

            //Content解析
            POIs.Land.Concat(POIs.Citys).All(name =>
            {
                var index = raw.IndexOf(name);
                while (index != -1)
                {
                    //POIs.Count[name] = POIs.Count[name] + 1;
                    if (!quest.RoutesDic.Keys.Contains(index))
                    {
                        quest.RoutesDic.Add(index, name);
                    }
                    index = raw.IndexOf(name, index + name.Length);
                }
                return true;
            });
            var keys=quest.RoutesDic.Keys.ToArray();
            var lastRoute=String.Empty;
            foreach (var key in keys)
            {
                var route = quest.RoutesDic[key];
                if (lastRoute == route)
                {
                    quest.RoutesDic.Remove(key);
                }
                lastRoute = route;
            }
            return quest;
        }
        public static Dol.Base.Quest GetQuest(HtmlNode node)
        {
            //first td,first a
            var quest = new Dol.Base.Quest();
            var href = node.SelectSingleNode("td[3]").SelectSingleNode("descendant::a").Attributes["href"].Value;
            var img = node.SelectSingleNode("td[3]").SelectSingleNode("descendant::img").Attributes["src"].Value;
            quest.Type = 1;//地图
            quest.ID = Int32.Parse(missionRegex.Match(href).Groups["id"].Value);
            quest.Chapter = Int32.Parse(chapterRegex.Match(img).Groups["chapter"].Value);
            quest.Name = node.SelectSingleNode("td[3]").SelectSingleNode("descendant::a[1]").InnerText;
            quest.Name = quest.Name.Replace("“", "");
            quest.Star = 0;
            quest.Skill = SkillHandler.ParseSkill(node.SelectSingleNode("td[4]"));
            var raw = node.SelectSingleNode("td[5]/span[1]").InnerHtml;
            quest.Content = raw;
            var remark = RemarkHandler.ParseRemark(node.SelectSingleNode("td[6]"));
            quest.FromCityList = remark.FromCityList;
            quest.AwardItem = remark.AwardItem;
            quest.Discovery = remark.Discovery;
            quest.DiscoveryID = remark.DiscoveryID;
            quest.DiscoveryLevel = remark.DiscoveryLevel;
            quest.DiscoveryType = remark.DiscoveryType;
            quest.DiscoveryExp = remark.DiscoveryExp;
            quest.FollowQuestID = remark.FollowQuestID;
            quest.PreFoundName = remark.PreFoundName;
            quest.PreQuestID = remark.PreQuestID;

            //Content解析
            POIs.Land.Concat(POIs.Citys).All(name =>
            {
                var index = raw.IndexOf(name);
                while (index != -1)
                {
                    //POIs.Count[name] = POIs.Count[name] + 1;
                    if (!quest.RoutesDic.Keys.Contains(index))
                    {
                        quest.RoutesDic.Add(index, name);
                    }
                    index = raw.IndexOf(name, index + name.Length);
                }
                return true;
            });
            var keys = quest.RoutesDic.Keys.ToArray();
            var lastRoute = String.Empty;
            foreach (var key in keys)
            {
                var route = quest.RoutesDic[key];
                if (lastRoute == route)
                {
                    quest.RoutesDic.Remove(key);
                }
                lastRoute = route;
            }
            return quest;
        }
 public List<KeyValuePair<int, Quest>> FindSim(Quest target, IList<Quest> questList)
 {
     var result=new SortedList<int, Quest>();
     questList.All(quest =>
     {
         var value = GetSimValue(target, quest);
         if (value == Int32.MaxValue)
             return true;
         while (result.ContainsKey(value) == true)
             value += 1;
         result.Add(value, quest);
         if (value == Int32.MinValue)
             return false;
         return true;
     });
     return result.OrderBy(x => x.Key).Take(10).ToList();
 }
 private int GetSimValue(Quest target, Quest template)
 {
     int sim = 1;
     //首先比对名称,如果名称一致则相似度为0
     if (target.Name == template.Name)
         return -5000;
     //比对接受任务地点
     if (target.FromCityList.Count != template.FromCityList.Count)
         return Int32.MaxValue;
     foreach (var city in target.FromCityList)
     {
         if (!template.FromCityList.Contains(city))
             return Int32.MaxValue;
     }
     if (target.Type == 0 && template.Star != target.Star)
         return Int32.MaxValue;
     if ((target.Discovery == null && template.Discovery != null) ||
         (target.Discovery != null && template.Discovery == null))
     {
         return Int32.MaxValue;
     }
     //对比技能是否有区别
     var comparedSkill = 0;
     foreach (string skill in compareSkill)
     {
         var fromSkill = target.Skill.Where(x => x.Name == skill).FirstOrDefault();
         var toSkill = template.Skill.Where(x => x.Name == skill).FirstOrDefault();
         if ((fromSkill == null && toSkill != null)||
             (fromSkill != null && toSkill == null))
         {
             return Int32.MaxValue;
         }
         else if (fromSkill != null && toSkill != null)
         {
             if (fromSkill.Level != toSkill.Level)
                 return Int32.MaxValue;
             comparedSkill++;
         }
     }
     //对比发现物
     if (target.DiscoveryType == template.DiscoveryType && target.DiscoveryLevel == template.DiscoveryLevel)
         sim -= 4;
     sim -= comparedSkill * 3;
     //查看路径的相似度
     sim += EditDistance.getEditDistance(target.RoutesDic.Aggregate("", (seed, pair) =>
     {
         return seed += "," + pair.Value;
     }), template.RoutesDic.Aggregate("", (seed, pair) =>
     {
         return seed += "," + pair.Value;
     }));
     sim += EditDistance.getEditDistance(formatContent(target.Content), formatContent(template.Content)) / 20;
     sim += EditDistance.getEditDistance(target.Discovery, template.Discovery);
     //查看任务名称的相似度
     sim += EditDistance.getEditDistance(specialName(target.Name), specialName(template.Name));
     //查看任务前置后续相似度
     //if (target.PreQuestID.Count == template.PreQuestID.Count && template.PreQuestID.Count != 0)
     //    sim -= 1;
     //if (target.FollowQuestID.Count == template.FollowQuestID.Count && template.FollowQuestID.Count != 0)
     //    sim -= 1;
     //if (target.PreQuestID.Count == template.PreQuestID.Count && template.PreQuestID.Count != 0 &&
     //    target.FollowQuestID.Count == template.FollowQuestID.Count && template.FollowQuestID.Count != 0)
     //    sim -= 1;
     return sim;
 }