コード例 #1
0
        /// <summary>
        /// 相似查找,返回对应的原油ID
        /// </summary>
        /// <param name="oilProperty">相似查找条件的实体集合OilSimilarSearchEntityList</param>
        /// <returns></returns>
        public IDictionary <string, double> GetOilSimInfoCrudeIndex(IList <OilSimilarSearchEntity> similarSearchEntityList)
        {
            IDictionary <string, double> crudeIndexSimDic = new Dictionary <string, double>();

            #region "输入条件判断"
            IList <string> resultCrudeIndexList = new List <string>(); //存放满足条件的原油编号
            if (similarSearchEntityList == null)                       //查找条件为空
            {
                return(crudeIndexSimDic);
            }
            if (similarSearchEntityList.Count == 0)//查找条件为空
            {
                return(crudeIndexSimDic);
            }
            #endregion

            #region "初始化判断条件"
            string sqlWhere = "select distinct(oilInfoID) from OilDataSearch";
            OilDataSearchAccess oilDataSearchAccess        = new OilDataSearchAccess();
            List <int>          oilDataSearchOilInfoIDList = oilDataSearchAccess.getId(sqlWhere); //获取OilDataSearch表中的所有oilInfoID

            foreach (int oilInfoBID in oilDataSearchOilInfoIDList)                                //从C库中查找到的原油编号
            {
                OilInfoBEntity           bEntity  = OilBll.GetOilBByID(oilInfoBID);
                List <TempsimliarEntity> tempList = new List <TempsimliarEntity>();
                if (bEntity != null)
                {
                    tempSimliarDic[bEntity.crudeIndex] = tempList;
                }
            }

            #endregion

            #region "范围查找中And和or两种类型的判断的归类"
            IList <OilSimilarSearchEntity> searchAnd = new List <OilSimilarSearchEntity>(); //范围查找用(and条件)
            IList <OilSimilarSearchEntity> searchOr  = new List <OilSimilarSearchEntity>(); //范围查找用(or条件)
            foreach (OilSimilarSearchEntity currentOilSimilarSearchEntity in similarSearchEntityList)
            {
                if (currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是And,添加到searchAnd中去
                {
                    searchAnd.Add(currentOilSimilarSearchEntity);
                    continue;
                }
                else if (!currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.LeftParenthesis.Trim() == "(" && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算
                {
                    searchOr.Add(currentOilSimilarSearchEntity);
                    continue;
                }
                else if (!currentOilSimilarSearchEntity.IsAnd && currentOilSimilarSearchEntity.LeftParenthesis.Trim() == "" && currentOilSimilarSearchEntity.RightParenthesis.Trim() == "")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算
                {
                    searchOr.Add(currentOilSimilarSearchEntity);
                    continue;
                }
                else if (currentOilSimilarSearchEntity.RightParenthesis.Trim() == ")")////如果该条件是Or,且是括号中的最后一个Or,则添加到searchOr中去,并进行或的计算
                {
                    #region "Or的计算"
                    searchOr.Add(currentOilSimilarSearchEntity);

                    foreach (int ID in oilDataSearchOilInfoIDList)//根据ID循环每一条原油
                    {
                        OilInfoBEntity infoB = OilBll.GetOilBByID(ID);
                        if (!tempSimliarDic.Keys.Contains(infoB.crudeIndex))
                        {
                            continue;
                        }

                        if (searchOr.Count <= 0)
                        {
                            continue;
                        }

                        TempsimliarEntity tempsimliarEntity = getDataFromOrSimilarSearchList(searchOr, ID);
                        if (tempSimliarDic.Keys.Contains(infoB.crudeIndex))
                        {
                            tempSimliarDic[infoB.crudeIndex].Add(tempsimliarEntity);
                        }
                    }
                    searchOr.Clear();//该Or括号计算完后,情况OrList,用于后面的Or括号计算
                    continue;

                    #endregion
                }
            }
            #endregion

            #region "处理And条件或计算的结果和And条件取交集"
            foreach (int oilInfoID in oilDataSearchOilInfoIDList)//根据ID循环每一条原油
            {
                OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoID);
                if (!tempSimliarDic.Keys.Contains(infoB.crudeIndex))
                {
                    continue;
                }
                if (searchAnd.Count <= 0)
                {
                    continue;
                }

                TempsimliarEntity tempsimliarEntity = getDataFromAndSimilarSearchList(searchAnd, oilInfoID);
                if (tempSimliarDic.Keys.Contains(infoB.crudeIndex))
                {
                    tempSimliarDic[infoB.crudeIndex].Add(tempsimliarEntity);
                }
            }
            #endregion

            foreach (string key in tempSimliarDic.Keys)
            {
                double sum = 0, sumWeight = 0;
                foreach (TempsimliarEntity tempsimliarEntity in tempSimliarDic[key])
                {
                    if (tempsimliarEntity.Match == 0 || tempsimliarEntity.Match.Equals(double.NaN))
                    {
                        sum       = double.NaN;
                        sumWeight = tempsimliarEntity.Weight;
                    }
                    else
                    {
                        sum       += tempsimliarEntity.Match;
                        sumWeight += tempsimliarEntity.Weight;
                    }
                }

                if (sumWeight != 0 && !sum.Equals(double.NaN))
                {
                    crudeIndexSimDic.Add(key, sum / sumWeight);
                }
            }

            return(crudeIndexSimDic);
        }
コード例 #2
0
        /// <summary>
        /// 范围查询-从C库查找满足条件的原油编号
        /// </summary>
        /// <returns></returns>
        public static IDictionary <string, double> GetRangOilInfoCrudeIndex(IList <OilRangeSearchEntity> rangeSearchEntityList)
        {
            int count = 0; //输入条件的个数
            IDictionary <string, double> crudeIndexRanDic = new Dictionary <string, double>();

            //IList<string> resultCrudeIndexList = new List<string>();//存放满足条件的原油编号

            #region "输入条件判断"
            if (rangeSearchEntityList == null)//查找条件为空
            {
                return(crudeIndexRanDic);
            }
            if (rangeSearchEntityList.Count == 0)//查找条件为空
            {
                return(crudeIndexRanDic);
            }
            #endregion

            #region "标志条件"
            Dictionary <string, int> oilInfoCrudeIndex_And_Result = new Dictionary <string, int>();//满足条件的原油对应值为1,不满足为0
            string sqlWhere = "select distinct(oilInfoID) from OilDataSearch";
            OilDataSearchAccess oilDataSearchAccess         = new OilDataSearchAccess();
            List <int>          oilDataSearchOilInfoBIDList = oilDataSearchAccess.getId(sqlWhere); //获取OilDataSearch表中的所有oilInfoID

            foreach (int oilInfoBID in oilDataSearchOilInfoBIDList)                                //从C库中查找到的原油编号
            {
                OilInfoBEntity bEntity = OilBll.GetOilBByID(oilInfoBID);
                if (bEntity != null)
                {
                    oilInfoCrudeIndex_And_Result[bEntity.crudeIndex] = 0;
                }
            }
            #endregion

            #region "范围查找中And和or两种类型的判断的归类"
            IList <OilRangeSearchEntity> searchAnd = new List <OilRangeSearchEntity>(); //范围查找用(and条件)
            IList <OilRangeSearchEntity> searchOr  = new List <OilRangeSearchEntity>(); //范围查找用(or条件)
            foreach (OilRangeSearchEntity currentOilRangeSearchEntity in rangeSearchEntityList)
            {
                if (currentOilRangeSearchEntity.IsAnd && currentOilRangeSearchEntity.RightParenthesis.Trim() == "")//如果该条件是And,添加到searchAnd中去
                {
                    searchAnd.Add(currentOilRangeSearchEntity);
                    count++;
                    continue;
                }
                else if (!currentOilRangeSearchEntity.IsAnd && currentOilRangeSearchEntity.RightParenthesis.Trim() != ")")//如果该条件是Or,但不是最后一个Or,则添加到searchOr中去,暂时不进行计算
                {
                    searchOr.Add(currentOilRangeSearchEntity);
                    continue;
                }
                else if (currentOilRangeSearchEntity.RightParenthesis.Trim() == ")")////如果该条件是Or,且是括号中的最后一个Or,则添加到searchOr中去,并进行或的计算
                {
                    #region "Or的计算"
                    searchOr.Add(currentOilRangeSearchEntity);

                    foreach (int oilInfoBID in oilDataSearchOilInfoBIDList)//从C库中查找到的原油编号
                    {
                        OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoBID);
                        int            temp  = getDataFromOrRangeSearchList(searchOr, oilInfoBID);
                        oilInfoCrudeIndex_And_Result[infoB.crudeIndex] += temp;
                    }
                    count++;
                    searchOr.Clear();//该Or括号计算完后,情况OrList,用于后面的Or括号计算
                    continue;
                    #endregion
                }
            }
            #endregion

            #region "处理And条件(或计算的结果和And条件取交集"
            foreach (int oilInfoBID in oilDataSearchOilInfoBIDList)//从C库中查找到的原油编号
            {
                OilInfoBEntity infoB = OilBll.GetOilBByID(oilInfoBID);
                oilInfoCrudeIndex_And_Result[infoB.crudeIndex] += getDataFromAndRangeSearchList(searchAnd, oilInfoBID);
            }
            #endregion

            foreach (string key in oilInfoCrudeIndex_And_Result.Keys)
            {
                if (oilInfoCrudeIndex_And_Result[key] == count)
                {
                    crudeIndexRanDic.Add(key, 0);
                }
            }
            searchAnd.Clear();
            searchOr.Clear();
            return(crudeIndexRanDic);
        }