Beispiel #1
0
        /// <summary>
        /// 初始化函数
        /// </summary>
        /// <param name="MediaType"></param>
        /// <param name="Language"></param>
        /// <param name="modelpath_title"></param>
        /// <param name="modelpath_rel"></param>
        /// <param name="stencilfeature"></param>
        public SoftStrategy(Enums.MediaType MediaType, Enums.Language Language)
        {
            this.MediaType = MediaType;
            this.Language  = Language;

            this.model_title = Model.Read("SVMmodel/model_title_WebNews");
            this.model_rel   = Model.Read("SVMmodel/model_rel_WebNews");
            //目前在用比较笨的方法来赋值,以后将直接调用文件资源对这些评分标准进行赋值

            this.Threshold = new HardThreshold(MediaType, Language);

            #region stencil定义部分

            string FileAdd = Path.Combine("Stencil");
            if (File.Exists(FileAdd + "/Stencil_ListTitle"))
            {
                this.Stencil_ListTitle = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ListTitle"), typeof(Feature));
            }
            else
            {
                #region listTitle模版定义部分
                this.Stencil_ListTitle = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "DateParseCount" || key == "AvgNumber" || key == "AvgDateDistance" || key == "DigitCountRate" || key == "DateCountRate")
                    {
                        this.Stencil_ListTitle.FigureFeatures[key] = 0;
                    }
                }

                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ListTitle.CharRecordf[key] = 0;
                }

                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ListTitle.CharRecords[key] = 0;
                }

                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ListTitle.BoolFeatures[key] = 0;
                }
                #endregion listtitle模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ListRel"))
            {
                this.Stencil_ListRel = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ListRel"), typeof(Feature));
            }
            else
            {
                #region listRel模版定义部分
                this.Stencil_ListRel = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "DateParseCount" || key == "AvgNumber" || key == "AvgDateDistance" || key == "ItemCount" || key == "AvgDateDistance")
                    {
                        this.Stencil_ListRel.FigureFeatures[key] = 0;
                    }
                }

                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ListRel.BoolFeatures[key] = 0;
                }

                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ListRel.IdClassnameRecord[key] = 0;
                }
                #endregion listRel模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ItemContent"))
            {
                this.Stencil_ItemContent = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ItemContent"), typeof(Feature));
            }
            else
            {
                #region itemcontent模版定义部分
                this.Stencil_ItemContent = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "AllTextLen")
                    {
                        this.Stencil_ItemContent.FigureFeatures[key] = 1;
                    }
                    else
                    {
                        this.Stencil_ItemContent.FigureFeatures[key] = 0;
                    }
                }
                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ItemContent.CharRecordf[key] = 1;
                }
                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ItemContent.CharRecords[key] = 1;
                }
                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ItemContent.IdClassnameRecord[key] = 1;
                }
                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ItemContent.BoolFeatures[key] = 0;
                }
                #endregion itemcontent模版定义部分
            }

            if (File.Exists(FileAdd + "/Stencil_ItemOthers"))
            {
                this.Stencil_ItemOthers = (Feature)JsonConvert.DeserializeObject(File.ReadAllText(FileAdd + "/Stencil_ItemOthers"), typeof(Feature));
            }
            else
            {
                #region itemcontent模版定义部分
                this.Stencil_ItemOthers = new Feature(1);
                Feature temp = new Feature(0);
                foreach (string key in temp.FigureFeatures.Keys)
                {
                    if (key == "AllTextLen" || key == "DateParseCount")
                    {
                        this.Stencil_ItemOthers.FigureFeatures[key] = 1;
                    }
                    else
                    {
                        this.Stencil_ItemOthers.FigureFeatures[key] = 0;
                    }
                }
                foreach (string key in temp.CharRecordf.Keys)
                {
                    this.Stencil_ItemOthers.CharRecordf[key] = 1;
                }
                foreach (string key in temp.CharRecords.Keys)
                {
                    this.Stencil_ItemOthers.CharRecords[key] = 1;
                }
                foreach (string key in temp.IdClassnameRecord.Keys)
                {
                    this.Stencil_ItemOthers.IdClassnameRecord[key] = 1;
                }
                foreach (string key in temp.BoolFeatures.Keys)
                {
                    this.Stencil_ItemOthers.BoolFeatures[key] = 0;
                }
                #endregion itemcontent模版定义部分
            }

            #endregion stencil定义部分
        }
Beispiel #2
0
 /// <summary>
 /// 简单的初始化方式
 /// </summary>
 public SoftStrategy()
 {
     this.Threshold = new HardThreshold();
 }