public override int GetHashCode()
 {
     unchecked
     {
         return(((int)Tag << 24) ^ (ClassIndex.GetHashCode() * 397) ^ NameAndTypeIndex.GetHashCode());
     }
 }
Exemple #2
0
        public override async Task <Message> HandleMessage(Message msg)
        {
            var tmsg = msg as ITokenisable;

            if (tmsg == null)
            {
                return(msg);
            }

            MessageContext context = new MessageContext(msg, this);

            string dfClass = await Class.SelectStringAsync(context);

            ClassIndex cindex = Bayes.GetClass(dfClass);

            if (cindex == null)
            {
                cindex = new ClassIndex {
                    Name = dfClass
                };
                Bayes.AddClass(cindex);
            }

            cindex.IncDocumentCount();

            foreach (string token in tmsg.Tokens)
            {
                cindex.IncTokenCount(token);
            }

            return(msg);
        }
Exemple #3
0
        private void FillOtherFields()
        {
            var catcat = Helpers.ItemsCategoryTable.Find(this);

            if (catcat == null)
            {
                //ClassCat = FindClassCat();
                //SlotCat = FindSlotCat();
                //if (SlotCat >= PoeItemClassSubCatNames[(int)ClassCat].Length)
                //{
                //    ClassCat = Helpers.ItemsCategoryTable.DefaultCat.ClassIndex;
                //    SlotCat = Helpers.ItemsCategoryTable.DefaultCat.SlotIndex;
                //}

                ClassCat = Helpers.ItemsCategoryTable.DefaultCat.ClassIndex;
                SlotCat  = Helpers.ItemsCategoryTable.DefaultCat.SlotIndex;
            }
            else
            {
                ClassCat = catcat.ClassIndex;
                SlotCat  = catcat.SlotIndex;
            }
            if (ItemRequirements.Count != 0 && ItemRequirements[0].Name == "Level") //First reqiurement is always level :) (hopefully chriss won't change it)
            {
                string lvlVal = ItemRequirements[0].Values[0].Value;
                if (lvlVal.EndsWith(" (gem)"))
                {
                    lvlVal = lvlVal.Remove(lvlVal.Length - 6, 6);
                }
                MinLevelRequired = byte.Parse(lvlVal);
            }

            //if (ItemRequirements.Count > 0)
            //    ItemRequirements.Insert(0, new ItemProperty("Requires ",0,new List<ItemProperty.PropertyValue>()));
        }
Exemple #4
0
 public void Ref(FPackageFileSummary summary)
 {
     ClassIndex.Ref(summary);
     TemplateIndex.Ref(summary);
     OuterIndex.Ref(summary);
     SuperIndex.Ref(summary);
     ObjectName.Ref(summary);
 }
Exemple #5
0
        public static double Prediction(IEnumerable <string> tokens, ClassIndex index)
        {
            var tokenPosteriori = from t in tokens
                                  let classOccurences = index.TokenCount(t)
                                                        where classOccurences > 0
                                                        select(double) classOccurences / index.DocumentCount;

            return(tokenPosteriori.Aggregate(1.0, (current, item) => current * item));
        }
Exemple #6
0
        public static double Prediction(IEnumerable <string> tokens, ClassIndex index, IEnumerable <ClassIndex> peers)
        {
            double allDocsCount    = (double)peers.Select(x => x.DocumentCount).Sum() + index.DocumentCount;
            double allUniqueTokens = (double)peers.Select(x => x.Tokens.Count()).Sum() + index.Tokens.Count();
            double allWordsInClass = (double)index.Tokens.Values.Sum();

            var classProbability = Math.Log((double)index.DocumentCount / allDocsCount);
            var score            = classProbability + tokens.Sum(x => Math.Log(((double)index.TokenCount(x) + 1) / (allUniqueTokens + allWordsInClass)));

            return(Math.Pow(Math.E, score));
        }
Exemple #7
0
        public Message Import(Message msg)
        {
            // Elimination of invalid messages
            var record = msg as RecordMessage;

            if (record is null)
            {
                return(null);
            }

            if (!record.Record.ContainsKey("Name"))
            {
                return(null);
            }

            if (!record.Record.ContainsKey("DocumentCount"))
            {
                return(null);
            }

            if (!record.Record.ContainsKey("TokensString"))
            {
                return(null);
            }

            //Okay, import it
            try
            {
                ClassIndex newClass = new ClassIndex
                {
                    Name          = record.Record["Name"] as string,
                    DocumentCount = (int)record.Record["DocumentCount"],
                    TokensString  = record.Record["TokensString"] as string
                };

                Bayes.AddClass(newClass);

                return(newClass);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"{ex.GetType().Name} thrown when importing ClassIndex: {ex.Message}");
            }

            return(null);
        }
Exemple #8
0
        private ClassIndex FindClassCat()
        {
            ClassIndex[] ClassTable = { ClassIndex.Misc,    ClassIndex.Marauder, ClassIndex.Ranger,
                                        ClassIndex.Duelist, ClassIndex.Witch,    ClassIndex.Templar,ClassIndex.Shadow, ClassIndex.Misc };
            if (FrameType == FrameTypeIndex.Gem || FrameType == FrameTypeIndex.Unique)
            {
                return(ClassIndex.Misc);
            }
            byte Dex = 0, Int = 0, Str = 0;

            foreach (ItemProperty p in ItemRequirements)
            {
                if (p.Name.StartsWith("Dex"))
                {
                    Dex = 2;
                }
                else if (p.Name.StartsWith("Str"))
                {
                    Str = 1;
                }
                else if (p.Name.StartsWith("Int"))
                {
                    Int = 4;
                }
            }
            ClassIndex ret = ClassTable[Int | Dex | Str];

            if (ret != ClassIndex.Misc)
            {
                return(ret);
            }


            foreach (ItemProperty p in ItemProperties)
            {
                if (p.Name == "Evasion Rating")
                {
                    Dex = 2;
                }
                else if (p.Name == "Armour")
                {
                    Str = 1;
                }
                else if (p.Name == "Energy Shield")
                {
                    Int = 4;
                }
            }
            ret = ClassTable[Int | Dex | Str];
            if (ret != ClassIndex.Misc)
            {
                return(ret);
            }

            //Quivers goes to rangers..
            if (TypeLine.EndsWith("Quiver"))
            {
                return(ClassIndex.Ranger);
            }

            if (ItemProperties.Count == 0)
            {
                return(ClassIndex.Misc);
            }
            if (ItemProperties[0].Name == "Bow")
            {
                return(ClassIndex.Ranger);
            }
            if (ItemProperties[0].Name == "Staff")
            {
                return(ClassIndex.Templar);
            }

            return(ClassIndex.Misc);
        }
Exemple #9
0
 /// <summary>
 /// Adds a class to the static dictionary
 /// </summary>
 /// <param name="class">Class.</param>
 public static void AddClass(ClassIndex @class)
 {
     Classes.TryAdd(@class.Name, @class);
 }