Exemplo n.º 1
0
 private void btnSeria_Click(object sender, EventArgs e)
 {
     WordSetKind.Serialize();
 }
Exemplo n.º 2
0
        void doAutoAna()
        {
            int anaCount = 0;

            if (WordSetKind.Words.Count != 0)
            {
                WordSetKind.Words.Clear();
            }
            if (Datas.sinaJSONList.Count == 0)
            {
                BlogReader br = new BlogReader(@"temp5.dat");
                Datas.sinaJSONList = br.ReadFromFile();
            }
            if (listBrands == null)
            {
                listBrands = new List <SingleBrand>();
            }
            if (listBrands.Count == 0)
            {
                using (FileStream fs = new FileStream("datas/mobileDatas.dat", FileMode.Open))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    listBrands = bf.Deserialize(fs) as List <SingleBrand>;
                    fs.Close();
                }
            }

            foreach (SinaJSON item in Datas.sinaJSONList)
            {
                anaCount++;
                Datas.ProgressBarState = "正在分析第" + anaCount + "个";
                string source = Regex.Match(item.Source, @">[^<]+").Value;
                source = source.Substring(1, source.Length - 1);

                SetAttribute attr = new SetAttribute();

                short position = 0;     //位置变量

                foreach (SingleBrand singleBrand in listBrands)
                {
                    string[] name = singleBrand.BrandName.Replace(")", "").Split('(');
                    if (name.Length == 2)
                    {
                        if (source.IndexOf(name[0]) != -1 || source.IndexOf(name[1]) != -1)
                        {
                            attr.BrandName = singleBrand.BrandName;
                            break;
                        }
                    }
                    else
                    {
                        if (source.IndexOf(name[0]) != -1)
                        {
                            attr.BrandName = singleBrand.BrandName;
                            break;
                        }
                    }
                    position++;
                }
                //品牌匹配成功
                if (attr.BrandName != null)
                {
                    foreach (Model model in listBrands[position].ListModels)
                    {
                        //存在型号
                        if (model.ModelName != null && model.ModelName.IndexOf(source) != -1)
                        {
                            if (model.ModelName.IndexOf("android", StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                attr.OS = OperatingSystem.Android;
                            }
                            else
                            if (model.ModelName.IndexOf("iOS", StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                attr.OS = OperatingSystem.iOS;
                            }
                            if (attr.OS != OperatingSystem.未知)
                            {
                                attr.setKind = SetKind.手机;
                                break;
                            }
                        }
                    }

                    if (attr.OS == OperatingSystem.未知)
                    {
                        attr.OS = OperatingSystem.Android;
                    }
                    if (attr.setKind == SetKind.未知)
                    {
                        attr.setKind = SetKind.手机;
                    }
                }
                //品牌匹配失败
                else
                {
                    //大系统确定
                    if (source.IndexOf("android", StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        attr.OS      = OperatingSystem.Android;
                        attr.setKind = SetKind.未知;
                    }
                    else
                    if (source.IndexOf("ios", StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        attr.OS      = OperatingSystem.iOS;
                        attr.setKind = SetKind.未知;
                    }
                    else
                    if (source.IndexOf("win8", StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        attr.OS      = OperatingSystem.Windows;
                        attr.setKind = SetKind.PC;
                    }
                    else
                    {
                        attr.OS      = OperatingSystem.其它;
                        attr.setKind = SetKind.未知;
                    }
                    attr.BrandName = "其它";
                }
                if (source.IndexOf("window", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.OS = OperatingSystem.WindowsPhone;
                }
                else
                if (source.IndexOf("s60", StringComparison.CurrentCultureIgnoreCase) != -1 ||
                    source.IndexOf("s40", StringComparison.CurrentCultureIgnoreCase) != -1 ||
                    source.IndexOf("s30", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.OS = OperatingSystem.塞班;
                }

                if (source.IndexOf("phone", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.setKind = SetKind.手机;
                }
                if (source.IndexOf("iphone", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.OS      = OperatingSystem.iOS;
                    attr.setKind = SetKind.手机;
                }
                else
                if (source.IndexOf("ipad", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.OS      = OperatingSystem.iOS;
                    attr.setKind = SetKind.平板;
                }

                if (source.IndexOf("手机", StringComparison.CurrentCultureIgnoreCase) != -1 ||
                    source.IndexOf("note", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.setKind = SetKind.手机;
                }
                else
                if (source.IndexOf("平板", StringComparison.CurrentCultureIgnoreCase) != -1 ||
                    source.IndexOf("tab", StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    attr.setKind = SetKind.平板;
                }

                if (attr.OS == OperatingSystem.其它 && source.IndexOf("智能") != -1)
                {
                    attr.OS = OperatingSystem.Android;
                }

                WordSetKind.AddWord(source, attr);
            }

            Datas.ProgressBarCompelet = true;
        }