Exemplo n.º 1
0
        public static KeyBondMDL <T, L> UpdateKeyBondColl <T, L>(T head, L tail, KeyBondColl <T, L> objKeyBondColl, OffsetWeightMDL objHeadWeightMDL, OffsetWeightMDL objTailWeightMDL)
        {
            if (!objKeyBondColl.Contains(head))
            {
                KeyBondMDL <T, L> bond = new KeyBondMDL <T, L>();
                bond.KeyItem.Key                      = head;
                bond.KeyItem.UpdateOffset             = objKeyBondColl.Parameter.TotalOffset;
                bond.LinkColl.Parameter.ContainerSize = objKeyBondColl.Parameter.ContainerSize;
                bond.LinkColl.Parameter.Threshold     = objKeyBondColl.Parameter.Threshold;
                objKeyBondColl.Add(bond);
            }

            KeyItemMDL <T> mdl = objKeyBondColl[head].KeyItem;

            mdl.ValidCount   = objHeadWeightMDL.Weight + mdl.ValidCount * MemoryDAL.CalcRemeberValue(objKeyBondColl.Parameter.TotalOffset - mdl.UpdateOffset, objKeyBondColl.Parameter);
            mdl.TotalCount   = objHeadWeightMDL.Weight + mdl.TotalCount * MemoryDAL.CalcRemeberValue(1, objKeyBondColl.Parameter);
            mdl.UpdateOffset = objKeyBondColl.Parameter.TotalOffset;


            KeyItemColl <L> objLinkColl = objKeyBondColl[head].LinkColl;

            if (objTailWeightMDL.Offset < 0)
            {
                //继承主计数
                objLinkColl.Parameter.TotalOffset = objKeyBondColl.Parameter.TotalOffset;
                objTailWeightMDL.Offset           = 0;
            }
            KeyItemDAL.UpdateKeyItemColl(tail, objLinkColl, objTailWeightMDL);

            objKeyBondColl.Parameter.TotalValidCount = objHeadWeightMDL.Weight + objKeyBondColl.Parameter.TotalValidCount * MemoryDAL.CalcRemeberValue(objHeadWeightMDL.Offset, objKeyBondColl.Parameter);
            objKeyBondColl.Parameter.TotalOffset    += objHeadWeightMDL.Offset;

            return(objKeyBondColl[head]);
        }
Exemplo n.º 2
0
        public static string ShowKeyBondCollEx(KeyBondColl <string, string> objKeyBondColl, List <string> objKeyWordList, int nLinkTopCount, bool bIsOrderbyDesc = true, string splitChar = "\t", string spaceChar = "\r")
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(String.Format("[{0}]{1}|{2}|{3}|{4}", "词项", "遗忘词频", "总词频", "词权重", "成熟度"));
            sb.AppendLine("=============================================");


            StringBuilder sbkey = new StringBuilder();
            HashSet <KeyItemMDL <string> > objBufferSet = new HashSet <KeyItemMDL <string> >();

            foreach (string keyword in objKeyWordList)
            {
                if (String.IsNullOrWhiteSpace(keyword))
                {
                    continue;
                }
                if (!objKeyBondColl.Contains(keyword))
                {
                    continue;
                }
                if (sbkey.Length > 0)
                {
                    sbkey.Append("、");
                }
                sbkey.Append(keyword);
                KeyBondMDL <string, string> bond = objKeyBondColl[keyword];
                if (objBufferSet.Count <= 0)
                {
                    objBufferSet.UnionWith(bond.LinkColl);
                }
                else
                {
                    HashSet <KeyItemMDL <string> > buffer = new HashSet <KeyItemMDL <string> >();
                    foreach (KeyItemMDL <string> mdl in objBufferSet)
                    {
                        if (bond.LinkColl.Contains(mdl.Key))
                        {
                            buffer.Add(mdl);
                        }
                    }
                    objBufferSet = new HashSet <KeyItemMDL <string> >(buffer);
                }
            }
            KeyItemColl <string> objBufferColl = new KeyItemColl <string>();

            foreach (KeyItemMDL <string> mdl in objBufferSet)
            {
                if (!objBufferColl.Contains(mdl.Key))
                {
                    objBufferColl.Add(mdl);
                }
            }

            sb.AppendLine();
            sb.AppendLine(String.Format("【{0}】", sbkey));
            sb.Append(KeyItemHelper.ShowKeyItemColl(objBufferColl, nLinkTopCount, false, bIsOrderbyDesc, false, splitChar, spaceChar));

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public static string ShowKeyBondColl(KeyBondColl <string, string> objKeyBondColl, List <string> objKeyWordList, int nLinkTopCount, bool bIsOrderbyDesc = true, string splitChar = "\t", string spaceChar = "\r")
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(String.Format("[{0}]{1}|{2}|{3}|{4}", "词项", "遗忘词频", "总词频", "词权重", "成熟度"));
            sb.AppendLine("=============================================");

            foreach (string keyword in objKeyWordList)
            {
                if (!objKeyBondColl.Contains(keyword))
                {
                    continue;
                }
                KeyBondMDL <string, string> bond = objKeyBondColl[keyword];
                sb.AppendLine();
                sb.AppendLine(String.Format("【{0}】{1}|{2}", bond.KeyItem.Key, Math.Round(bond.KeyItem.ValidCount * KeyBondHelper.CalcRemeberValue <string, string>(bond.KeyItem.Key, objKeyBondColl), 4), Math.Round(bond.KeyItem.TotalCount)));
                sb.Append(KeyItemHelper.ShowKeyItemColl(bond.LinkColl, nLinkTopCount, false, bIsOrderbyDesc, false, splitChar, spaceChar));
            }
            return(sb.ToString());
        }
Exemplo n.º 4
0
 protected override T GetKeyForItem(KeyBondMDL<T, L> item)
 {
     return item.KeyItem.Key;
 }
Exemplo n.º 5
0
 public static double CalcRemeberValue <T, L>(KeyBondMDL <T, L> mdl, KeyBondColl <T, L> objMemoryBondColl)
 {
     return(MemoryDAL.CalcRemeberValue(objMemoryBondColl.Parameter.TotalOffset - mdl.KeyItem.UpdateOffset, objMemoryBondColl.Parameter));
 }